commit 16e9e24894066828020aa4bfa988657224bd3a96 Author: 李泽帆 <411641460@qq.com> Date: Mon Dec 29 16:38:44 2025 +0800 初始化框架 diff --git a/data_cache/config/log4j.properties b/data_cache/config/log4j.properties new file mode 100644 index 0000000..60b65bc --- /dev/null +++ b/data_cache/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/evt_mgr.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/data_cache/config/mpnet-tools.xml b/data_cache/config/mpnet-tools.xml new file mode 100644 index 0000000..0fc606d --- /dev/null +++ b/data_cache/config/mpnet-tools.xml @@ -0,0 +1,93 @@ + + + + + + 80 + + 2 + + 10 + + -1 + + true + + true + + true + + select 1 + + 180000 + + 60000 + + 30000 + + false + + 300000 + + false + + -1 + + + + + db1 + com.mysql.jdbc.Driver + jdbc:mysql://127.0.0.1:8060/wb_game + root + root + + + + + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/data_cache/pom.xml b/data_cache/pom.xml new file mode 100644 index 0000000..33adc3c --- /dev/null +++ b/data_cache/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + + com.data + data_cache + 1.0.1 + jar + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.taurus + taurus-core + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + log4j + log4j + 1.2.17 + + + + + data_cache + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/data_cache/src/main/java/com/data/bean/AccountBean.java b/data_cache/src/main/java/com/data/bean/AccountBean.java new file mode 100644 index 0000000..5976064 --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/AccountBean.java @@ -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 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; + } + + +} diff --git a/data_cache/src/main/java/com/data/bean/BaseBean.java b/data_cache/src/main/java/com/data/bean/BaseBean.java new file mode 100644 index 0000000..f36ec34 --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/BaseBean.java @@ -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 map) { + + } +} diff --git a/data_cache/src/main/java/com/data/bean/GameBean.java b/data_cache/src/main/java/com/data/bean/GameBean.java new file mode 100644 index 0000000..cef648f --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/GameBean.java @@ -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 opt; + /** + * 版本 + */ + public String version; + + public int gameType; + + /** + * 服务器列表 + */ + public Set svr_list; + /** + * 支付设置 + */ + public Map pay; + /**不可负分*/ + public int isNonnegative ; + + + + public void fillData(Map redis_map) { +// Map 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 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; + } +} diff --git a/data_cache/src/main/java/com/data/bean/GroupBean.java b/data_cache/src/main/java/com/data/bean/GroupBean.java new file mode 100644 index 0000000..07994be --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/GroupBean.java @@ -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 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")); + } + } +} diff --git a/data_cache/src/main/java/com/data/bean/GroupMemberBean.java b/data_cache/src/main/java/com/data/bean/GroupMemberBean.java new file mode 100644 index 0000000..1dd9cbc --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/GroupMemberBean.java @@ -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; //分组号用于幸运号看到对应的用户分组号 + public int seeid; //幸运号看到的分组id + + public GroupMemberBean(int gid) { + this.groupId = gid; + } + + public void fillData(Map 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")); + } + + } +} diff --git a/data_cache/src/main/java/com/data/bean/GroupPlayBean.java b/data_cache/src/main/java/com/data/bean/GroupPlayBean.java new file mode 100644 index 0000000..0b19a92 --- /dev/null +++ b/data_cache/src/main/java/com/data/bean/GroupPlayBean.java @@ -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 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); + } +} diff --git a/data_cache/src/main/java/com/data/cache/AccountCache.java b/data_cache/src/main/java/com/data/cache/AccountCache.java new file mode 100644 index 0000000..d6b7ca0 --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/AccountCache.java @@ -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; + } +} diff --git a/data_cache/src/main/java/com/data/cache/BaseCache.java b/data_cache/src/main/java/com/data/cache/BaseCache.java new file mode 100644 index 0000000..a29f085 --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/BaseCache.java @@ -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 mapByKey = new ConcurrentHashMap<>(); + protected ConcurrentMap 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 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 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 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 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 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(); + } + +} diff --git a/data_cache/src/main/java/com/data/cache/GameCache.java b/data_cache/src/main/java/com/data/cache/GameCache.java new file mode 100644 index 0000000..ba49b37 --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/GameCache.java @@ -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; + } +} diff --git a/data_cache/src/main/java/com/data/cache/GroupCache.java b/data_cache/src/main/java/com/data/cache/GroupCache.java new file mode 100644 index 0000000..7933a62 --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/GroupCache.java @@ -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"; + } +} diff --git a/data_cache/src/main/java/com/data/cache/GroupMemberCache.java b/data_cache/src/main/java/com/data/cache/GroupMemberCache.java new file mode 100644 index 0000000..3a42942 --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/GroupMemberCache.java @@ -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); + } +} diff --git a/data_cache/src/main/java/com/data/cache/GroupPlayCache.java b/data_cache/src/main/java/com/data/cache/GroupPlayCache.java new file mode 100644 index 0000000..94ea55b --- /dev/null +++ b/data_cache/src/main/java/com/data/cache/GroupPlayCache.java @@ -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> set = this.mapById.entrySet(); + for(Entry 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 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 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; + } +} diff --git a/data_cache/src/main/java/com/data/util/ConsumeCode.java b/data_cache/src/main/java/com/data/util/ConsumeCode.java new file mode 100644 index 0000000..2f9cdb2 --- /dev/null +++ b/data_cache/src/main/java/com/data/util/ConsumeCode.java @@ -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; +} diff --git a/data_cache/src/main/java/com/data/util/CountUtil.java b/data_cache/src/main/java/com/data/util/CountUtil.java new file mode 100644 index 0000000..ea3cb60 --- /dev/null +++ b/data_cache/src/main/java/com/data/util/CountUtil.java @@ -0,0 +1,262 @@ +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; + + 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; + } +} diff --git a/data_cache/src/main/java/com/data/util/ErrorCode.java b/data_cache/src/main/java/com/data/util/ErrorCode.java new file mode 100644 index 0000000..a1679cf --- /dev/null +++ b/data_cache/src/main/java/com/data/util/ErrorCode.java @@ -0,0 +1,163 @@ +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; + // 不可选游�? + public final static int NO_GAME = 5; + // 无游戏服�? + public final static int NO_SERVICE = 6; + // 缺钻�? + public final static int NO_DIAMO = 7; + // 房间不可进入 + public final static int ROOM_CLOSE = 10; + // 房间号错�? + public final static int NO_ROOM_NUM = 11; + // 邮件不存�? + public final static int NO_MAIL = 12; + // 邮件已领�? + public final static int RECEIVED_MAIL = 13; + // 任务不存�? + public final static int NO_TASK = 14; + // 任务已领�? + public final static int TASK_COMPLETE = 16; + // 缺奖�? + public final static int NO_RAFFLE = 17; + // 没有战绩 + public final static int NO_MILITARY = 19; + // 没有回放 + 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; +} diff --git a/data_cache/src/main/java/com/data/util/EventType.java b/data_cache/src/main/java/com/data/util/EventType.java new file mode 100644 index 0000000..21dc418 --- /dev/null +++ b/data_cache/src/main/java/com/data/util/EventType.java @@ -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; +} diff --git a/data_cache/src/main/java/com/data/util/Utility.java b/data_cache/src/main/java/com/data/util/Utility.java new file mode 100644 index 0000000..c6631cb --- /dev/null +++ b/data_cache/src/main/java/com/data/util/Utility.java @@ -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 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 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 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 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 list = new ArrayList(partnerLev); + for(int i=start_par_lev-1;i 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 getChildParentList(int groupId,int uid,boolean self) { + String pl_key = String.format("g{%s}:par_list:%s",groupId,uid); + Set child_list = Redis.use("group1_db10").smembers(pl_key); + List 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 getMembersList(int groupId,int uid,boolean self) { + String pl_key = String.format("g{%s}:member_list:%s",groupId,uid); + Set child_list = Redis.use("group1_db10").smembers(pl_key); + List 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 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) 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 _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; + } + +} diff --git a/event_mgr/.idea/compiler.xml b/event_mgr/.idea/compiler.xml new file mode 100644 index 0000000..72058f1 --- /dev/null +++ b/event_mgr/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/.idea/encodings.xml b/event_mgr/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/event_mgr/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/event_mgr/.idea/jarRepositories.xml b/event_mgr/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/event_mgr/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/.idea/misc.xml b/event_mgr/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/event_mgr/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/event_mgr/.idea/vcs.xml b/event_mgr/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/event_mgr/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/event_mgr/build/local/taurus-core.xml b/event_mgr/build/local/taurus-core.xml new file mode 100644 index 0000000..3076fae --- /dev/null +++ b/event_mgr/build/local/taurus-core.xml @@ -0,0 +1,102 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.138.220.239:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/build/pro/log4j.properties b/event_mgr/build/pro/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/event_mgr/build/pro/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/event_mgr/build/pro/taurus-core.xml b/event_mgr/build/pro/taurus-core.xml new file mode 100644 index 0000000..cc81951 --- /dev/null +++ b/event_mgr/build/pro/taurus-core.xml @@ -0,0 +1,102 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.138.220.239:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/build/test/log4j.properties b/event_mgr/build/test/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/event_mgr/build/test/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/event_mgr/build/test/taurus-core.xml b/event_mgr/build/test/taurus-core.xml new file mode 100644 index 0000000..3076fae --- /dev/null +++ b/event_mgr/build/test/taurus-core.xml @@ -0,0 +1,102 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.138.220.239:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/pom.xml b/event_mgr/pom.xml new file mode 100644 index 0000000..86389d3 --- /dev/null +++ b/event_mgr/pom.xml @@ -0,0 +1,117 @@ + + 4.0.0 + com.evt + event_mgr + war + 1.0.0 + + UTF-8 + 1.8 + 1.8 + pro + + + + + junit + junit + 3.8.1 + test + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + mysql + mysql-connector-java + 8.0.16 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + org.quartz-scheduler + quartz + 2.2.3 + + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + + + ROOT + + + org.apache.maven.plugins + maven-war-plugin + + 1.8 + 1.8 + UTF-8 + logs/**,config/** + + + config/ + ${project.basedir}/build/${build.type}/ + + + + + + + + diff --git a/event_mgr/src/main/java/com/evt/mgr/EventController.java b/event_mgr/src/main/java/com/evt/mgr/EventController.java new file mode 100644 index 0000000..6eff42b --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/EventController.java @@ -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; + } +} diff --git a/event_mgr/src/main/java/com/evt/mgr/EventReceiver.java b/event_mgr/src/main/java/com/evt/mgr/EventReceiver.java new file mode 100644 index 0000000..cd5f251 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/EventReceiver.java @@ -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 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); + } + } + } + + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/EventServer.java b/event_mgr/src/main/java/com/evt/mgr/EventServer.java new file mode 100644 index 0000000..115535a --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/EventServer.java @@ -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(); + } + + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/GroupPublisherService.java b/event_mgr/src/main/java/com/evt/mgr/GroupPublisherService.java new file mode 100644 index 0000000..8208b7f --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/GroupPublisherService.java @@ -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()); + } +} diff --git a/event_mgr/src/main/java/com/evt/mgr/IHandler.java b/event_mgr/src/main/java/com/evt/mgr/IHandler.java new file mode 100644 index 0000000..3c47eff --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/IHandler.java @@ -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; +} diff --git a/event_mgr/src/main/java/com/evt/mgr/Utils.java b/event_mgr/src/main/java/com/evt/mgr/Utils.java new file mode 100644 index 0000000..2cbfb27 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/Utils.java @@ -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 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 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 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); + } + } + + } +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupMemberRound.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupMemberRound.java new file mode 100644 index 0000000..916203c --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupMemberRound.java @@ -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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupRound.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupRound.java new file mode 100644 index 0000000..c4cd1ea --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerGroupRound.java @@ -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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerHpConsume.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerHpConsume.java new file mode 100644 index 0000000..1ef6a95 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerHpConsume.java @@ -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, 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; + } +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerLose.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerLose.java new file mode 100644 index 0000000..6cf37c8 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerLose.java @@ -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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerOver.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerOver.java new file mode 100644 index 0000000..6aec1e0 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerOver.java @@ -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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerPay.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerPay.java new file mode 100644 index 0000000..7a48392 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerPay.java @@ -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 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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/handler/HandlerWin.java b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerWin.java new file mode 100644 index 0000000..dffc80f --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/handler/HandlerWin.java @@ -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; + } + +} diff --git a/event_mgr/src/main/java/com/evt/mgr/job/CleanGroupLogJob.java b/event_mgr/src/main/java/com/evt/mgr/job/CleanGroupLogJob.java new file mode 100644 index 0000000..105eb64 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/job/CleanGroupLogJob.java @@ -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(); + } + } +} diff --git a/event_mgr/src/main/java/com/evt/mgr/job/CleanTimeOutRoomJob.java b/event_mgr/src/main/java/com/evt/mgr/job/CleanTimeOutRoomJob.java new file mode 100644 index 0000000..ef67502 --- /dev/null +++ b/event_mgr/src/main/java/com/evt/mgr/job/CleanTimeOutRoomJob.java @@ -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 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 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 scanResult = jedis0.scan(cursor, scanParams); + cursor = scanResult.getStringCursor(); + List 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 scanResult = jedis11.scan(cursor, scanParams); + cursor = scanResult.getStringCursor(); + List list = scanResult.getResult(); + + for(int m = 0; m < list.size(); m++){ + + + String mapentry = list.get(m); + logger.info("正在查询群" +mapentry + "的无效房间"); + Set 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(); + } + } +} diff --git a/event_mgr/src/main/webapp/WEB-INF/web.xml b/event_mgr/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..7b0149b --- /dev/null +++ b/event_mgr/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + + taurus-web + com.taurus.web.WebFilter + + main + com.evt.mgr.EventServer + + + + + taurus-web + /* + + diff --git a/event_mgr/src/main/webapp/config/log4j.properties b/event_mgr/src/main/webapp/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/event_mgr/src/main/webapp/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/event_mgr/src/main/webapp/config/taurus-core.xml b/event_mgr/src/main/webapp/config/taurus-core.xml new file mode 100644 index 0000000..3076fae --- /dev/null +++ b/event_mgr/src/main/webapp/config/taurus-core.xml @@ -0,0 +1,102 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.138.220.239:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/event_mgr/src/test/java/Main.java b/event_mgr/src/test/java/Main.java new file mode 100644 index 0000000..be52d78 --- /dev/null +++ b/event_mgr/src/test/java/Main.java @@ -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(); + + } + +} diff --git a/game_common/pom.xml b/game_common/pom.xml new file mode 100644 index 0000000..d4bb088 --- /dev/null +++ b/game_common/pom.xml @@ -0,0 +1,85 @@ + + 4.0.0 + + com.game + game_common + 1.0.0 + jar + game_common + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_common-${version} + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_common/src/main/java/com/game/ActionEvent.java b/game_common/src/main/java/com/game/ActionEvent.java new file mode 100644 index 0000000..3dc1572 --- /dev/null +++ b/game_common/src/main/java/com/game/ActionEvent.java @@ -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"; +} diff --git a/game_common/src/main/java/com/game/Constant.java b/game_common/src/main/java/com/game/Constant.java new file mode 100644 index 0000000..e763591 --- /dev/null +++ b/game_common/src/main/java/com/game/Constant.java @@ -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; +} diff --git a/game_common/src/main/java/com/game/EventController.java b/game_common/src/main/java/com/game/EventController.java new file mode 100644 index 0000000..d253583 --- /dev/null +++ b/game_common/src/main/java/com/game/EventController.java @@ -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 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); + } +} diff --git a/game_common/src/main/java/com/game/GPSUtil.java b/game_common/src/main/java/com/game/GPSUtil.java new file mode 100644 index 0000000..314d63c --- /dev/null +++ b/game_common/src/main/java/com/game/GPSUtil.java @@ -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)); + } + +} diff --git a/game_common/src/main/java/com/game/GameController.java b/game_common/src/main/java/com/game/GameController.java new file mode 100644 index 0000000..f32d79b --- /dev/null +++ b/game_common/src/main/java/com/game/GameController.java @@ -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 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 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 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 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); + } +} diff --git a/game_common/src/main/java/com/game/GameInterceptor.java b/game_common/src/main/java/com/game/GameInterceptor.java new file mode 100644 index 0000000..98ed3fd --- /dev/null +++ b/game_common/src/main/java/com/game/GameInterceptor.java @@ -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); + } + } + } + }); + } + } + } + +} diff --git a/game_common/src/main/java/com/game/Global.java b/game_common/src/main/java/com/game/Global.java new file mode 100644 index 0000000..86b80a0 --- /dev/null +++ b/game_common/src/main/java/com/game/Global.java @@ -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, 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)); + } + } +} diff --git a/game_common/src/main/java/com/game/GroupPublisherService.java b/game_common/src/main/java/com/game/GroupPublisherService.java new file mode 100644 index 0000000..a36a684 --- /dev/null +++ b/game_common/src/main/java/com/game/GroupPublisherService.java @@ -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()); + } + +} diff --git a/game_common/src/main/java/com/game/MainServer.java b/game_common/src/main/java/com/game/MainServer.java new file mode 100644 index 0000000..1b02d41 --- /dev/null +++ b/game_common/src/main/java/com/game/MainServer.java @@ -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 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 list = Global.sessionMgr.getPlayerList(); + for (Player p : list) { + Global.sessionMgr.deleteSession(p.sender); + } + } + })); + } + + public abstract Room newRoom(String roomid, Map 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 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; + } +} diff --git a/game_common/src/main/java/com/game/Router.java b/game_common/src/main/java/com/game/Router.java new file mode 100644 index 0000000..d8e98b2 --- /dev/null +++ b/game_common/src/main/java/com/game/Router.java @@ -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); +} diff --git a/game_common/src/main/java/com/game/Util.java b/game_common/src/main/java/com/game/Util.java new file mode 100644 index 0000000..2e7a13e --- /dev/null +++ b/game_common/src/main/java/com/game/Util.java @@ -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 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 cardList) { + return checkCard(eventCard, cardList); + } + + @Deprecated + public static final ITArray toMPGroup(List 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 toModList(List list){ + List tem = new ArrayList(); + for(Integer card : list) { + tem.add(card % 100); + } + return tem; + } + + /** + * TArray to mod 100 list + * @param list + * @return + */ + public static final List toModList(ITArray list){ + List tem = new ArrayList<>(); + for(int i=0;i 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 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 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 cardList, int num) { + if (checkCard(eventCard, cardList, num)) { + removeCard(cardList, eventCard, num); + return true; + } + return false; + } + + /** + * 获取每张牌的数量MAP + * @param cardList + * @return + */ + public static final Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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 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 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 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; + } +} diff --git a/game_common/src/main/java/com/game/data/BasePlayBack.java b/game_common/src/main/java/com/game/data/BasePlayBack.java new file mode 100644 index 0000000..c721e31 --- /dev/null +++ b/game_common/src/main/java/com/game/data/BasePlayBack.java @@ -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 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); + } + +} diff --git a/game_common/src/main/java/com/game/data/Hp.java b/game_common/src/main/java/com/game/data/Hp.java new file mode 100644 index 0000000..863237a --- /dev/null +++ b/game_common/src/main/java/com/game/data/Hp.java @@ -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; +} diff --git a/game_common/src/main/java/com/game/data/JoinRoomData.java b/game_common/src/main/java/com/game/data/JoinRoomData.java new file mode 100644 index 0000000..9e9fbea --- /dev/null +++ b/game_common/src/main/java/com/game/data/JoinRoomData.java @@ -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; + +} diff --git a/game_common/src/main/java/com/game/data/Player.java b/game_common/src/main/java/com/game/data/Player.java new file mode 100644 index 0000000..c0125f0 --- /dev/null +++ b/game_common/src/main/java/com/game/data/Player.java @@ -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; + } + +} diff --git a/game_common/src/main/java/com/game/data/Room.java b/game_common/src/main/java/com/game/data/Room.java new file mode 100644 index 0000000..736eb9d --- /dev/null +++ b/game_common/src/main/java/com/game/data/Room.java @@ -0,0 +1,1871 @@ +package com.game.data; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +import com.data.bean.AccountBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupMemberCache; +import com.game.Constant; +import com.game.GPSUtil; +import com.game.Global; +import com.game.GroupPublisherService; +import com.game.MainServer; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPopupState; +import com.game.room.state.RoomDestoryGameState; +import com.game.room.state.RoomEndState; +import com.game.room.state.RoomInitState; +import com.game.state.StateMachine; +import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; +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.StringUtil; +import com.taurus.permanent.data.Session; + +import redis.clients.jedis.Jedis; + +/** + * 基本房间对象 + * + * + */ +public class Room implements Runnable { + /** + * 房间ID + */ + public String roomid = ""; + /** + * 房间redis_key + */ + public String room_key = ""; + /** + * 房间状态机 + */ + public StateMachine stateMachine; + /** + * 玩家列表ID映射 + */ + public final Map playerMapById = new HashMap(); + /** + * 玩家列表Seat映射 + */ + public final Map playerMapBySeat = new HashMap(); + /** + * 游戏中玩家列表 + */ + public final Map playerMapByPlaying = new HashMap(); + /** + * 观看列表 + */ + public final Map playerMapBySpectator = new HashMap(); + /** + * 房间配置数据 + */ + public ITObject config; + /** + * 房间最大人数 + */ + public int maxPlayers; + /** + * 开始游戏数量 0 首位开始 > + */ + public int startGameNum; + + private Thread roomUpdateThread; + /** + * 房间是否被激活 + */ + private volatile boolean isActive = false; + /** + * 房间是否被销毁 + */ + public volatile boolean isDestroy = false; + final BlockingQueue updateHandleList = new LinkedBlockingQueue(); + final List timerList = new ArrayList<>(); + /** + * 当前激活的座位号 + */ + public int activeSeat = 0; + /** + * 庄家座位号 + */ + public int bankerSeat = 0; + /** + * 房主ID + */ + public int owner_id = 0; + /** + * 局數 + */ + public Integer round = 0; + /** + * 最大回合数 + */ + public int maxRound = 0; + /** + * 服务器重连 + */ + public boolean serverRload = false; + /** + * 是否开始 + */ + public boolean isplaying = false; + + /** + * 是否禁止解散 + */ + public boolean isBanDismiss = false; + + /** + * 房间解散处理对象 + */ + public RoomDismiss dismissRunable; + /** + * 当前房间对象逻辑锁 + */ + public Object lock = new Object(); + /** + * 房间数据redis映射 + */ + public Map redis_room_map; + /** + * 战绩回放redis key + */ + public String military_key; + /** + * 退还 + */ + public int pay = 0; + /** + * 支付人玩家ID + */ + public int pay_playerid = 0; + /** + * 是否AA支付 + */ + public boolean pay_AA = false; + /** + * 是否是代理房间 + */ + public boolean agent = false; + /** + * 0 未开始 1开始 2删除标记 3已删除 + */ + public int status = 0; + /** + * 圈子ID + */ + public int groupId = 0; + /** + * 圈子玩法ID + */ + public int groupPid = 0; + /** + * 奖励类型 + */ + public int rewardType = 1; + public int rewardValueType = 1; + public int basePump = 0; + public int totalPump = 0; + + public int xipai_rewardType = 1; + public int xipai_rewardValueType = 1; + + /** + * 人头制时,是否需要奖励 + */ + public boolean aHeadReward = true; + + /** + * 限制进入房间 limitInRoom 限制抢庄 limitloot 退出游戏体力值限制 limitPlay 抽水设置 limitPump (0 + * --大赢家抽水 ; 1 --全部赢家抽水) 抽水比例 pumpProportion 单人单局抽水上限 UpperLimit 抽水类型 type + * 1.固定抽水 : 2.浮动抽水(百分比) 倍数 times + */ + public ITObject hpData; + /** + * 是否打开托管 + */ + public boolean openEntrust; + /** + * 托管时间 + */ + public int entrustTime = 60000; + /** + * 1 单局结束 大结算 2 局满结算 3 局结算 + */ + public int entrusResultType = 1; + /** + * 默认托管时间 500ms + */ + public int default_entrust_time = 2000; + /** + * 计时器默认时间 + */ + public int def_actionTimer_time = 1000; + /** + * 踢出时间 + */ + public int kickTime = 0; + /** + * 回放数据 + */ + public BasePlayBack playBackData; + /** + * 是否托管玩法。 + */ + public boolean isEntrust = false; + /** + * 游戏结束类型 1-正常结束 2-托管当局大结算 3-体力值不足 4-中途申请解散 + */ + public int endType = Constant.END_TYPE_NORMAL; + + public List win, loss; + /** + * 当前局战绩是否已存储 + */ + public boolean roundSave = false; + + /** + * 进入玩家 + */ + public Player join_player; + + public boolean while_list = false; + + public double white_value = 20; + + public int xi_pai_score = 0; + + public long upper_limit_hp = 0; + + public Room(String roomid, Map redis_room_map) { + this.roomid = roomid; + this.room_key = "room:" + roomid; + if (owner_id == 0) { + String owner_key = redis_room_map.get("owner"); + String ownerid = Redis.use().hget(owner_key, "id"); + owner_id = Integer.parseInt(ownerid); + military_key = "military_" + roomid + redis_room_map.get("create_time"); + } + + this.stateMachine = new StateMachine(this); + this.stateMachine.changeState(Global.getState(RoomInitState.class)); + redis_room_map.remove("cache_ver"); + this.redis_room_map = redis_room_map; + this.win = new ArrayList<>(); + this.loss = new ArrayList<>(); + this.config = TObject.newFromJsonData(redis_room_map.get("options")); + this.maxPlayers = Integer.parseInt(redis_room_map.get("maxPlayers")); + this.maxRound = Integer.parseInt(redis_room_map.get("times")); + this.config.putInt("maxPlayers", this.maxPlayers); + this.config.putInt("times", this.maxRound); + this.pay = Integer.parseInt(redis_room_map.get("pay")); + this.pay_playerid = Integer.parseInt(redis_room_map.get("payer")); + this.pay_AA = Integer.parseInt(redis_room_map.get("AA")) == 1; + this.config.putInt("AA", this.pay_AA ? 1 : 0); + this.agent = Integer.parseInt(redis_room_map.get("agent")) > 0; + this.status = Integer.parseInt(redis_room_map.get("status")); + if (this.config.containsKey("start_num")) { + this.startGameNum = this.config.getInt("start_num"); + } else { + this.startGameNum = this.maxPlayers; + } + + Integer str = config.getInt("isBanDismiss");// 0 / 1 + if (str != null && str == 1) { + this.isBanDismiss = true; + } else { + this.isBanDismiss = false; + } + + this.dismissRunable = new RoomDismiss(this); + this.xi_pai_score = 0; + if (redis_room_map.containsKey("group")) { + groupId = Integer.parseInt(redis_room_map.get("group")); + if (groupId > 0) { + if (redis_room_map.containsKey("dismiss_time")) { + this.dismissRunable.maxTime = Integer.parseInt(redis_room_map.get("dismiss_time")); + } + if (redis_room_map.containsKey("kick_time")) { + this.kickTime = Integer.parseInt(redis_room_map.get("kick_time")); + } + groupPid = Integer.parseInt(redis_room_map.get("gpid")); + rewardType = Integer.parseInt(redis_room_map.get("rewardType")); + if (redis_room_map.get("rewardValueType") != null) { + rewardValueType = Integer.parseInt(redis_room_map.get("rewardValueType")); + } + + if (redis_room_map.get("xipai_rewardType") != null) { + xipai_rewardType = Integer.parseInt(redis_room_map.get("xipai_rewardType")); + } + + if (redis_room_map.get("xipai_rewardValueType") != null) { + xipai_rewardValueType = Integer.parseInt(redis_room_map.get("xipai_rewardValueType")); + } + + if (this.config.containsKey("hpData")) { + hpData = this.config.getTObject("hpData"); + + if (hpData.containsKey("basePump")) { + basePump = hpData.getInt("basePump") / 2; + } + } + if (this.config.containsKey("tuoguan_active_time")) { + this.entrustTime = this.config.getInt("tuoguan_active_time") * 1000; + this.openEntrust = this.entrustTime > 0; + this.entrusResultType = this.config.getInt("tuoguan_result_type"); + } + + } + } + } + + /** + * 决定总结算方式 + * + * @return true : 总结算 + */ + protected boolean totalType() { + return this.round >= this.maxRound; + } + + public void start() { + if (isActive) + return; + Global.logger.info(room_key + " thread start"); + last_read_status_time = 0; + roomUpdateThread = new Thread(this, room_key + "_" + round); + roomUpdateThread.start(); + isActive = true; + } + + private void handleTimer(int index) { + if (isDestroy) { + return; + } + if (timerList.size() > index) { + Timer timer = timerList.get(index); + if (timer.isRuning()) { + timer.executeTask(); + handleTimer(index + 1); + } else { + synchronized (timerList) { + timerList.remove(index); + } + handleTimer(index); + } + } + } + + private void handleTask() { + if (isDestroy) { + return; + } + if (updateHandleList.size() > 0) { + Runnable tem = null; + synchronized (updateHandleList) { + tem = updateHandleList.poll(); + } + if (tem == null) + return; + tem.run(); + handleTask(); + } + } + + private long last_read_status_time = 0; + + public void run() { + Global.logger.info(room_key + " thread run"); + while (isActive && !isDestroy) { + try { + synchronized (lock) { + if (System.currentTimeMillis() - last_read_status_time > 1000) { + last_read_status_time = System.currentTimeMillis(); + String status = Redis.use().hget(room_key, "status"); + if (StringUtil.isNotEmpty(status)) { + int tem = Integer.parseInt(status); + if (tem == Constant.ROOM_STATUS_DEL_FALG || tem == Constant.ROOM_STATUS_DEL_FALG) { + Global.roomMgr.dismissRoom(roomid, false); + continue; + } + } else { + Global.roomMgr.dismissRoom(roomid, false); + continue; + } + } + handleTimer(0); + if (isDestroy) + continue; + handleTask(); + if (isDestroy) + continue; + } + Thread.sleep(5); + } catch (InterruptedException e) { + isActive = false; + Global.logger.error("[" + room_key + "] room thread interrupted!"); + } catch (Throwable t) { + Global.logger.error("[" + room_key + "] exception!", t); + } + } + Global.logger.info(room_key + " thread stop"); + } + + /** + * add queue runnable + * + * @param runnable + */ + public void enqueueRunnable(Runnable runnable) { + if (!isActive) + return; + if (runnable == null) + return; + synchronized (updateHandleList) { + updateHandleList.add(runnable); + } + } + + /** + * 单线程计时器 + * + * @param timer + */ + public void addTimer(Timer timer) { + if (!isActive) + return; + if (timer == null) + return; + synchronized (timerList) { + timerList.add(timer); + timer.start(); + } + } + + /** + * 开始游戏改变状态 + */ + public void startGame() { + while_list = false; + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + player.clear(); + if (player.stateMachine.curState instanceof PlayerPopupState) { + continue; + } + player.already_round++; + player.ready = false; + player.is_white = false; + player.black_white_status = 0; + String gm_key = GroupMemberCache.genKey(this.groupId, player.playerid); + String black_key = Redis.use("group1_db10").hget(gm_key, "group_black_key"); + if (StringUtil.isEmpty(black_key)) { + black_key = gm_key; + } + + String black = Redis.use("group1_db10").hget(black_key, "black"); + String black_rate = Redis.use("group1_db10").hget(black_key, "group_black_rate"); + + if (StringUtil.isNotEmpty(black) && black.equals("0")) { + player.black_white_status = 0; + player.black_white_rate = 0; + } else if (StringUtil.isNotEmpty(black) && black.equals("1")) { + player.black_white_status = 1; + if (StringUtil.isNotEmpty(black_rate)) { + try { + player.black_white_rate = Integer.parseInt(black_rate); + } catch (NumberFormatException e) { + player.black_white_rate = 10; + } + } + } else if (StringUtil.isNotEmpty(black) && black.equals("2")) { + player.black_white_status = 2; + if (StringUtil.isNotEmpty(black_rate)) { + try { + player.black_white_rate = Integer.parseInt(black_rate); + } catch (NumberFormatException e) { + player.black_white_rate = 10; + } + } + } else { + player.black_white_status = 0; + player.black_white_rate = 0; + } + + if (Redis.use("group1_db1").sismember("gods", Integer.toString(player.playerid))) { + player.is_white = true; + while_list = true; + String StrGameWhiteValue = Redis.use("group1_db1").hget("gods_game_value", + Integer.toString(Global.gameId)); + if (StringUtil.isNotEmpty(StrGameWhiteValue)) { + Global.logger.info("xingyuhao gods_game_value:" + Global.gameId + " rate:" + StrGameWhiteValue); + white_value = Integer.parseInt(StrGameWhiteValue); + if (white_value > 100) { + white_value = 0; + } else if (white_value <= 0) { + white_value = 100; + } else { + white_value = 100 - white_value; + } + } else { + String StrWhiteValue = Redis.use("group1_db1").hget("gods_value", + Integer.toString(player.playerid)); + if (StringUtil.isNotEmpty(StrWhiteValue)) { + white_value = Integer.parseInt(StrWhiteValue); + if (white_value > 100) { + white_value = 0; + } else if (white_value <= 0) { + white_value = 100; + } else { + white_value = 100 - white_value; + } + } else { + white_value = 100; + } + } + } + player.initSeat(); + this.playerMapByPlaying.put(player.playerid, player); + } + if (this.round == 0 && this.status == Constant.ROOM_STATUS_NOBEGIN) { + this.status = Constant.ROOM_STATUS_PLAYING; + this.redis_room_map.put("status", this.status + ""); + Redis.use().hset(this.room_key, "status", this.status + ""); + this.redis_room_map.put("open", "0"); + Redis.use().hset(this.room_key, "open", "0"); + + } + this.round++; + this.isplaying = true; + this.roundSave = false; + this.updateRound(); + this.clearHp(); + } + + /** + * 房间小结算 + */ + protected void roomResult() { + + } + + public void CountXiPai() { + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.xi_pai) { + player.xi_pai = false; + } + + // redisUpdateXiPaiPlayer(player); + } + } + + /** + * 游戏结束 + */ + public void endGame() { + boolean total = totalType(); + // if (!total) + // total = entrustTotal(); + Global.logger.info("total: " + total); + CountXiPai(); + CheckModifyHp(); + boolean settlement = redisUpdateHp();// 结算分数 + // total = total || settlement; + Global.logger.info("total: " + total); + this.saveRecRound(); + + if (total) { + this.saveMilitaryTotal(false); + } else { + roomResult(); + } + Global.logger.info("total: " + total); + for (Entry entry : this.playerMapById.entrySet()) { + + Player player = entry.getValue(); + if (player.manualAutoCard) { + player.manualAutoCard = false; + // player.exitEntrust(); + if (player.room.isEntrust()) { + // Global.gameCtr.cancelEntrust(player); + player.entrust = false; + Global.gameCtr.updatePlayerEntrust(player); + } + } + Global.logger.info("player.score.total_score: " + player.score.total_score); + + } + Global.logger.info("total: " + total); + if (total) { + this.stateMachine.changeState(Global.getState(RoomDestoryGameState.class)); + } else { + this.stateMachine.changeState(Global.getState(RoomEndState.class)); + this.playerMapByPlaying.clear(); + this.clear(); + } + + } + + /** + * 保存积分 + */ + public void saveSocre() { + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + redis_room_map.put(player.score_key, player.score.total_score + ""); + } + Redis.use().hmset(this.room_key, redis_room_map); + } + + /** + * + * @param player_id + */ + protected Player loadReloadPlayer(int player_id, int seat) { + AccountBean acc = AccountCache.getAccount(player_id); + Player player = MainServer.instance.newPlayer(player_id, this, acc.redis_key); + player.seat = seat; + player.nick = acc.nick; + player.sex = acc.sex; + player.portrait = acc.portrait; + String score_str = this.redis_room_map.get(player.score_key); + int num = StringUtil.isNotEmpty(score_str) ? Integer.parseInt(score_str) : 0; + player.score.total_score = num; + player.setSender(null); + player.offlineTime = System.currentTimeMillis(); + this.redis_room_map.put(player.net_key, player.offlineTime + ""); + player.already_round = this.round; + player.hp.cur_hp = Util.readRedisHp(this.groupId, player.playerid); + if (groupId > 0) { + player.prs = redis_room_map.get("prs_" + player.playerid); + } + addPlayer(player, true, true); + return player; + } + + /** + * 服务器重连恢复玩家数据 + */ + public void loadRedisPlayer() { + if (this.redis_room_map != null && this.redis_room_map.containsKey("players")) { + this.serverRload = true; + this.status = Integer.parseInt(this.redis_room_map.get("status")); + if (this.redis_room_map.containsKey("round")) { + this.round = Math.max(Integer.parseInt(this.redis_room_map.get("round")) - 1, 0); + } + ITArray players = TArray.newFromJsonData(this.redis_room_map.get("players")); + ITArray seats = TArray.newFromJsonData(this.redis_room_map.get("seats")); + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + this.loadReloadPlayer(player_id, seats.getInt(i)); + } + } + + } + + /** + * 添加玩家,加入房间 + * + * @param player + * @param reload + */ + public void addPlayer(Player player, boolean reload, boolean onseat) { + if (!reload) { + if (onseat) { + player.seat = this.getSeat(); + } + Redis.use().hset(player.session_id, "seat", player.seat + ""); + if (groupId > 0) { + + player.prs = Redis.use().hget(this.room_key, "prs_" + player.playerid); + } + this.redis_room_map.remove(player.net_key); + this.redis_room_map.put(player.score_key, "0"); + // 不是支付人,不是代理房间的AA至,由游戏服发送扣钱事件 + // if (this.pay_AA && this.pay > 0) { + // if ((player.playerid != this.pay_playerid && !this.agent) || this.agent) { + // Global.eventCtr.payDiamo(player, pay, groupId); + // } + // } + } + if (onseat) { + this.playerMapBySeat.put(player.seat, player); + } else { + this.playerMapBySpectator.put(player.playerid, player); + } + this.playerMapById.put(player.playerid, player); + + if (!reload && onseat) { + updateRedisMap(); + } + } + + /** + * 观众席入座 + * + * @param owner + */ + public boolean joinSeat(Player owner) { + if (owner.spectator) { + int seat = this.getSeat(); + if (seat == 0) + return false; + if (!this.playerMapBySeat.containsKey(seat)) { + owner.ready = true; + owner.seat = seat; + this.playerMapBySeat.put(owner.seat, owner); + this.playerMapBySpectator.remove(owner.playerid); + updateRedisMap(); + return true; + } + } + return false; + } + + /** + * 离开座位到观众席 + * + * @param player + */ + public boolean exitSeat(Player player) { + if (this.playerMapBySeat.containsKey(player.seat)) { + if (!this.isplaying && player.seat == this.bankerSeat) { + if (this.playerMapBySeat.size() > 1) { + for (Player tem : this.playerMapBySeat.values()) { + tem.initSeat(); + } + this.bankerSeat = player.nextSeat; + } else { + this.bankerSeat = 0; + } + } + this.playerMapBySeat.remove(player.seat); + this.playerMapBySpectator.put(player.playerid, player); + updateRedisMap(); + return true; + } + return false; + } + + /** + * 刪除玩家,退出房间 + * + * @param player + */ + public void removePlayer(Player player, boolean sysredis) { + this.playerMapBySeat.remove(player.seat); + this.playerMapById.remove(player.playerid); + this.playerMapByPlaying.remove(player.playerid); + this.playerMapBySpectator.remove(player.playerid); + if (this.status == 0 && this.pay > 0) { + if (this.pay_AA) { + Global.eventCtr.refundDiamo(player.playerid, pay, groupId, groupPid); + } else if (this.pay_playerid == player.playerid && !this.agent) { + Global.eventCtr.refundDiamo(player.playerid, pay, groupId, groupPid); + } + } + Global.gameCtr.delRoomSeat(player.session_id, this.room_key); + if (sysredis) { + redis_room_map.remove(player.score_key); + updateRedisMap(); + } + } + + /** + * 更新房间redis数据 + */ + public void updateRedisMap() { + Iterator> it = playerMapBySeat.entrySet().iterator(); + List seat_list = new ArrayList<>(); + List player_list = new ArrayList<>(); + while (it.hasNext()) { + Entry entry = (Entry) it.next(); + seat_list.add(entry.getKey()); + player_list.add(entry.getValue().playerid); + } + redis_room_map.put("players", Util.toTArray(player_list).toJson()); + redis_room_map.put("seats", Util.toTArray(seat_list).toJson()); + Redis.use().hmset(this.room_key, redis_room_map); + roomUpdateEvent(); + } + + /** + * 获取房间信息 + * + * @return + */ + public ITObject getRoomInfo(Player self) { + ITObject data = new TObject(); + data.putTObject("config", this.config); + data.putInt("round", this.round); + + TArray playerData = new TArray(); + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + playerData.addTObject(player.getInfo()); + } + data.putTArray("playerData", playerData); + data.putInt("xipai_score", this.xi_pai_score); + return data; + + } + + /** + * 获取重连数据 + * + * @return + */ + public ITObject getReloadInfo(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player self = (Player) entry.getValue(); + Global.logger.info("self.playerid:" + self.playerid); + Global.logger.info("player.playerid:" + player.playerid); + if (self.playerid == player.playerid) { + info_list.addTObject(entry.getValue().getReloadInfo(true)); + } else { + info_list.addTObject(entry.getValue().getReloadInfo(false)); + + } +// info_list.addTObject(entry.getValue().getReloadInfo()); + } + data.putTArray("info_list", info_list); + return data; + } + + /** + * 广播消息到客户端 + * + * @param withOutPlayerid 排除的玩家ID0+ 0 + * @param cmd 协议指令 + * @param param 协议数据 + */ + public void broadCastToClient(int withOutPlayerid, String cmd, ITObject param) { + if (!isActive) + return; + List list = new ArrayList(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.playerid == withOutPlayerid) { + continue; + } + if (!player.isConnect) + continue; + list.add(player.sender); + } + MainServer.instance.sendEvent(cmd, param, list); + } + + /** + * 广播服务器事件 + * + * @param withOutPlayerid 排除的玩家ID + * @param cmd + * @param param + */ + public void broadCastToServer(int withOutPlayerid, String cmd, Object param) { + if (!isActive) + return; + for (Entry entry : this.playerMapByPlaying.entrySet()) { + Player player = entry.getValue(); + if (player.playerid == withOutPlayerid) + continue; + player.stateMachine.execute(cmd, 0, param); + } + + } + + /** + * 获取当前房间空闲座位号 + * + * @return + */ + public int getSeat() { + if (!isActive) + return 1; + for (int seat = 1; seat <= this.maxPlayers; seat++) { + if (!this.playerMapBySeat.containsKey(seat)) { + return seat; + } + } + return 1; + } + + /** + * 更新redis回合 + */ + private void updateRound() { + redis_room_map.put("round", this.round.toString()); + this.roomUpdateThread.setName(room_key + "_" + round); + Redis.use().hset(this.room_key, "round", this.round.toString()); + roomUpdateEvent(); + } + + /** + * 更新redis玩家离线 + * + * @param player + */ + public void updatePlayerOffline(Player player) { + if (player.seat == 0) + return; + if (player.isConnect) { + redis_room_map.remove(player.net_key); + Redis.use().hdel(this.room_key, player.net_key); + } else { + player.offlineTime = System.currentTimeMillis(); + redis_room_map.put(player.net_key, player.offlineTime + ""); + Redis.use().hset(this.room_key, player.net_key, redis_room_map.get(player.net_key)); + } + roomUpdateEvent(); + } + + /** + * 每局的战绩 + * + */ + public void saveRecRound() { + if (this.playBackData == null || roundSave) + return; + ITArray plist = TArray.newInstance(); + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + if (!jedis5.exists(military_key)) { + Map militart_map = new HashMap<>(); + militart_map.put("game_id", Global.gameId + ""); + militart_map.put("room_id", roomid); + militart_map.put("groupId", this.groupId + ""); + militart_map.put("create_time", redis_room_map.get("create_time")); + int hp_times = this.hpData != null ? this.hpData.getInt("times") : 0; + militart_map.put("hp_times", hp_times + ""); + militart_map.put("groupPid", this.groupPid + ""); + jedis5.hmset(military_key, militart_map); + } + jedis5.hset(military_key, "round", this.round.toString()); + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + ITObject pdata = TObject.newInstance(); + pdata.putUtfString("nick", player.nick); + pdata.putInt("score", player.score.round_score); + if (player.hp != null) { + pdata.putInt("hp", player.hp.round_actual_hp); + } + + plist.addTObject(pdata); + } + jedis5.hset(military_key, "round_" + this.round, plist.toJson()); + String json = this.playBackData.getData().toJson(); + jedis5.hset(military_key, "rec_" + this.round, json); + + Global.logger.info("json: " + json); + + roundSave = true; + } finally { + jedis5.close(); + } + } + + /** + * 总战绩 + */ + public void saveMilitaryTotal(boolean dissmiss) { + if (dissmiss) { + saveRecRound(); + } + this.endType = dissmiss ? Constant.END_TYPE_DISSMISS : this.endType; + int scoreWin = 0; + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + boolean hpPump = false; + + int totalPumpHp = 0; + int roomMoney = 0; + int pumpProportion = 0; + int UpperLimitRewardsub = 0; + try { + ITArray plist = TArray.newInstance(); + boolean isMilitary = jedis5.exists(military_key); + int time = (int) (System.currentTimeMillis() / 1000); + + totalPumpHp = roomPlayerHpPump(); + + for (Entry entry : this.playerMapBySeat.entrySet()) { + + Player player = entry.getValue(); + if (player.already_round == 0) + continue; + Global.eventCtr.redisOver(player, time, isMilitary ? military_key : null); + if (this.agent && this.groupId > 0) { + if (player.hp.total_hp > scoreWin) { + scoreWin = player.hp.total_hp; + } + + if (player.practicalHpPump > 0) { + hpPump = true; + } + } + ITObject pdata = TObject.newInstance(); + pdata = TObject.newInstance(); + pdata.putUtfString("nick", player.nick); + pdata.putUtfString("portrait", player.portrait); + pdata.putInt("score", player.score.total_score); + if (player.hp != null) { + int total_hp = player.hp.total_hp - player.practicalHpPumpReal; +// total_hp = Math.abs(total_hp) > player.room.upper_limit_hp ? (int) player.room.upper_limit_hp +// : total_hp; + pdata.putInt("hp", total_hp); + +// pdata.putInt("hp", player.hp.total_hp - player.practicalHpPump); + } + + pdata.putInt("accId", player.playerid); + plist.addTObject(pdata); + } + + // 人头制-是否需要奖励 + // 以大赢家为标准 -2019.12.23 + if (this.hpData != null) { + + int type = this.hpData.containsKey("type") ? this.hpData.getInt("type") : 2; + if (type == 1) { + + if (this.hpData.containsKey("rewards_list")) { + + ITArray rewards_list = this.hpData.getTArray("rewards_list"); + if (rewards_list.size() > 0) { + pumpProportion = rewards_list.getTObject(0).getInt("pumpProportion"); + + if (rewards_list.getTObject(0).containsKey("UpperLimitRewardsub")) { + UpperLimitRewardsub = rewards_list.getTObject(0).getInt("UpperLimitRewardsub"); + } + + } + } + int lowerThanValue = 0; + if (hpData.containsKey("UpperLimitReward") && hpData.getInt("UpperLimitReward") > 0) { + + if (hpData.containsKey("UpperLimit")) { + lowerThanValue = hpData.getInt("UpperLimit"); + roomMoney = hpData.getInt("UpperLimitReward"); + } + + } else if (this.hpData.containsKey("rewards_list")) { + // 新浮动抽水数据 + ITArray rewards_list = this.hpData.getTArray("rewards_list"); + if (rewards_list.size() > 0) { + + lowerThanValue = rewards_list.getTObject(0).getInt("UpperLimit"); + if (rewards_list.getTObject(0).containsKey("UpperLimitReward")) { + roomMoney = rewards_list.getTObject(0).getInt("UpperLimitReward"); + } + } + } + + if (scoreDesc().size() > 0 && scoreDesc().get(0).hpPumpValue() < lowerThanValue && roomMoney > 0) { + aHeadReward = false; + } else { + roomMoney = 0; + } + } + } + + if (isMilitary) { + Map map = new HashMap<>(); + map.put("totalScore", plist.toJson()); + if (hpData != null) { + map.put("hpData", hpData.toJson()); + } + map.put("create_time", time + ""); + jedis5.hmset(military_key, map); + jedis5.expire(military_key, 3600 * 24 * 3); + } + } finally { + jedis5.close(); + } + + if (totalPumpHp > 0) { + if (totalPumpHp >= basePump) { + this.totalPump = totalPumpHp - basePump; + } else { + this.totalPump = 0; + } + + } + + if (this.agent && this.groupId > 0) { + Global.eventCtr.redisGroupRound(this, groupId, groupPid, hpPump ? 1 : 0); +// Global.eventCtr.redisGroupRound(this, groupId, groupPid,1); + + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.already_round == 0) + continue; + if (aHeadReward == false && roomMoney > 0) { + player.practicalHpPump += roomMoney; + this.totalPump += roomMoney; + } + } + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.already_round == 0) + continue; + + long curHp = 0; + + // 设置保底 + if (scoreWin > pumpProportion) { + this.basePump = 0; + } + Global.logger.info("scoreWin:" + scoreWin + "|room.basepump:" + this.basePump + + "room UpperLimitRewardsub" + UpperLimitRewardsub); + Global.logger.info("roomMoney:" + roomMoney + "|room.basepump:" + this.basePump + "hpPump" + hpPump + + "practicalHpPump:" + player.practicalHpPump + "aHeadReward:" + aHeadReward); + // 抽水 + if (aHeadReward == false && roomMoney > 0) { + if (UpperLimitRewardsub == 1) { + // 只扣赢家 + if (player.hp.total_hp > 0 && scoreWin > 0) { + player.practicalHpPumpReal = roomMoney; + this.basePump = 0; + } else { + player.practicalHpPump = 0; + } + } else { + // 扣两人 + if (scoreWin > 0) { + player.practicalHpPumpReal = roomMoney; + this.basePump = 0; + } + + } +// if (this.basePump != 0) { +// player.practicalHpPump = 0; +// player.practicalHpPumpReal = 0; +// } + if (player.hp.total_hp > 0 && scoreWin > 0) { + curHp = Global.eventCtr.redisFag(player, 0, hpPump || player.practicalHpPump > 0, true, 0, + false, null); + } else { + curHp = Global.eventCtr.redisFag(player, 0, hpPump || player.practicalHpPump > 0, true, 0, + false, null); + } + } else { +// if (this.basePump != 0) { +// player.practicalHpPump = 0; +// player.practicalHpPumpReal = 0; +// } + curHp = Global.eventCtr.redisFag(player, player.hp.total_hp, hpPump || player.practicalHpPump > 0, false, 0, false, + null); + + } + Global.logger.info("scoreWin:" + scoreWin + "|room.basepump:" + this.basePump + + "room practicalHpPumpReal" + player.practicalHpPumpReal); + Global.eventCtr.redisGroupMemberRound(player, this.groupPid, + scoreWin > 0 && player.hp.total_hp == scoreWin, hpPump, (int) curHp); + // 游戏积分记录 + } + } + + } + + public int getValidPlayer() { + int count = 0; + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.already_round == 0) + continue; + + count++; + } + return count; + } + + public ITArray getValidPlayerList() { + ITArray array = TArray.newInstance(); + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.already_round == 0) + continue; + + array.addInt(player.playerid); + } + return array; + } + + /** + * 清理房间数据 + */ + public void clear() { + this.isplaying = false; + this.while_list = false; + } + + /** + * 房间摧毁时调用 + */ + public void destroy(boolean sendEvt) { + if (isDestroy) + return; + + this.broadCastToClient(0, Router.GAME_EVT_EXIT_ROOM_DISMISS, null); + List playerlist = new ArrayList(this.playerMapById.values()); + for (Player player : playerlist) { + player.destroy(false); + } + this.status = Constant.ROOM_STATUS_DEL; + Redis.use().hset(room_key, "status", this.status + ""); + Redis.use().hincrBy(room_key, "cache_ver", 1); + Redis.use().expire(room_key, 20); + if (sendEvt && this.groupId > 0) { + GroupPublisherService.delRoomEvt(groupId, roomid); + } + isDestroy = true; + isActive = false; + + this.timerList.clear(); + this.playerMapById.clear(); + this.playerMapBySeat.clear(); + this.playerMapByPlaying.clear(); + this.playerMapBySpectator.clear(); + roomUpdateThread.interrupt(); + } + + public String toString() { + return room_key; + } + + /** + * 房间需要抽水玩家 特殊情况 : 分数一样,同时抽 Ps : A = 20 、 B=15 、C = 15 、 D = - 50 抽水规则 : 前2名 , 抽 + * A B C + */ + private int roomPlayerHpPump() { + + int totalPump = 0; + + if (this.hpData != null) { + List pumpPlay = new ArrayList<>(); + // limitPump-抽水类型 0.大赢家抽水1.所有赢家抽水2.前两名赢家抽水 3.前3名赢家抽水 4.(固定)所有玩家平分抽水(2019.11.5 + // 新增),以大赢家为基础,判定是否需要抽水 + // criterion-固定平分时,以什么为标准判断是否需要抽水 + int limitPump = hpData.containsKey("limitPump") ? hpData.getInt("limitPump") : 0, criterion = 0; + if (limitPump == 0 || limitPump == 4) {// 大赢家抽水 // (固定)所有玩家平分抽水 + List list = scoreDesc(); + if (list.size() == 0) + return 0; + Player winner = list.get(0); + if (winner.hpPumpValue() <= 0) + return 0; + if (limitPump == 0) { + pumpPlay.add(winner); + // 与排序后第一位玩家分数相等的玩家也需要抽水 + pumpPlay.addAll(scoreEq(winner)); + } else { + pumpPlay.addAll(alreadyRoundPlayer()); + criterion = winner.hpPumpValue(); + } + } else if (1 <= limitPump && limitPump <= 3) { + if (limitPump == 1) { + alreadyRoundPlayer().forEach(player -> { + if (player.hpPumpValue() >= 0) { + pumpPlay.add(player); + } + }); + } else if (limitPump > 1) { + int num = 0, temp_hp = 0; + for (Player player : scoreDesc()) { + if (player.hpPumpValue() >= 0) { + pumpPlay.add(player); + if (temp_hp != player.hpPumpValue()) { + num++; + } + if (num == limitPump) { + pumpPlay.addAll(scoreEq(player)); + break; + } else { + temp_hp = player.hpPumpValue(); + } + } + } + } + } + for (Player player : pumpPlay) { + totalPump += hpPump(player, limitPump, criterion); + } + } + + return totalPump; + } + + /** + * 具体抽水体力值(向下取整) + * + * @param player + * @param limitPump 抽水类型 + * @param criterion 固定平分时,以什么为标准判断是否需要抽水 + */ + private int hpPump(Player player, int limitPump, int criterion) { + try { + // 抽水类型 1.固定 2.浮动 + int type = this.hpData.containsKey("type") ? this.hpData.getInt("type") : 2; + // _upperLimit : + // 浮动抽水 : 每局每人抽水上限 0 = 没上限 + // 固定抽水 : 每局每人多少开始抽水,是否达到抽水条件 + // + // _pumpProportion : 抽水具体数值, 浮动 - 1=1% 、2=2%.. 固定 - 10 、20.. + // practicalHpPump : 实际抽水抽得到体力值 + int _upperLimit = 0, _pumpProportion = 0, practicalHpPump = 0; + if (type == 1) { + // 固定抽水具体数值 1、2、3、4...10、20、30、40、50..... + // 修改 :新增 期间固定抽水 2019.11.01 + if (hpData.containsKey("pumpProportion") && hpData.containsKey("UpperLimit")) { + // 兼容老数据 + _upperLimit = hpData.getInt("UpperLimit"); + _pumpProportion = hpData.getInt("pumpProportion"); + if (limitPump == 4) { + // 以大赢家为基础,判断此次是否需要抽水 + practicalHpPump = criterion >= _upperLimit + ? (int) Math.ceil(_pumpProportion / alreadyRoundPlayer().size()) + : 0; + } else { + practicalHpPump = player.hpPumpValue() >= _upperLimit ? _pumpProportion : 0; + } + } else if (this.hpData.containsKey("rewards_list")) { + // 新数据 - 期间 + ITArray rewards_list = this.hpData.getTArray("rewards_list"); + for (int i = rewards_list.size() - 1; i >= 0; i--) { + ITObject object = rewards_list.getTObject(i); + _upperLimit = object.getInt("UpperLimit"); + _pumpProportion = object.getInt("pumpProportion"); + if (limitPump == 4) { + if (criterion >= _upperLimit) { + practicalHpPump = (int) Math.ceil(_pumpProportion / alreadyRoundPlayer().size()); + break; + } + } else { + if (player.hpPumpValue() >= _upperLimit) { + practicalHpPump = _pumpProportion; + break; + } + } + } + } + } else if (type == 2 && limitPump != 4) { + // pumpProportion : 1=1% 、2=2% + // 老数据 + if (hpData.containsKey("pumpProportion") && hpData.containsKey("UpperLimit")) { + _upperLimit = hpData.getInt("UpperLimit"); + _pumpProportion = hpData.getInt("pumpProportion"); + } else if (this.hpData.containsKey("rewards_list")) { + // 新浮动抽水数据 + ITArray rewards_list = this.hpData.getTArray("rewards_list"); + if (rewards_list.size() > 0) { + _upperLimit = rewards_list.getTObject(0).getInt("UpperLimit"); + _pumpProportion = rewards_list.getTObject(0).getInt("pumpProportion"); + } + } + int hpPump = (int) Math.ceil(player.hpPumpValue() * (_pumpProportion / 100d)); + practicalHpPump = _upperLimit == 0 ? hpPump : hpPump >= _upperLimit ? _upperLimit : hpPump; + } + if (practicalHpPump > 0) { +// int cur_hp = player.hp.cur_hp; +// practicalHpPump = Math.min(practicalHpPump, cur_hp); + + // 这里需要抽一人一半 + player.practicalHpPumpReal = practicalHpPump; + for (Entry entry : this.playerMapById.entrySet()) { + Global.logger.error("palyerId:"+entry.getValue().playerid); + + entry.getValue().practicalHpPump = practicalHpPump / 2; + + } + + } + + String pumpDesc = String.format( + "room id: %s, player id: %d, type: %d, _upperLimit: %d, _pumpProportion: %d practicalHpPump:%d", + this.roomid, player.playerid, type, _upperLimit, _pumpProportion, practicalHpPump); + + Global.logger.error(pumpDesc); + + } catch (Exception e) { + Global.logger.error(e); + } + + return player.practicalHpPump; + } + + /** + * 已玩家排序,从大到小 ,不可负分 : 实际输赢体力值 ,可负分 :总分换算成总体力值 + */ + public List scoreDesc() { + List list = alreadyRoundPlayer(); + list.sort((Player p1, Player p2) -> { + return p2.hpPumpValue() - p1.hpPumpValue(); + }); + return list; + } + + /** + * 存在已玩局数玩家 + */ + private List alreadyRoundPlayer() { + List list = new ArrayList<>(); + playerMapBySeat.values().forEach(player -> { + if (player.already_round > 0) + list.add(player); + }); + return list; + } + + /** + * 房间总分一样玩家 + */ + private List scoreEq(Player play) { + List list = new ArrayList<>(); + int referToHp = play.hpPumpValue(); + alreadyRoundPlayer().forEach(player -> { + if (play != player) { + int hp = player.hpPumpValue(); + if (hp >= 0 && hp == referToHp) { + list.add(player); + } + } + }); + return list; + } + + /** + * 开启倍数后 体力值消耗= 倍数*分数 + */ + public int multipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score * this.hpData.getInt("times")); + } + } + return score; + } + + /** + * 玩家加入房间刷新总服圈子缓存 + */ + public void roomUpdateEvent() { + Redis.use("group1_db0").hincrBy(room_key, "cache_ver", 1); + GroupPublisherService.updateRoomEvt(groupId, this.roomid); + + } + + public boolean isActive() { + return this.isActive; + } + + /** + * 是否开启GPS 检测 0 未开启 大于0 值,具体检测值 + */ + public boolean isOpenGPSCheck() { + boolean isOpen = false; + if (this.config.containsKey("GPSDetection")) { + isOpen = this.config.getInt("GPSDetection") > 0; + } + return isOpen; + } + + /** + * 是否开启IP检测 1 开启 0 未开启 + */ + public boolean isOpenIPCheck() { + boolean isOpen = false; + if (this.config.containsKey("IPDetection")) { + isOpen = this.config.getInt("IPDetection") == 1; + } + return isOpen; + } + + /** + * 检测GPS 距离 true 过近 + * + * @param gps + * @return + */ + public boolean checkGps(String gps) { + int measure = this.config.getInt("GPSDetection"); + for (Player player : this.playerMapById.values()) { + if (GPSUtil.isDistanceNear(gps, player.gps_pos, measure)) { + try { + Global.warn("{} Near location,gps:{},toGps:{}|player:{},Distance:{}m", this.room_key, gps, + player.gps_pos, player.playerid, GPSUtil.getDistance(gps, player.gps_pos)); + } catch (Exception e) { + } + return true; + } + } + return false; + } + + /** + * 检测GPS 距离 true 过近 + * + * @param ip + * @return + */ + public boolean checkIp(String ip) { + for (Player player : this.playerMapById.values()) { + if (player.sender.getAddress().equals(ip)) { + return true; + } + } + return false; + } + + public void redisUpdateXiPaiPlayer(Player player) { + int xipai_score = 0; + if (player.xi_pai) { + xipai_score = this.xi_pai_score; + // player.xi_pai = false; + } + Global.logger.info("xi_pai_score:" + xipai_score); + + if (xipai_score > 0) { +// int hp = xipai_score * 1000; //multipleScore(xipai_score); + int hp = xipai_score; // multipleScore(xipai_score); + + if (player.hp.cur_hp - (long) hp < 0) { + if (player.hp.cur_hp > 0) { + player.hp.cur_hp = Global.eventCtr.redisFag(player, 0, false, false, (int) player.hp.cur_hp, true, + "洗牌"); + player.xi_pai_total += (int) player.hp.cur_hp; + } + } else { + player.hp.cur_hp = Global.eventCtr.redisFag(player, 0, false, false, hp, true, "洗牌"); + player.xi_pai_total += hp; + } + } + } + + protected void redisUpdateHpPlayer(Player player) { + // 更新分数 redis 未入库 + if (player.score.negative_score == true) { + if (player.hp.cur_hp >= 0) { + player.hp.round_actual_hp = -(int) player.hp.cur_hp; + player.hp.round_answer_hp = player.hp.round_actual_hp; + } else { + player.hp.round_actual_hp = 0; + player.hp.round_answer_hp = player.hp.round_actual_hp; + } + } else { + player.hp.round_actual_hp = multipleScore(player.score.round_score) + (int) player.score.d_real_score; + player.hp.round_answer_hp = player.hp.round_actual_hp; + } + int hp = player.hp.round_actual_hp; + int pumpProportion = 0; + int UpperLimit = 0; + int UpperLimitReward = 0; + int type = this.hpData.containsKey("type") ? this.hpData.getInt("type") : 2; + if (type == 1) { + + if (this.hpData.containsKey("rewards_list")) { + + ITArray rewards_list = this.hpData.getTArray("rewards_list"); + if (rewards_list.size() > 0) { + pumpProportion = rewards_list.getTObject(0).getInt("pumpProportion"); + UpperLimit = rewards_list.getTObject(0).getInt("UpperLimit"); + UpperLimitReward = rewards_list.getTObject(0).getInt("UpperLimitReward"); + + } + } + } +// Global.logger.info("player.hp.upper_limit_hp:" + player.room.upper_limit_hp); + if (player.hp.upper_limit) { + player.hp.upper_limit = Math.abs(hp) == Math.abs(player.hp.round_answer_hp); + } + // 如果输家也只能输最高限制分 + if (hp < 0) { +// hp = 0 - (int) player.room.upper_limit_hp; + if (player.room.upper_limit_hp < Math.abs(hp)) { + hp = 0 - (int) player.room.upper_limit_hp; + } + if (player.hp.cur_hp < Math.abs(hp)) { + hp = 0 - player.hp.round_actual_hp; + } + } else if (hp > player.room.upper_limit_hp) { + hp = (int) player.room.upper_limit_hp; + } + + Global.logger.info("upper_limit_hp:" + player.room.upper_limit_hp); + Global.logger.info("hp:" + hp); + Global.logger.info("player.hp.total_hp:" + player.hp.total_hp); + + if (hp == 0) + return; + + player.hp.total_hp += hp; +// player.hp.cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", hp); +// if(hp>0) { +// player.hp.cur_hp = Global.eventCtr.redisFag(player, hp, false, false, 0, false, null); +// }else { +// String gm_key = GroupMemberCache.genKey(this.groupId, player.playerid); +// player.hp.cur_hp = Redis.use("group1_db10").hincrBy(gm_key, "hp", hp); +// +// } + player.hp.cur_hp = Global.eventCtr.redisFag(player, hp, false, false, 0, false, null); + redisCountBlack(player, hp); + // 重新设置房间最低分数 + + } + + public void redisCountBlack(Player player, int hp) { + if (Redis.use("group1_db1").sismember("gods", Integer.toString(player.playerid))) { + return; + } + hp = hp / 100; + String gm_key = GroupMemberCache.genKey(groupId, player.playerid); + String black_key = Redis.use("group1_db10").hget(gm_key, "group_black_key"); + if (StringUtil.isEmpty(black_key)) { + return; + } + String strblack = Redis.use("group1_db10").hget(black_key, "black"); + int black = 0; + if (StringUtil.isNotEmpty(strblack)) { + try { + black = Integer.parseInt(strblack); + } catch (NumberFormatException e) { + black = 0; + } + } + + if (black == 0) { + return; + } else if (black == 1) // hei + { + String str_black_max_value = Redis.use("group1_db10").hget(black_key, "group_black_max_value"); + int black_max_value = 0; + if (StringUtil.isEmpty(str_black_max_value)) { + return; + } + + try { + black_max_value = Integer.parseInt(str_black_max_value); + } catch (NumberFormatException e) { + return; + } + + if (hp > 0) { + Redis.use("group1_db10").hincrBy(black_key, "group_black_now_value", -Math.abs(hp)); + } else { + Redis.use("group1_db10").hincrBy(black_key, "group_black_now_value", Math.abs(hp)); + } + + String str_black_value = Redis.use("group1_db10").hget(black_key, "group_black_now_value"); + if (StringUtil.isEmpty(str_black_value)) { + return; + } + + try { + int black_value = Integer.parseInt(str_black_value); + if (black_value >= black_max_value) { + //Redis.use("group1_db10").hset(black_key, "black", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_rate", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_max_value", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_now_value", "0"); + } + } catch (NumberFormatException e) { + return; + } + } else if (black == 2) { + String str_black_max_value = Redis.use("group1_db10").hget(black_key, "group_black_max_value"); + int black_max_value = 0; + if (StringUtil.isEmpty(str_black_max_value)) { + return; + } + + try { + black_max_value = Integer.parseInt(str_black_max_value); + } catch (NumberFormatException e) { + return; + } + + if (hp > 0) { + Redis.use("group1_db10").hincrBy(black_key, "group_black_now_value", Math.abs(hp)); + } else { + Redis.use("group1_db10").hincrBy(black_key, "group_black_now_value", -Math.abs(hp)); + } + + String str_black_value = Redis.use("group1_db10").hget(black_key, "group_black_now_value"); + if (StringUtil.isEmpty(str_black_value)) { + return; + } + + try { + int black_value = Integer.parseInt(str_black_value); + if (black_value >= black_max_value) { + //Redis.use("group1_db10").hset(black_key, "black", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_rate", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_max_value", "0"); + //Redis.use("group1_db10").hset(black_key, "group_black_now_value", "0"); + } + } catch (NumberFormatException e) { + return; + } + } + } + + protected boolean redisUpdateHp() { + int limitInRoom = this.hpData.containsKey("limitPlay") ? this.hpData.getInt("limitPlay") : 0; + int minOneScore = this.hpData.containsKey("times") ? this.hpData.getInt("times") : 0; + + int count = this.playerMapBySeat.size(); + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + redisUpdateHpPlayer(player); + if (player.check_exit_limit && player.hp.cur_hp < (long) limitInRoom) { + count--; + } else if (player.hp.cur_hp < (long) minOneScore) { + count--; + } + } + boolean total = count < this.playerMapBySeat.size(); + if (total) { + this.endType = Constant.END_TYPE_HP; + } + return total; + } + + protected void CheckModifyHp() { + int times = 1; + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + times = this.hpData.getInt("times"); + } + } + + int limitInRoom = this.hpData.containsKey("limitPlay") ? this.hpData.getInt("limitPlay") : 0; + int count = this.playerMapBySeat.size(); + boolean flag = false; + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + int actual_hp = (player.score.round_score) * times; + if (player.hp.cur_hp + (long) actual_hp < 0) { + flag = true; + break; + } + } + + if (flag == false) { + return; + } + + int lostAllJetton = 0; + int allWinJetton = 0; + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.score.round_score * times < 0) { + if (player.hp.cur_hp + player.score.round_score * times < 0) { + if (player.hp.cur_hp > 0) { + lostAllJetton += Math.abs(player.hp.cur_hp); + } + } else { + lostAllJetton += Math.abs(player.score.round_score * times); + } + } else if (player.score.round_score * times > 0) { + allWinJetton += Math.abs(player.score.round_score * times); + } + } + + if (allWinJetton <= 0) { + return; + } + + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + if (player.score.round_score * times > 0) { + double real_score = (double) lostAllJetton * (double) player.score.round_score * times + / (double) allWinJetton; + player.score.d_real_score = real_score - (double) player.score.round_score * times; + } else if (player.score.round_score * times < 0 + && player.hp.cur_hp + player.score.round_score * times < 0) { + player.score.negative_score = true; + } + } + } + + public void clearHp() { + for (Entry entry : this.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + player.clearHp(); + } + } + + /** + * 是否托管房间 + */ + public boolean isEntrust() { + return this.openEntrust && this.isEntrust; + } + + /** + * 托管是否结算 + */ + public boolean entrustTotal() { + boolean entrustTotal = false; + if (this.isEntrust()) { + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.isEntrust() && player.manualAutoCard == false) { + if (this.entrusResultType == Constant.ENTRUST_CURREN_RESULT) { + entrustTotal = true; + } else if (this.entrusResultType == Constant.ENTRUST_TWO_RESULT) { + if (++player.entrust_round == 2) { + entrustTotal = true; + } + } else if (this.entrusResultType == Constant.ENTRUST_THREE_RESULT) { + if (++player.entrust_round == 3) { + entrustTotal = true; + } + } else if (this.entrusResultType == Constant.ENTRUST_TOTAL_RESULT1) { + if (++player.entrust_round == maxRound) { + entrustTotal = true; + } + } + if (entrustTotal) { + this.endType = Constant.END_TYPE_ENTRUST; + break; + } + } + } + } + return entrustTotal; + } + + public void notifyXiPai() { + ITObject param1 = new TObject(); + ITArray list = TArray.newInstance(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = (Player) entry.getValue(); + if (player.xi_pai) { + list.addInt(player.playerid); + } + } + param1.putTArray("list", list); + broadCastToClient(0, Router.GAME_EVENT_NOTIFY_XIPAI, param1); + } +} diff --git a/game_common/src/main/java/com/game/data/RoomDismiss.java b/game_common/src/main/java/com/game/data/RoomDismiss.java new file mode 100644 index 0000000..639ae66 --- /dev/null +++ b/game_common/src/main/java/com/game/data/RoomDismiss.java @@ -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 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 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(); + } + +} diff --git a/game_common/src/main/java/com/game/data/Score.java b/game_common/src/main/java/com/game/data/Score.java new file mode 100644 index 0000000..228fc2b --- /dev/null +++ b/game_common/src/main/java/com/game/data/Score.java @@ -0,0 +1,52 @@ +package com.game.data; + +import java.util.HashMap; +import java.util.Map; + +/** + * 玩家积分统计 + * + * + * 2017年9月19日 + */ +public class Score { + + public Map 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; + } + +} diff --git a/game_common/src/main/java/com/game/data/Timer.java b/game_common/src/main/java/com/game/data/Timer.java new file mode 100644 index 0000000..c3d4aa5 --- /dev/null +++ b/game_common/src/main/java/com/game/data/Timer.java @@ -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 parameters; + + /** + * + * @param time 单位毫秒 + * @param task + */ + public Timer(int time, ITaskHandler task) { + _lastTime = System.currentTimeMillis(); + _time = time; + _task = task; + this.parameters = new HashMap(); + } + + 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); + } +} diff --git a/game_common/src/main/java/com/game/manager/RoomManager.java b/game_common/src/main/java/com/game/manager/RoomManager.java new file mode 100644 index 0000000..fd32c17 --- /dev/null +++ b/game_common/src/main/java/com/game/manager/RoomManager.java @@ -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 tableMap; + + public RoomManager() { + this.tableMap = new ConcurrentHashMap(); + } + + /** + * 进入房间 + * @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 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(); + } + } + + +} diff --git a/game_common/src/main/java/com/game/manager/SessionManager.java b/game_common/src/main/java/com/game/manager/SessionManager.java new file mode 100644 index 0000000..0f27705 --- /dev/null +++ b/game_common/src/main/java/com/game/manager/SessionManager.java @@ -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 sessionMap = null; + + public SessionManager() { + this.sessionMap = new ConcurrentHashMap(); + } + + /** + * 通过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 getPlayerList(){ + List list = new ArrayList(); + 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); + } + } + }); + } + +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerEndState.java b/game_common/src/main/java/com/game/player/state/PlayerEndState.java new file mode 100644 index 0000000..96039e9 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerEndState.java @@ -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 { + + @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; + } + } +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerInitState.java b/game_common/src/main/java/com/game/player/state/PlayerInitState.java new file mode 100644 index 0000000..319dc05 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerInitState.java @@ -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 { + + @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; + } + } + +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerPauseState.java b/game_common/src/main/java/com/game/player/state/PlayerPauseState.java new file mode 100644 index 0000000..4c43920 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerPauseState.java @@ -0,0 +1,20 @@ +package com.game.player.state; + +import com.game.data.Player; +import com.game.state.StateBase; + + +/** + * 玩家暂停状态 + * + */ +public class PlayerPauseState extends StateBase { + + @SuppressWarnings("unchecked") + @Override + public void toNextState(Player owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerPopupState.java b/game_common/src/main/java/com/game/player/state/PlayerPopupState.java new file mode 100644 index 0000000..c4f0683 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerPopupState.java @@ -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{ + /** + * 进入状态时处理 + * + * @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; + } +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerReadyState.java b/game_common/src/main/java/com/game/player/state/PlayerReadyState.java new file mode 100644 index 0000000..f1f7fae --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerReadyState.java @@ -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 { + + @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); + } + } + +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerReloadState.java b/game_common/src/main/java/com/game/player/state/PlayerReloadState.java new file mode 100644 index 0000000..484bb05 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerReloadState.java @@ -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 { + + 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; + } + } + +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerSpectatorState.java b/game_common/src/main/java/com/game/player/state/PlayerSpectatorState.java new file mode 100644 index 0000000..0e070fe --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerSpectatorState.java @@ -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 { + /** + * 进入状态时处理 + * + * @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; + } + } +} diff --git a/game_common/src/main/java/com/game/player/state/PlayerWaitState.java b/game_common/src/main/java/com/game/player/state/PlayerWaitState.java new file mode 100644 index 0000000..269bac6 --- /dev/null +++ b/game_common/src/main/java/com/game/player/state/PlayerWaitState.java @@ -0,0 +1,11 @@ +package com.game.player.state; +import com.game.data.Player; +import com.game.state.StateBase; + +/** + * 玩家等待状态 + * + */ +public class PlayerWaitState extends StateBase { + +} diff --git a/game_common/src/main/java/com/game/room/state/RoomDestoryGameState.java b/game_common/src/main/java/com/game/room/state/RoomDestoryGameState.java new file mode 100644 index 0000000..b5d4726 --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomDestoryGameState.java @@ -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 { + + @Override + public void enter(Room owner) { + Global.roomMgr.dismissRoom(owner.roomid,true); + + } +} diff --git a/game_common/src/main/java/com/game/room/state/RoomEndState.java b/game_common/src/main/java/com/game/room/state/RoomEndState.java new file mode 100644 index 0000000..e9176f4 --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomEndState.java @@ -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{ + @Override + public void enter(Room owner) { + owner.saveSocre(); + + for (Entry 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 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; + } + } +} diff --git a/game_common/src/main/java/com/game/room/state/RoomInitState.java b/game_common/src/main/java/com/game/room/state/RoomInitState.java new file mode 100644 index 0000000..685cdae --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomInitState.java @@ -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 { + + + @Override + public void execute(Room owner, String cmd, int gid, Object param) { + switch (cmd) { + case ActionEvent.EVENT_READY: + for (Entry 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; + } + + } + +} diff --git a/game_common/src/main/java/com/game/room/state/RoomReloadState.java b/game_common/src/main/java/com/game/room/state/RoomReloadState.java new file mode 100644 index 0000000..400f329 --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomReloadState.java @@ -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{ + + public void execute(Room owner, String cmd, int gid, Object param) { + switch (cmd) { + case ActionEvent.EVENT_READY: + for (Entry 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; + } + } +} diff --git a/game_common/src/main/java/com/game/room/state/RoomStartGameState.java b/game_common/src/main/java/com/game/room/state/RoomStartGameState.java new file mode 100644 index 0000000..093f008 --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomStartGameState.java @@ -0,0 +1,12 @@ +package com.game.room.state; +import com.game.data.Room; +import com.game.state.StateBase; + +/** + * 房间开始游戏 + * + */ +public class RoomStartGameState extends StateBase{ + + +} diff --git a/game_common/src/main/java/com/game/room/state/RoomWaitState.java b/game_common/src/main/java/com/game/room/state/RoomWaitState.java new file mode 100644 index 0000000..b79fa4f --- /dev/null +++ b/game_common/src/main/java/com/game/room/state/RoomWaitState.java @@ -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 { + + @Override + public void execute(Room owner, String cmd, int gid, Object param) { + switch(cmd) { + case ActionEvent.EVENT_START_GAME: + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.clear(); + } + owner.stateMachine.changeState(Global.getState(RoomStartGameState.class)); + break; + } + + } + +} diff --git a/game_common/src/main/java/com/game/state/StateBase.java b/game_common/src/main/java/com/game/state/StateBase.java new file mode 100644 index 0000000..3264ed8 --- /dev/null +++ b/game_common/src/main/java/com/game/state/StateBase.java @@ -0,0 +1,51 @@ +package com.game.state; + +/** + * 状态基类 + * + * @param + */ +public abstract class StateBase { + + /** + * 进入状态时处理 + * @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) { + + } +} diff --git a/game_common/src/main/java/com/game/state/StateMachine.java b/game_common/src/main/java/com/game/state/StateMachine.java new file mode 100644 index 0000000..3e701f6 --- /dev/null +++ b/game_common/src/main/java/com/game/state/StateMachine.java @@ -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); + } + +} diff --git a/game_mj_changsha/.idea/compiler.xml b/game_mj_changsha/.idea/compiler.xml new file mode 100644 index 0000000..2656d33 --- /dev/null +++ b/game_mj_changsha/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_changsha/.idea/encodings.xml b/game_mj_changsha/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_mj_changsha/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_mj_changsha/.idea/jarRepositories.xml b/game_mj_changsha/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_mj_changsha/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_changsha/.idea/misc.xml b/game_mj_changsha/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_mj_changsha/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_mj_changsha/config/game-config.xml b/game_mj_changsha/config/game-config.xml new file mode 100644 index 0000000..c74e03e --- /dev/null +++ b/game_mj_changsha/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.14.1 + 192.168.14.1 + 8842 + 8841 + 10 + true + \ No newline at end of file diff --git a/game_mj_changsha/config/log4j.properties b/game_mj_changsha/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_changsha/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_changsha/config/taurus-core.xml b/game_mj_changsha/config/taurus-core.xml new file mode 100644 index 0000000..1ba569f --- /dev/null +++ b/game_mj_changsha/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_changsha/config/taurus-permanent.xml b/game_mj_changsha/config/taurus-permanent.xml new file mode 100644 index 0000000..172f728 --- /dev/null +++ b/game_mj_changsha/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_changsha/pom.xml b/game_mj_changsha/pom.xml new file mode 100644 index 0000000..8fc1088 --- /dev/null +++ b/game_mj_changsha/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_changsha + 1.0.0 + jar + + robot_mj_changsha + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_changsha/src/main/java/extend/mj/CardNiao.java b/game_mj_changsha/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..133e619 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/CardNiao.java @@ -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; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/Config.java b/game_mj_changsha/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..565538b --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/Config.java @@ -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"; +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXActionEvent.java b/game_mj_changsha/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..7a47b0c --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXActionEvent.java @@ -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"; + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXGameController.java b/game_mj_changsha/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..38ed5fd --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXGameController.java @@ -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 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 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 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 entry : tip.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i map) + { + int count = 0; + for (Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + if (isDaHu(wct.type)) + { + for(int i = 0;i entry : tip.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i 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 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 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); + + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXMainServer.java b/game_mj_changsha/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..1d9105c --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXMainServer.java @@ -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 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(); + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXPlayBack.java b/game_mj_changsha/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..8e4ea16 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXPlayBack.java @@ -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); + } + + + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXPlayer.java b/game_mj_changsha/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..59449bf --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXPlayer.java @@ -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 cardInhand; + + + public List outcardList; + + public ITArray opCard; + + public List 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 winMap; + + public OpenKong openKong; + public Set llsCardRecord; + public int piaoNiao = 0; + + public int win_count; + public boolean fengding; + public List 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(); + + 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; + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXRoom.java b/game_mj_changsha/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..f4dc3b3 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXRoom.java @@ -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 tipMap; + public List actionList; + public List 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 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 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(); + this.actionList = new ArrayList(); + this.actionWinList = new ArrayList(); + this.niao = new ArrayList(); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry 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 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 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 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 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 winPlayerList = new ArrayList(); + for (Entry 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 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 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 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 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 list, int card) { + CardNiao cn = new CardNiao(); + cn.card = card; + list.add(cn); + int tem = card % 100; + for (Entry 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 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 tlist = new ArrayList(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 entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) { + List 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(); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/EXScore.java b/game_mj_changsha/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..48b58fc --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,52 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.game.data.Score; + + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int QS = 2; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + + public List hu_score; + + public EXScore(EXPlayer owner){ + super(owner); + this.hu_score = new ArrayList<>(); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(QS, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + if(this.hu_score!=null) + this.hu_score.clear(); + } + + public HUScore getHuScore(EXPlayer from){ + for(HUScore hu_score : hu_score){ + if(hu_score.player.playerid == from.playerid){ + return hu_score; + } + } + return null; + } + + + public static final class HUScore{ + public int score; + public EXPlayer player; + public int niao_double_num; + public int niao_score; + public Map qs_score_map = new HashMap(); + } + + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/OpCard.java b/game_mj_changsha/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..3767cde --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,15 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; + +public class OpCard { + public int type; + public int card; + + public ITArray opCard; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/OpenKong.java b/game_mj_changsha/src/main/java/extend/mj/OpenKong.java new file mode 100644 index 0000000..ec3a748 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/OpenKong.java @@ -0,0 +1,53 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +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.uitl.CardUtil; + +public class OpenKong { + + public int diceNum1; + public int diceNum2; + + /** + * + */ + public int fromSeat; + + + public int kongSeat; + public List drawList; + + public boolean haidi; + + public int tipActionSeat = -1; + + public OpenKong() { + drawList = new ArrayList(); + + diceNum1 = CardUtil.randomDiceNum(); + diceNum2 = CardUtil.randomDiceNum(); + } + + public ITObject getTObject() { + ITObject data = TObject.newInstance(); + data.putInt("diceNum1", diceNum1); + data.putInt("diceNum2", diceNum2); + + data.putInt("from_seat", fromSeat); + data.putInt("kong_seat", kongSeat); + + ITArray cardList = TArray.newInstance(); + for (int card : drawList) { + cardList.addInt(card); + } + data.putTArray("cardList", cardList); + return data; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_changsha/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..817e56d --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,143 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.RuleChow; +import extend.mj.player.rule.RuleHaidi; +import extend.mj.player.rule.RuleOtherKong; +import extend.mj.player.rule.RuleOtherOpenKong; +import extend.mj.player.rule.RuleOtherWin; +import extend.mj.player.rule.RulePong; +import extend.mj.player.rule.RulePongKong; +import extend.mj.player.rule.RulePongOpenKong; +import extend.mj.player.rule.RuleQSWin; +import extend.mj.player.rule.RuleSelfKong; +import extend.mj.player.rule.RuleSelfOpenKong; +import extend.mj.player.rule.RuleSelfWin; +import extend.mj.player.rule.RuleZTWin; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerHaidiTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerQSWinTipState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.player.state.EXPlayerZTWinTipState; +import extend.mj.tip.IRuleBase; + +/** + * + */ +public class PlayerRuleManager { + + + public static final int DRAW_RULE = 1; + + public static final int OTHER_DISCARD_RULE = 2; + + public static final int KONG_HU_RULE = 3; + + public static final int QS_HU_RULE = 4; + + public static final int OPENKONG_RULE = 5; + + public static final int HAIDI_RULE = 6; + + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public static final int ZT_HU_RULE = 8; + + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.QS_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerQSWinTipState.class)); + tipMap.put(PlayerRuleManager.OPENKONG_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.HAIDI_RULE, (EXPlayerTipState) Global.getState(EXPlayerHaidiTipState.class)); + tipMap.put(PlayerRuleManager.ZT_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerZTWinTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RuleSelfOpenKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RulePongOpenKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleChow()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RuleOtherOpenKong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List qshuList = new ArrayList(); + qshuList.add(new RuleQSWin()); + ruleMap.put(PlayerRuleManager.QS_HU_RULE, qshuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + cpDiscardRuleList.add(new RuleSelfOpenKong()); + cpDiscardRuleList.add(new RulePongKong()); + cpDiscardRuleList.add(new RulePongOpenKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + List openkongList = new ArrayList(); + openkongList.add(new RuleChow()); + openkongList.add(new RulePong()); + openkongList.add(new RuleOtherKong()); + openkongList.add(new RuleOtherOpenKong()); + openkongList.add(new RulePongOpenKong()); + openkongList.add(new RuleOtherWin()); + openkongList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.OPENKONG_RULE, openkongList); + + List haidiList = new ArrayList(); + haidiList.add(new RuleHaidi()); + ruleMap.put(PlayerRuleManager.HAIDI_RULE, haidiList); + + List zthuList = new ArrayList(); + zthuList.add(new RuleZTWin()); + ruleMap.put(PlayerRuleManager.ZT_HU_RULE, zthuList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + player.getRoom().actionWinList.clear(); + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/QSLog.java b/game_mj_changsha/src/main/java/extend/mj/QSLog.java new file mode 100644 index 0000000..a93f5f0 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/QSLog.java @@ -0,0 +1,30 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class QSLog { + public int score; + public int niao_score; + public List niaoList = new ArrayList(2); + + public ITArray winMap; + + public ITObject toMP() { + ITObject p = TObject.newInstance(); + p.putInt("score", score); + p.putInt("niao_score", niao_score); + ITArray niao = new TArray(); + for (int index = 0; index < niaoList.size(); index++) { + niao.addTObject(niaoList.get(index).toMP()); + } + p.putTArray("niao", niao); + p.putTArray("win_list", winMap); + return p; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/RoomCard.java b/game_mj_changsha/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..1f67607 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,382 @@ +package extend.mj; + +import java.util.*; + +import com.game.Global; +import com.game.Util; + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + //this.initCard2(); + } + + private void initCard2() { + List list = Arrays.asList(109, 109, 109, 207, 207, 207, 105, 106, 107, 202, 202, 203, 204); + List list2 = Arrays.asList(209, 209, 209, 206, 206, 203, 203, 208, 208, 208, 202, 202, 202); + List list3 = Arrays.asList(208, 201, 202, 103, 107, 107, 205, 208, 209, 207, 109, 203, 208, 104, 210, 106, 104, 107, 202, 105, 206, 206, 109, 202, 209, 210, 104, 206, 107, 101, 108, 210, 203, 101, 102, 106, 209); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + + private void initCard() { + boolean queyimen = this.room.config.getBoolean(Config.ROOM_CONFIG_QUEYIMEN); + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + if(!queyimen) { + this.cardList.add(300 + index); + } + } + } + +// this.cardList.add(207); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public int pop() { + //Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } +// this.room.roundSettle(); + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; +// this.room.roundSettle(); + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + private boolean IsGoodCard(List dealCards, int drawCard) { + if (Util.cardNum(drawCard, dealCards) >= 2) + { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, dealCards) >= 1 && Util.cardNum(drawCard+2, dealCards) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, dealCards) >= 1 && Util.cardNum(drawCard-2, dealCards) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, dealCards) >= 1 && Util.cardNum(drawCard+1, dealCards) >= 1) + { + return true; + } + } + } + + return false; + } + + // 发牌 + public List deal(EXPlayer owner, int num) { + List dealCards = new ArrayList<>(); + shuffle(); + + for (int index = 0; index < num ; index++) { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(dealCards.size() > 0 && !IsGoodCard(dealCards, drawCard)) { + if (room.card.cardList.size() != 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + dealCards.add(drawCard); + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else { + if (owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:" + owner.playerid + " white player:" + owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } else if (owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:" + owner.playerid + " black player:" + owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } else { + if (room.while_list && !owner.is_white && rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } + } + } + + return dealCards; + } + + public List deal(int deal_index,int num) { + List dealCards = new ArrayList(); + /* + for (int index = 0; index < num; index++) { + dealCards.add(this.pop()); + }*/ + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + + dealCards.add(106); + dealCards.add(106); + dealCards.add(106); + + dealCards.add(107); + dealCards.add(107); + dealCards.add(107); + + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + + dealCards.add(109); + if(num == 14) { + //dealCards.add(101); + } + // deal_tempCards_1 = 101; + } + else if (deal_index == 2) + { + + dealCards.add(102); + dealCards.add(103); + + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + dealCards.add(205); + if(num == 14) { + dealCards.add(101); + } + //deal_tempCards_2 = 205; + } +// if(num == 14) { +// dealCards.add(104); +// } +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// +// +// dealCards.add(104); + return dealCards; + + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/RuleWeight.java b/game_mj_changsha/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..01f9beb --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,55 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 1; + public final static int PONG = 2; + + public final static int KONG = 4; + + public final static int SELF_KONG = 8; + + public final static int WIN = 16; + + public final static int SELF_WIN = 32; + + public final static int GROUP_CHOW = 1; + public final static int GROUO_PONG = 2; + public final static int GROUO_KONG = 3; + public final static int GROUO_OPENKONG = 4; + public final static int GROUO_WIN = 5; + public final static int GROUO_QSWIN = 6; + public final static int GROUO_HAIDI = 7; + public final static int GROUO_ZTWIN = 8; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_PONG_KONG = 5; + public final static int TYPE_WIN = 6; + public final static int TYPE_QSWIN = 7; + public final static int TYPE_ZTWIN = 8; + + + public final static int TYPE_LIULIUSHUN = 21; + + public final static int TYPE_DASIXI = 22; + + public final static int TYPE_QUEYISE = 23; + + public final static int TYPE_BANBANHU = 24; + + public final static int TYPE_JIEJIEGAO = 25; + + public final static int TYPE_SANTONG = 26; + + public final static int TYPE_YIZHIHUA = 27; + + public final static int TYPE_ZT_LIULIUSHUN = 28; + + public final static int TYPE_ZT_DASIXI = 29; + + public final static int TYPE_QTYN = 30; + +} + diff --git a/game_mj_changsha/src/main/java/extend/mj/SettleLog.java b/game_mj_changsha/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/WinCardType.java b/game_mj_changsha/src/main/java/extend/mj/WinCardType.java new file mode 100644 index 0000000..f82bae8 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/WinCardType.java @@ -0,0 +1,87 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class WinCardType { + + public static final int QIXIAODUI = 1; //七小对多少分? + + public static final int JIANGJIANGHU = 2; //将将胡多少分? + + public static final int QINGYISE = 3; //清一色多少分? + + public static final int PENGPENGHU = 4; //碰碰胡多少分? + + public static final int GANGSHANGHUA = 5; //杠上花多少分? + + public static final int GANGSHANGPAO = 6; //杠上炮多少分? + + public static final int QUANQIUREN = 7; //全求人多少分? + + public static final int HAIDI = 8; //海底多少分? + + public static final int HAIDIPAO = 9; //海底炮多少分? + + public static final int QIANG_GANG_HU =10; //抢杠胡? + + public static final int XIAOHU = 11; + + public final static int TYPE_TIANHU = 12; + + public final static int TYPE_TIANTINGHU = 13; + + public final static int TYPE_MENQING = 14; + + public final static int TYPE_LIULIUSHUN = 21; + + public final static int TYPE_DASIXI = 22; + + public final static int TYPE_QUEYISE = 23; + + public final static int TYPE_BANBANHU = 24; + + public final static int TYPE_JIEJIEGAO = 25; + + public final static int TYPE_SANTONG = 26; + + + public final static int TYPE_YIZHIHUA = 27; + + public final static int WIN_TYPE_SCORE = 7; + public final static int WIN_PING_TYPE_SCORE = 3; + + public int type; + + public int value; + + public int score; + + public ITArray opcard; + + public WinCardType(int type, int value,int score) { + this.type = type; + this.value = value; + this.score = score; + } + + public ITObject toTObject() { + return toTObject(false); + } + + public ITObject toTObject(boolean is_opcard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", type); + obj.putInt("value", value); + if(is_opcard&&opcard!=null) { + obj.putTArray("opcard", opcard); + } + return obj; + } + + public String toString() { + return "type:" + type + " value:" + value; + + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleChow.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleChow.java new file mode 100644 index 0000000..c7d1595 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleChow.java @@ -0,0 +1,94 @@ +package extend.mj.player.rule; + +import java.util.List; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRChowState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����״̬ + * + * + * 2017��11��2�� + * PRChowRule.java + */ +public class RuleChow implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (player.lastSeat != room.activeSeat) { + return false; + } + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + if(room.activeKong.kongSeat == player.seat)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + boolean result = false; + List cardInhand = player.cardInhand; + if (Util.checkCard(eventCard - 1, cardInhand) && Util.checkCard(eventCard - 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 1); + opcard.addInt(eventCard - 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard - 1, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard - 1); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard + 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard + 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRChowState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleHaidi.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleHaidi.java new file mode 100644 index 0000000..036ab06 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleHaidi.java @@ -0,0 +1,37 @@ +package extend.mj.player.rule; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���׼�� + * + * + * 2017��11��8�� + * RuleHaidi.java + */ +public class RuleHaidi implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (room.card.getCount() == 1) { + player.tipMgr.clean(); + room.tipMap.clear(); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..5fd5971 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,67 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ +// if(room.activeKong.kongSeat == player.seat)return false; + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + if (Util.checkCard(eventCard, player.cardInhand,3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java new file mode 100644 index 0000000..f0e6c08 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java @@ -0,0 +1,76 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * �����ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + + if (Util.checkCardAndRomve(eventCard, player.cardInhand,3)) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + try { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,eventCard,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + return true; + } + }finally { + Util.addCard(player.cardInhand, eventCard, 3); + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PROtherOpenKongState.class)); + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..109e0a1 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,108 @@ +package extend.mj.player.rule; + +import java.util.HashMap; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.player.rulestate.PRPongOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���Ƽ�� + * + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + boolean zimo = room.config.getBoolean(Config.ROOM_CONFIG_ZIMO); + if(!zimo&&player.louhu)return false; + if(room.activeSeat == player.seat)return false; + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + boolean qiang_kong = activePlayer.stateMachine.curState instanceof PRPongOpenKongState; + OpenKong ok = room.activeKong; + boolean result = false; + ITArray opcard = TArray.newInstance(); + HashMap map = new HashMap(); + if (ok != null) { + for (int card : ok.drawList) { + if (Paixing.checkWin(map, player.opCardList, player.cardInhand, card,!no_jiang, room.difen_score)) { + Paixing.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.WIN_TYPE_SCORE); + map.remove(WinCardType.XIAOHU); + result = true; + opcard.addInt(card); + } + } + } else { + boolean jiang = true; + if(no_jiang&&(qiang_kong ||room.activeHaidi)) { + jiang = false; + } + result = Paixing.checkWin(map, player.opCardList, player.cardInhand, room.activeCard,jiang, room.difen_score); + opcard.addInt(room.activeCard); + } + if (result) { + if (room.activeHaidi) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.HAIDIPAO, new WinCardType(WinCardType.HAIDIPAO, 1,WinCardType.WIN_TYPE_SCORE)); + } + + boolean menqing = room.config.getBoolean("menqing"); + if(menqing) { + boolean m_r = true; + for (OpCard oc : player.opCardList) { + if(oc.type !=RuleWeight.TYPE_SELF_KONG) { + m_r = false; + break; + } + } + if(m_r) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_MENQING, new WinCardType(WinCardType.TYPE_MENQING, 1,WinCardType.WIN_TYPE_SCORE)); + } + } + + if(qiang_kong) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.QIANG_GANG_HU, new WinCardType(WinCardType.QIANG_GANG_HU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + if(player.tianting) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANTINGHU, new WinCardType(WinCardType.TYPE_TIANTINGHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + if(zimo&&map.containsKey(WinCardType.XIAOHU))return false; + + Tip tip = new Tip(opcard.getInt(0),opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.group_type = RuleWeight.GROUO_WIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + } + + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeCard = tip.card; + player.winMap = tip.winMap; + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..1bbdd22 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,70 @@ +package extend.mj.player.rule; + +import java.util.ArrayList; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + if(room.activeKong.kongSeat == player.seat)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + if (Util.cardNum(eventCard, player.cardInhand) >= 2) { + ArrayList opCard = new ArrayList<>(); + opCard.add(eventCard); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.PONG,this, RuleWeight.TYPE_PONG); + tip.group_type = RuleWeight.GROUO_PONG; + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..59fd0ce --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,61 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + for (int card : player.cardInhand) { + result = check(player, card) || result; + } + + return result; + } + + private boolean check(EXPlayer player, int card) { + for (OpCard opc : player.opCardList) { + if (opc.type == RuleWeight.TYPE_PONG && card == opc.card) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_PONG_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + return true; + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongOpenKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongOpenKong.java new file mode 100644 index 0000000..d7d2cf9 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RulePongOpenKong.java @@ -0,0 +1,89 @@ +package extend.mj.player.rule; + +import java.util.ArrayList; +import java.util.List; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ܿ��ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + if(player.tianting)return false; + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.kongSeat != player.seat)return false; + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card,false) || result; + } + }else{ + List cardList = new ArrayList<>(); + cardList.addAll(player.cardInhand); + if(player.autoOutCard) { + int card = player.drawCard; + result = check(player, card,true); + }else { + for (int card : cardList) { + result = check(player, card,true) || result; + } + } + + } + return result; + } + + private boolean check(EXPlayer player, int card,boolean remove) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + for (OpCard opc : player.opCardList) { + if (opc.type == RuleWeight.TYPE_PONG && card == opc.card) { + if(remove)Util.removeCard(player.cardInhand, card, 1); + try { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_PONG_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + return true; + } + }finally { + if(remove)Util.addCard(player.cardInhand, card, 1); + } + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRPongOpenKongState.class)); + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleQSWin.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleQSWin.java new file mode 100644 index 0000000..59cf314 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleQSWin.java @@ -0,0 +1,45 @@ +package extend.mj.player.rule; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ֺ���� + * + */ +public class RuleQSWin implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + List cardList = player.cardInhand; + Map map = new HashMap<>(); + Paixing.qs_check(map, cardList,player.room.config, player.getRoom().difen_score); + boolean result = map.size()>0; + + if (result) { + Tip tip = new Tip(0,new TArray(), 0,this, RuleWeight.TYPE_QSWIN); + tip.group_type = RuleWeight.GROUO_QSWIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + player.getRoom().qsWinCount ++; + } + return result; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..3d63005 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,56 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + + if (player.getRoom().activeHaidi) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + result = true; + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java new file mode 100644 index 0000000..67f9f6f --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java @@ -0,0 +1,77 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ܿ��ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + if (player.getRoom().activeHaidi) { + return false; + } + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean result = false; + if(player.autoOutCard) { + int card = player.drawCard; + if(Util.checkCardAndRomve(card, player.cardInhand,4)) { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + result = true; + } + Util.addCard(player.cardInhand, card, 4); + } + }else { + Map cardMap = Util.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 4) { + Util.removeCard(player.cardInhand, card, 4); + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + result = true; + } + Util.addCard(player.cardInhand, card, 4); + } + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.drawCard = 0; + player.stateMachine.changeState(Global.getState(PRSelfOpenKongState.class)); + + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..53b7827 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,108 @@ +package extend.mj.player.rule; + +import java.util.HashMap; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if(room.activeSeat != player.seat)return false; + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + OpenKong ok = room.activeKong; + boolean result = false; + ITArray opcard = TArray.newInstance(); + HashMap map = new HashMap(); + if (ok != null) { + for (int card : ok.drawList) { + if (Paixing.checkWin(map, player.opCardList, player.cardInhand, card,!no_jiang, room.difen_score)) { + Paixing.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.WIN_TYPE_SCORE); + map.remove(WinCardType.XIAOHU); + result = true; + opcard.addInt(card); + } + } + } else { + player.cardInhand.remove((Integer) player.drawCard); + boolean jiang = true; + if(no_jiang&&room.activeHaidi) { + jiang = false; + } + result = Paixing.checkWin(map, player.opCardList, player.cardInhand, player.drawCard,jiang, room.difen_score); + player.cardInhand.add(player.drawCard); + opcard.addInt(player.drawCard); + } + if (result) { + if (room.activeHaidi) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.HAIDI, new WinCardType(WinCardType.HAIDI, 1,WinCardType.WIN_TYPE_SCORE)); + } + if(player.tianting) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANTINGHU, new WinCardType(WinCardType.TYPE_TIANTINGHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + boolean tianhu = room.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if(tianhu&&room.bankerSeat == player.seat && player.outCardCount ==0) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANHU, new WinCardType(WinCardType.TYPE_TIANHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + boolean menqing = room.config.getBoolean("menqing"); + if(menqing) { + boolean m_r = true; + for (OpCard oc : player.opCardList) { + if(oc.type !=RuleWeight.TYPE_SELF_KONG) { + m_r = false; + break; + } + } + if(m_r) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_MENQING, new WinCardType(WinCardType.TYPE_MENQING, 1,WinCardType.WIN_TYPE_SCORE)); + } + } + + + Tip tip = new Tip(opcard.getInt(0),opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.group_type = RuleWeight.GROUO_WIN; + tip.winMap = map; + tip.self = true; + player.tipMgr.addTip(tip); + } + + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winCard = tip.card; + player.drawCard = tip.card; + player.winMap = tip.winMap; + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleZTWin.java b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleZTWin.java new file mode 100644 index 0000000..ee80373 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rule/RuleZTWin.java @@ -0,0 +1,45 @@ +package extend.mj.player.rule; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ֺ���� + * + */ +public class RuleZTWin implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + List cardList = player.cardInhand; + Map map = new HashMap<>(); + Paixing.zt_check(map, cardList,player.room.config,player.drawCard,player.llsCardRecord, player.getRoom().difen_score); + boolean result = map.size()>0; + + if (result) { + Tip tip = new Tip(0,new TArray(), 0,this, RuleWeight.TYPE_ZTWIN); + tip.group_type = RuleWeight.GROUO_ZTWIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + } + return result; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRChowState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRChowState.java new file mode 100644 index 0000000..3fcfd69 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRChowState.java @@ -0,0 +1,64 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRChowState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + ITArray opcard = owner.opCard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + int card= room.activeCard; + Util.removeCard(owner.cardInhand, chowcard1, 1); + Util.removeCard(owner.cardInhand, chowcard2, 1); + room.activeCard = 0; + + + OpCard opc = new OpCard(RuleWeight.TYPE_CHOW, card); + opc.opCard = new TArray(); + opc.opCard.addInt(chowcard1); + opc.opCard.addInt(chowcard2); + owner.opCardList.add(opc); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_CHOW, fromseat,opc.opCard,false); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..e108491 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,58 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(room.activeCard); + int card = room.activeCard; + OpCard opc = new OpCard(RuleWeight.TYPE_KONG, card); + owner.opCardList.add(opc); + Util.removeCard(owner.cardInhand, card, 4); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard,false); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java new file mode 100644 index 0000000..20fbc50 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java @@ -0,0 +1,64 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; + +/** + * + */ +public class PROtherOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + if(activePlayer!=owner) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + int fromseat = activePlayer.seat; + OpenKong ok = new OpenKong(); + ok.fromSeat = fromseat; + ok.kongSeat = owner.seat; + owner.openKong = ok; + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + + int card = room.activeCard; + OpCard opc = new OpCard(RuleWeight.TYPE_KONG, card); + owner.opCardList.add(opc); + + Util.removeCard(owner.cardInhand, card, 3); + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard,true); + room.activeCard = 0; + room.lastDiscardSeat = 0; + toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().activeKong = owner.openKong; + owner.openKong=null; + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..b8cd9dd --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,47 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.*; + +/** + * + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.win_count ++; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + for (Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + OpCard opc = CardUtil.findOpcard(owner.opCardList, card,RuleWeight.TYPE_PONG); + opc.type = RuleWeight.TYPE_KONG; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard,false); + + room.activeCard = card; + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + room.activeCard = 0; + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java new file mode 100644 index 0000000..10b3ca8 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java @@ -0,0 +1,81 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.tip.TipManager; +import extend.mj.uitl.CardUtil; + +/** + * + */ +public class PRPongOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + ITArray opcard = TArray.newInstance(); + if(room.activeKong==null){ + Util.removeCard(owner.cardInhand, card, 1); + opcard.addInt(card); + }else { + if(owner.outcardList.get(owner.outcardList.size() - 1)!=room.activeCard){ + owner.outcardList.remove(owner.outcardList.size() - 2); + }else{ + owner.outcardList.remove(owner.outcardList.size() - 1); + } + } + + OpCard opc = CardUtil.findOpcard(owner.opCardList, card,RuleWeight.TYPE_PONG); + opc.type = RuleWeight.TYPE_KONG; + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard,true); + if(room.activeKong==null) { + room.activeCard = card; + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + room.activeCard = 0; + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().activeCard = 0; + OpenKong ok = new OpenKong(); + ok.fromSeat = owner.seat; + ok.kongSeat = owner.seat; + owner.getRoom().activeKong = ok; + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..60bf1bf --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,61 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int card = room.activeCard; + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard,false); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..b9c3339 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,39 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard,false); + + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java new file mode 100644 index 0000000..dcb3c70 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java @@ -0,0 +1,48 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; + +/** + * + */ +public class PRSelfOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + OpenKong ok = new OpenKong(); + ok.fromSeat = owner.seat; + ok.kongSeat = owner.seat; + room.activeKong = ok; + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard,true); + + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..67f83bd --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,50 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.*; + +/** + * + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + owner.win_count ++; + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.win_count = 0; + } + for (Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner, 0, 0); + } + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..b8492bb --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,158 @@ +package extend.mj.player.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.*; + +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.tip.TipManager; +import extend.mj.uitl.Paixing; + +/** + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + if (owner.autoOutCard) { + owner.startActionTimer(1000); + } else { + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + // owner.startActionTimer(); + } + + private void _action(EXPlayer owner, int discard, int gid) { + if (owner.autoOutCard && discard != owner.drawCard) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.louhu = false; + owner.drawCard = 0; + EXMainServer.gameCtr.outCard(owner, discard); + boolean ting = owner.room.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if (owner.seat == owner.room.bankerSeat && owner.outCardCount == 0 && ting && Paixing.tingCheck(owner.opCardList, owner.cardInhand)) { + owner.stateMachine.changeState(Global.getState(EXPlayerTianTingTipState.class)); + } else { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + EXRoom room = owner.getRoom(); + if (room.tipMap.size() != 0) { + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if (tipmgr.isWin) + win_count++; + } + room.tongpao = 0; + if (win_count > 1) + room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + owner.outCardCount++; + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + _action(owner, discard, gid); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard = owner.drawCard; + if (owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + _action(owner, discard, gid); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..e9bdd53 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,255 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; + +import extend.mj.*; +import extend.mj.uitl.Paixing; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!owner.skipDraw&&room.card.cardList.size() == 0) { + room.liuju = true; + room.endGame(); + return; + } + draw(owner); + } + + void draw(EXPlayer owner) { + EXRoom room = owner.getRoom(); + boolean zt_win = false; + if(!owner.skipDraw) { + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean jiang = true; + if(no_jiang&&room.activeHaidi) { + jiang = false; + } + + HashMap map = new HashMap(); + boolean result = Paixing.checkWin(map, owner.opCardList, owner.cardInhand, drawCard, jiang, room.difen_score); + if (result) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(!IsGoodCard(owner, drawCard)) { + if (room.card.cardList.size() != 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else { + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + //owner.drawCard = room.card.pop(); + zt_win = EXMainServer.playerRuleMgr.condition(PlayerRuleManager.ZT_HU_RULE, owner,false); + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + } + if(room.activeHaidi) { + room.haidiCard = owner.drawCard; + } + owner.skipDraw = false; + if(!zt_win) { + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean jiang = true; + if(no_jiang&&player.getRoom().activeHaidi) { + jiang = false; + } + + HashMap map = new HashMap(); + boolean result = Paixing.checkWin(map, player.opCardList, player.cardInhand, drawCard, jiang, player.getRoom().difen_score); + if (result) { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..faaacf8 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,38 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java new file mode 100644 index 0000000..8e4b897 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java @@ -0,0 +1,52 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; + +/** + * + */ +public class EXPlayerHaidiTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.haidiTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + owner.tipMgr.clean(); + if (id == 0) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.haidiCount ++; + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + room.niao.clear(); + owner.autoOutCard = true; + room.activeHaidi = true; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..b48e82a --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,48 @@ +package extend.mj.player.state; + +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + +// protected void winOpt(Tip tip) { +// tip.winMap.remove(WinCardType.XIAOHU); +// tip.winMap.put(WinCardType.QIANG_GANG_HU, new WinCardType(WinCardType.QIANG_GANG_HU, 1,6)); +// } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); +// if(id!=0) { +// Tip tip = owner.tipMgr.tipMap.get(id); +// if(tip.weight == RuleWeight.WIN) { +// winOpt(tip); +// } +// } + + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java new file mode 100644 index 0000000..b0c9978 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java @@ -0,0 +1,106 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.mj.*; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.tip.TipManager; + +/** + * + */ +public class EXPlayerOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + owner.louhu = false; + owner.autoOutCard = true; + + EXRoom room = owner.getRoom(); + OpenKong ok = room.activeKong; + if (ok != null) { + ok.drawList.add(room.card.pop()); + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + if (room.config.getInt(Config.ROOM_CONFIG_KAI_GONG) > 0) + { + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + } + if(room.card.getCount() == 0){ + ok.haidi = true; + } + } + + for(Integer card : ok.drawList) { + owner.outcardList.add(card); + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).openKongEvent(owner, leftCount, ok); + + timer(owner.getRoom(), owner, this); + } + + public static void timer(EXRoom room, EXPlayer owner, EXPlayerOpenKongState state) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (room == null) { + Global.logger.error("room is null"); + return; + } + + if (room.isDestroy) + return; + + room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OPENKONG, null); + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OPENKONG_RULE, owner,false); + if (room.tipMap.size() == 0) { + room.activeKong = null; + state.toNextState(owner); + } + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXPlayer owner) { + if(owner.getRoom().activeKong == null) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + }else { + + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + + } + + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d9c6b79 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,47 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.piaoNiaoTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + owner.piaoNiao = id; + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoNiaoCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + EXMainServer.gameCtr.piaoNiaoEvent(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java new file mode 100644 index 0000000..370ec6e --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java @@ -0,0 +1,49 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXGameController; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.tip.Tip; + +/** + * + */ +public class EXPlayerQSWinTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.qsTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + if (id != 0) { + Tip tip = owner.tipMgr.tipMap.get(id); + ((EXGameController)Global.gameCtr).banbanWinEvent(owner,tip); + } + owner.tipMgr.clean(); + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().qsWinCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_QSWIN, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java new file mode 100644 index 0000000..25ed8b9 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java @@ -0,0 +1,68 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; + +/** + * + */ +public class EXPlayerTianTingTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.tingTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + owner.tipMgr.clean(); + if(id!=0) { + owner.tianting = true; + owner.autoOutCard = true; + EXMainServer.gameCtr.tingEvent(owner); + } + if(owner.seat == owner.room.bankerSeat) { + EXRoom room = owner.getRoom(); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DISCARD, room.activeCard); + if (room.tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + }else { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().tianTingCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_TIANTING, gid, null); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + } + + @Override + public void toNextState(EXPlayer owner) { + if(owner.seat == owner.room.bankerSeat) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + }else { + super.toNextState(owner); + } + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..a8da242 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (!owner.isEntrust()) { + _tipEvent(owner); + owner.startActionTimer(); + } else { + owner.startActionTimer(500); + } + } + + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } + + protected void _action(EXPlayer owner, int id, int gid) { + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..716e90c --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,20 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..ff4f2ea --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,47 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * + */ +public class EXPlayerWaitState extends StateBase { + +// @SuppressWarnings("unchecked") +// @Override +// public void toNextState(EXPlayer owner) { +// if(owner.getRoom().activeKong!=null){ +// if(owner.getRoom().activeKong.kongSeat == owner.seat){ +// owner.stateMachine.lastState.toNextState(owner); +// } +// } +// } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + boolean old_louhu = owner.louhu; + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.louhu = false; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + break; + case EXActionEvent.EVENT_OPENKONG: + owner.louhu = false; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OPENKONG_RULE , owner); + break; + default: + break; + } + owner.louhu =old_louhu; + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java new file mode 100644 index 0000000..be03472 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java @@ -0,0 +1,51 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXGameController; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.tip.Tip; + +/** + * 中途胡 + */ +public class EXPlayerZTWinTipState extends EXPlayerTipState { + + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.qsTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + if (id != 0) { + Tip tip = owner.tipMgr.tipMap.get(id); + + ((EXGameController) Global.gameCtr).qsWinEvent(owner, tip); + } + owner.tipMgr.clean(); + owner.skipDraw = true; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + } else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner, 0, gid); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..2896ebd --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,197 @@ +package extend.mj.room.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayBack; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.PlayerRuleManager; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; +import extend.mj.player.state.EXPlayerTianTingTipState; +import extend.mj.uitl.Paixing; + +/** + * + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + ArrayList randPlayer = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + Integer seat = entry.getKey(); + randPlayer.add(seat); + } + + Collections.shuffle(randPlayer); + if (randPlayer.size() > 0) + { + owner.bankerSeat = randPlayer.get(0); + } + } +// owner.round += 1; +// owner.isplaying = true; + + int piao_niao = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO); + boolean piao_niao_auto = owner.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO_AUTO); + if(piao_niao > 0) { + if(piao_niao == 1 || piao_niao == 2 && piao_niao_auto) { + owner.piaoNiaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + else if (piao_niao == 2) + { + owner.piaoNiaoCount = 0; + int opt = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO_OPT); + int piao_fen = 1; + if (opt == 0) + { + piao_fen = 1; + } + else if (opt == 1) + { + piao_fen = 2; + } + else if (opt == 2) + { + piao_fen = 3; + } + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.piaoNiao = piao_fen; + player.tipMgr.clean(); + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + player.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(player); + } + checkXiPai(owner); + } else { + checkXiPai(owner); + } + }else { + checkXiPai(owner); + } + } + + public static void timer(EXRoom owner, EXRoomDealState state) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + state.checkQSWin(owner); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + private void checkXiPai(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner, this); + } + else { + checkQSWin(owner); + } + } + + private void checkQSWin(EXRoom owner) { + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.QS_HU_RULE, (EXPlayer)player); + } + + if(owner.qsWinCount ==0) { + checkTianting(owner); + } + } + + private void checkTianting(EXRoom owner) { + boolean ting = owner.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if(ting) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat != owner.bankerSeat) { + if(Paixing.tingCheck(player.opCardList, player.cardInhand)) { + owner.tianTingCount ++; + player.stateMachine.changeState(Global.getState(EXPlayerTianTingTipState.class)); + } + } + } + if (owner.tianTingCount == 0) { + toNextState(owner); + } + }else { + toNextState(owner); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) { + if(owner.piaoNiaoCount==0) { + checkXiPai(owner); + } + }else if(cmd.equals(EXActionEvent.EVENT_QSWIN)) { + if(owner.qsWinCount ==0) { + checkTianting(owner); + } + }else if(cmd.equals(EXActionEvent.EVENT_TIANTING)) { + if(owner.tianTingCount ==0) { + toNextState(owner); + } + } + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..8054053 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,45 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.PlayerRuleManager; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + if(owner.haidiCount == owner.maxPlayers) { + owner.liuju = true; + owner.endGame(); + return; + } + + Player player; + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HAIDI_RULE, (EXPlayer)player,false)){ + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..5637fca --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,34 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.activeKong = null; + owner.startGame(); + + this.toNextState(owner); + + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/tip/Action.java b/game_mj_changsha/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..7f657ac --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,30 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + * Action.java + */ +public class Action { + + public Tip tip; + public EXPlayer player; + public boolean isRun; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + if(this.isRun)return; + this.isRun = true; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_changsha/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..fac8497 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,23 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * + * + * RuleBase.java + */ +public interface IRuleBase { + + /** + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/tip/Tip.java b/game_mj_changsha/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..f7b92cb --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,44 @@ +package extend.mj.tip; + +import java.util.Map; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.mj.WinCardType; + +/** + * + * + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public int group_type; + + public Map winMap; + public boolean self; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", group_type); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/tip/TipManager.java b/game_mj_changsha/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..993f3c6 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,175 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; + +/** + * + * + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + public boolean isWin = false; + private Tip winTip = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + if(tip.weight == RuleWeight.WIN) { + this.isWin = true; + this.winTip = tip; + } + this.tipMap.put(id, tip); + } + + + + private void checkLouhu() { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + + public void choicAction(int id) { + EXRoom room = this.owner.getRoom(); + if(room.tongpao > 1 && this.isWin) { + Tip tip = this.winTip; + Tip choic_tip = this.tipMap.get(id); + if(choic_tip!=null) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Action action = new Action(choic_tip, owner); + if(tip == choic_tip) { + for (Entry entry : room.tipMap.entrySet()) { + TipManager tem = entry.getValue(); + if (action.tip.weight < tem.getWeightest()) { + room.actionWinList.add(action); + room.actionList.add(action); + return; + } + } + action.run(); + room.actionList.clear(); + room.tongpao = 0; + }else { + room.actionWinList.add(new Action(tip, owner)); + room.addAction(action); + } + return; + }else { + room.actionWinList.add(new Action(tip, owner)); + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.checkAction(); + } + }else { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + } + + public void winAction() { + EXRoom room = this.owner.getRoom(); + if(room.tongpao > 1 && this.isWin) { + Tip tip = this.winTip; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.addAction(new Action(tip, owner)); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); +// mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.winTip = null; + this.isWin = false; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_changsha/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..7c60282 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,52 @@ +package extend.mj.uitl; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.OpCard; +import extend.mj.WinCardType; + +public class CardUtil { + + static public OpCard findOpcard(List opcards, int card,int type) { + for (OpCard oc : opcards) { + if(oc.type == type) { + if (card == oc.card) { + return oc; + } + } + } + return null; + } + + + final static Random random = new Random(); + static { + random.setSeed(System.currentTimeMillis()); + } + static public int randomDiceNum() { + int result = random.nextInt(5); + return result + 1; + } + + static public ITArray toMPData_WinMap(Map map) { + return toMPData_WinMap(map,false); + } + + static public ITArray toMPData_WinMap(Map map,boolean is_opcard) { + if (map != null && map.size() > 0) { + ITArray array = TArray.newInstance(); + for (Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + array.addTObject(wct.toTObject(is_opcard)); + } + return array; + } + return null; + } +} diff --git a/game_mj_changsha/src/main/java/extend/mj/uitl/Paixing.java b/game_mj_changsha/src/main/java/extend/mj/uitl/Paixing.java new file mode 100644 index 0000000..cb3a1c6 --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/uitl/Paixing.java @@ -0,0 +1,438 @@ +package extend.mj.uitl; + +import java.util.*; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; + + + +public class Paixing { + + private final static boolean qs_yijihua_check(Map cardMap,int se,int index) { + Integer num = cardMap.get(se+index); + if(num!=null&&num==1) { + for(int i=1;i<=9;++i) { + if(i !=index) { + if(cardMap.containsKey(se+i)){ + return false; + } + } + } + return true; + } + return false; + } + + public final static void zt_check(Map map,List cardInhand,ITObject config,int card,Set llsCardRecord, int difen) { + if(config.getBoolean(Config.ROOM_CONFIG_ZT_DASIXI)) { + if(Util.cardNum(card,cardInhand) >= 3) { + ITArray opcard4 = new TArray(); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_DASIXI, 1,1); + Util.addCard(opcard4, card, 4); + wct.opcard = opcard4; + + } + } + if(config.getBoolean(Config.ROOM_CONFIG_ZT_LIULIUSHUN)) { + if(!llsCardRecord.contains(card)) { + if(Util.cardNum(card,cardInhand) >= 2) { + Map cardMap =Util.getCardNumMap(cardInhand); + for (Entry entry : cardMap.entrySet()) { + int t_card = entry.getKey(); + int num = entry.getValue(); + if(num>=3&&t_card!=card&&!llsCardRecord.contains(t_card)) { + ITArray opcard3 = new TArray(); + Util.addCard(opcard3, card, 3); + Util.addCard(opcard3, t_card, 3); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_LIULIUSHUN, 1,1); + wct.opcard = opcard3; + break; + } + } + } + + } + } + } + + public final static void qs_check(Map map,List cardInhand,ITObject config, int difen){ + Map cardMap =Util.getCardNumMap(cardInhand); + int card3count=0; + int card4count=0; + boolean banban = true; + ITArray opcard4 = new TArray(); + ITArray opcard3 = new TArray(); + + Set se = new HashSet(); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) { + banban = false; + } + se.add(card/100); + int num = entry.getValue(); + if(num>=4) { + Util.addCard(opcard4, card, 4); + Util.addCard(opcard3, card, 3); + card4count++; + card3count++; + }else if(num>=3) { + Util.addCard(opcard3, card, 3); + card3count++; + } + } + if(card4count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_DASIXI, card4count,1); + wct.opcard = opcard4; + } + if(card3count>=2) { + if(card3count>2 &&card3count %2 !=0){ + opcard3.del(opcard3.size()-1); + opcard3.del(opcard3.size()-1); + opcard3.del(opcard3.size()-1); + } + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_LIULIUSHUN, card3count/2,1); + wct.opcard = opcard3; + } + if(banban) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_BANBANHU, 1,1); + wct.opcard = Util.toTArray(cardInhand); + } + if(!config.getBoolean(Config.ROOM_CONFIG_QUEYIMEN)&&se.size()<3) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_QUEYISE, 1,1); + wct.opcard = Util.toTArray(cardInhand); + + } + if(config.getBoolean(Config.ROOM_CONFIG_QS_YIZHIHUA)) { + int yizhihua_count = 0; + for(int k=100;k<=300;k+=100) { + if(qs_yijihua_check(cardMap,k,5)) { + yizhihua_count ++; + } + } + if(yizhihua_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_YIZHIHUA, yizhihua_count,1); + wct.opcard = Util.toTArray(cardInhand); + }else { + boolean card_5 = false; + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + if(!card_5 && card % 100 == 5&&entry.getValue() == 1) { + card_5 = true; + }else { + if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) { + card_5 = false; + break; + } + } + } + if(card_5) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_YIZHIHUA, 1,1); + wct.opcard = Util.toTArray(cardInhand); + } + } + } + + boolean santong_2= false; + if(config.getBoolean(Config.ROOM_CONFIG_QS_SANTONG)) { + int santong_count = 0; + ITArray st_opcard = new TArray(); + for(int i=1;i<=9;++i) { + if(Util.cardNum(cardMap, 100+i, 2)&&Util.cardNum(cardMap, 200+i, 2)&&Util.cardNum(cardMap, 300+i, 2)) { + santong_count++; + Util.addCard(st_opcard, 100+i, 2); + Util.addCard(st_opcard, 200+i, 2); + Util.addCard(st_opcard, 300+i, 2); + if (i == 2)santong_2=true; + } + } + if(santong_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_SANTONG, santong_count,1); + wct.opcard = st_opcard; + } + } + + if(!santong_2&&config.getBoolean(Config.ROOM_CONFIG_QS_JTYN)) { + if(Util.cardNum(cardMap, 202, 2)&&Util.cardNum(cardMap, 302, 2)) { + ITArray st_opcard = new TArray(); + Util.addCard(st_opcard, 202, 2); + Util.addCard(st_opcard, 302, 2); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_QTYN, 1,1); + wct.opcard = st_opcard; + } + } + + if(config.getBoolean(Config.ROOM_CONFIG_QS_JIEJIEGAO)) { + int jjg_count = 0; + ITArray jjg_opcard = new TArray(); + for(int k=100;k<=300;k+=100) { + for(int i=1;i<=7;++i) { + if(Util.cardNum(cardMap, k+i, 2)&&Util.cardNum(cardMap, k+i+1, 2)&&Util.cardNum(cardMap, k+i+2, 2)) { + jjg_count++; + Util.addCard(jjg_opcard, k+i, 2); + Util.addCard(jjg_opcard, k+i+1, 2); + Util.addCard(jjg_opcard, k+i+2, 2); + i+=2; + } + } + } + if(jjg_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_JIEJIEGAO, jjg_count,1); + wct.opcard = jjg_opcard; + } + } + } + + public static void main(String[] args) { +// List cardInhand = new java.util.ArrayList<>(); +// List opCards = new java.util.ArrayList<>(); +// opCards.add(new OpCard(RuleWeight.TYPE_PONG, 109)); +// opCards.add(new OpCard(RuleWeight.TYPE_PONG, 209)); +// cardInhand.add(106); +// cardInhand.add(106); +// cardInhand.add(107); +// cardInhand.add(108); +//// cardInhand.add(109); +// +// +// System.out.println(tingKongCheck(opCards,cardInhand, 109)); + } + + private final static boolean quanqiuren(List opCards,List cardInhand, int drawCard) { + if (cardInhand.size() > 1) { + return false; + } + if(drawCard == 0)return true; + if (cardInhand.get(0) != drawCard) + return false; + return true; + } + + private final static boolean qingyise(List opCards, List cardInhand, int drawCard) { + int se = cardInhand.get(0) / 100; + if (drawCard!=0&&drawCard / 100 != se) + return false; + for (OpCard card : opCards) { + if (se != card.card / 100) { + return false; + } + } + for (int card : cardInhand) { + if (se != card / 100) { + return false; + } + } + return true; + } + + private final static boolean pongpong(List opCards, List cardInhand, int drawCard,boolean quanqiuren) { + for (OpCard card : opCards) { + if (card.type == RuleWeight.TYPE_CHOW) { + return false; + } + } + if (quanqiuren)return true; + + int card1count=0,card2count=0; + Map cardMap =Util.getCardNumMap(cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 4) return false; + switch(num) { + case 1: + if(card1count>=1)return false; + if(drawCard!=0&&card != drawCard)return false; + card1count++; + break; + case 2: + if(card2count >=2)return false; + card2count ++; + break; + } + } + if(card1count>0&&card2count>0)return false; + if(card1count>0&&drawCard!=0&&!cardMap.containsKey(drawCard))return false; + if(card2count == 2&&drawCard!=0) { + if(!cardMap.containsKey(drawCard))return false; + if(cardMap.get(drawCard)!=2)return false; + } + return true; + } + + private final static boolean jiangjiang(List opCards, List cardInhand, int drawCard) { + if(drawCard!=0){ + if (drawCard % 100 != 2 && drawCard % 100 != 5 && drawCard % 100 != 8) { + return false; + } + } + for (OpCard card : opCards) { + if (card.type == RuleWeight.TYPE_CHOW) { + return false; + } + if (card.card % 100 != 2 && card.card % 100 != 5 && card.card % 100 != 8) { + return false; + } + } + for (int card : cardInhand) { + if (card % 100 != 2 && card % 100 != 5 && card % 100 != 8) { + return false; + } + + } + return true; + } + + private final static int qixiaodui(List opCards, List cardInhand, int drawCard) { + if (cardInhand.size() != 13) { + return -1; + } + List cardlist = cardInhand; + int pair = 0; + int card4count=0; + Map cardMap =Util.getCardNumMap(cardlist); + for (Entry entry : cardMap.entrySet()) { + int num = entry.getValue(); + int card = entry.getKey(); + if (num == 4) { + pair +=2; + card4count ++; + }else if(num >=2) { + if(num==3&&drawCard!=0&&drawCard != card) { + return -1; + } + pair +=1; + }else if(num ==1) { + if(drawCard!=0&&drawCard != card) { + return -1; + } + } + } + if(pair<6) return -1; + if(drawCard ==0)return card4count+1; + if(!cardMap.containsKey(drawCard)) return -1; + if(cardMap.get(drawCard) == 3) { + card4count++; + } + return card4count+1; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score) { + if (map == null) + return null; + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score); + map.put(type, wct); + return wct; + } + } + + public static boolean checkWin(Map map, List opCards, List cardInhand,int drawCard, int difen) { + return checkWin(map,opCards,cardInhand,drawCard,true, difen); + } + + public static boolean checkWin(Map map, List opCards, List cardInhand,int drawCard,boolean jiang, int difen) { + int qixiaodui = qixiaodui(opCards,cardInhand, drawCard); + if (qixiaodui != -1) { + putWinCardType(map, WinCardType.QIXIAODUI, qixiaodui,WinCardType.WIN_TYPE_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.WIN_TYPE_SCORE); + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.WIN_TYPE_SCORE); + } + return true; + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.WIN_TYPE_SCORE); + boolean _qqr =quanqiuren(opCards,cardInhand, drawCard); + if (_qqr) { + putWinCardType(map, WinCardType.QUANQIUREN, 1,WinCardType.WIN_TYPE_SCORE); + } + if (pongpong(opCards,cardInhand, drawCard,_qqr)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.WIN_TYPE_SCORE); + } + return true; + } + if (quanqiuren(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QUANQIUREN, 1,WinCardType.WIN_TYPE_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.WIN_TYPE_SCORE); + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.WIN_TYPE_SCORE); + } + if (pongpong(opCards,cardInhand, drawCard,true)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.WIN_TYPE_SCORE); + } + return true; + } + if (pongpong(opCards,cardInhand, drawCard,false)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.WIN_TYPE_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.WIN_TYPE_SCORE); + } + return true; + } + if (qingyise(opCards,cardInhand, drawCard)) { + WinCard win = new WinCard(cardInhand, drawCard); + win.jiang = false; + if (win.tryWin()) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.WIN_TYPE_SCORE); + return true; + } + } else { + WinCard win = new WinCard(cardInhand, drawCard); + win.jiang = jiang; + if (win.tryWin()) { + putWinCardType(map, WinCardType.XIAOHU, 1, difen); + return true; + } + } + return false; + } + + static public boolean tingCheck(List opCards,List cardInhand) { + if(qixiaodui(opCards,cardInhand, 0)!=-1)return true; + if (quanqiuren(opCards,cardInhand, 0))return true; + if (jiangjiang(opCards,cardInhand, 0))return true; + if (pongpong(opCards,cardInhand, 0,false))return true; + + if (qingyise(opCards,cardInhand, 0)) { + WinCard win = new WinCard(cardInhand, 0); + win.jiang = false; + return win.tryWin(); + } + WinCard win = new WinCard(cardInhand, 0); + return win.tryWin(); + } + + + static public boolean tingKongCheck(List opCards,List cardInhand,int kongCard,boolean jiang) { + if (quanqiuren(opCards,cardInhand, 0))return true; + if (jiangjiang(opCards,cardInhand, kongCard))return true; + if (pongpong(opCards,cardInhand, 0,false))return true; + if (qingyise(opCards,cardInhand, kongCard)) { + WinCard win = new WinCard(cardInhand, 0); + win.jiang = false; + return win.tryWin(); + } + WinCard win = new WinCard(cardInhand, 0); + win.jiang = jiang; + return win.tryWin(); + } + +} diff --git a/game_mj_changsha/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_changsha/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..558fc8d --- /dev/null +++ b/game_mj_changsha/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,275 @@ +package extend.mj.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import com.game.Util; + +import extend.mj.WinCardType; + +public class WinCard { + public int pair_count; + public Stack> stack; + public List cardList; + public boolean jiang = true; + public int zhong_count; + public int zhongid = 0; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + if (card == zhongid) { + this.zhong_count += 1; + } else { + this.cardList.add(card); + } + } + Collections.sort(this.cardList); + } + + private boolean tryShunzi(int card) { + if (card % 100 > 7) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList) && Util.checkCard(card + 2, this.cardList)) { + Util.removeCard(this.cardList, card, 1); + Util.removeCard(this.cardList, card + 1, 1); + Util.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryKezi(int card) { + if (Util.checkCardAndRomve(card, this.cardList, 3)) { +// CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (jiang) { + if (!(card % 100 == 2 || card % 100 == 5 || card % 100 == 8)) { + return false; + } + } + if (Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + return true; + } + return false; + } + + private boolean tryKezi1Zhong(int card) { + if (this.zhong_count >= 1 && Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.zhong_count -= 1; + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryShunzi1Zhong(int card) { + if (card % 100 > 8) { + return false; + } + + if (this.zhong_count < 1) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 1, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(this.zhongid); + this.push(cardGroup); + return true; + } + + if (Util.checkCard(card + 2, this.cardList) && ((card + 1) % 100 != 0)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 2, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryPair1Zhong(int card) { + if (this.pair_count > 0) { + return false; + } + if (jiang) { + if (!(card % 100 == 2 || card % 100 == 5 || card % 100 == 8)) { + return false; + } + } + if (this.zhong_count < 1) { + return false; + } + + Util.removeCard(cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.zhong_count -= 1; + this.pair_count = 1; + return true; + } + + public boolean tryWin() { + if (this.cardList.size() == 0 && this.pair_count == 1) { + return true; + } + + if (this.cardList.size() == 0) { + return false; + } + int activeCard = this.cardList.get(0); + + if (tryPair(activeCard)) { + if (tryWin()) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + + if (tryKezi(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + + } + if (tryShunzi(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + } + + if (tryKezi1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + + } + if (tryShunzi1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + } + if (tryPair1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard == 0) { + this.zhongid = 0; + this.zhong_count = 1; + } else { + this.cardList.add(addCard); + } + + Collections.sort(this.cardList); + } + + public static void main(String[] args) { + + long time = System.currentTimeMillis(); +// for (int i = 0; i < 1000000; ++i) { + ArrayList cardInhand = new ArrayList(); + cardInhand.add(102); + cardInhand.add(102); + cardInhand.add(204); + cardInhand.add(204); + cardInhand.add(206); + cardInhand.add(206); + + cardInhand.add(305); + cardInhand.add(305); + cardInhand.add(305); + cardInhand.add(306); + cardInhand.add(306); + cardInhand.add(307); + + cardInhand.add(307); +// cardInhand.add(301); +// cardInhand.add(301); +// cardInhand.add(108); + +// cardInhand.contains(204); +// Util.checkCard(204, cardInhand); +// CardUtil.checkCardAndRomve(204, cardInhand, 2); + +// if(Util.checkCard(204, cardInhand)) { +// CardUtil.removeCard(cardInhand, 204, 2); +// } +// WinCard win = new WinCard(cardInhand, 0); +// win.tryWin(); +// Paixing.tingKongCheck(new ArrayList<>(), cardInhand, 301); +// } + Map map = new HashMap(); + //Paixing.checkWin(map, new ArrayList<>(), cardInhand, 305, room.difen_score); + + System.out.println(System.currentTimeMillis() - time); + + } + +} diff --git a/game_mj_changsha/src/test/java/robot_mj_changsha/Main.java b/game_mj_changsha/src/test/java/robot_mj_changsha/Main.java new file mode 100644 index 0000000..2f0cb9d --- /dev/null +++ b/game_mj_changsha/src/test/java/robot_mj_changsha/Main.java @@ -0,0 +1,9 @@ +package robot_mj_changsha; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_fulushou/config/game-config.xml b/game_mj_fulushou/config/game-config.xml new file mode 100644 index 0000000..98458c1 --- /dev/null +++ b/game_mj_fulushou/config/game-config.xml @@ -0,0 +1,11 @@ + + + + + 192.168.1.6 + 192.168.1.6 + 8971 + 8971 + 107 + true + \ No newline at end of file diff --git a/game_mj_fulushou/config/log4j.properties b/game_mj_fulushou/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_fulushou/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_fulushou/config/taurus-core.xml b/game_mj_fulushou/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_mj_fulushou/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_fulushou/config/taurus-permanent.xml b/game_mj_fulushou/config/taurus-permanent.xml new file mode 100644 index 0000000..856ea37 --- /dev/null +++ b/game_mj_fulushou/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_fulushou/pom.xml b/game_mj_fulushou/pom.xml new file mode 100644 index 0000000..c05bcde --- /dev/null +++ b/game_mj_fulushou/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_fulushou + 1.0.0 + jar + + game_mj_fulushou + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_fulushou + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_fulushou/src/main/java/extend/mj/CardNiao.java b/game_mj_fulushou/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..12b4af9 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/CardNiao.java @@ -0,0 +1,22 @@ +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 seat = 0; + public int score = 0; + + + public ITObject toMP(){ + ITObject obj = TObject.newInstance(); + obj.putInt("card", card); + obj.putInt("score", score); + obj.putInt("playerId", playerId); + obj.putInt("seat", seat); + return obj; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/Config.java b/game_mj_fulushou/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..5fd9248 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/Config.java @@ -0,0 +1,199 @@ +package extend.mj; + +public class Config { + public static final int XIPAI_SCORE = 10; + public static final String ROOM_CONFIG_CHUIPAI = "chipai"; //吃牌 + public static final String ROOM_CONFIG_DIANPAO = "dianpao"; //接炮胡 + public static final String ROOM_CONFIG_HUNYISE = "hunyise"; //混一色 + public static final String ROOM_CONFIG_QINGYISE = "qingyise"; //清一色 + public static final String ROOM_CONFIG_PENGPENGHU = "pengpenghu"; //碰碰胡 + public static final String ROOM_CONFIG_QIDUI = "qidui"; //七小对 + public static final String ROOM_CONFIG_HAOHUA_QIDUI = "haohua_qidui"; //豪华七小对 + public static final String ROOM_CONFIG_HAOHUA2_QIDUI = "haohua2_qidui"; //双豪华七小对 + public static final String ROOM_CONFIG_HAOHUA3_QIDUI = "haohua3_qidui"; //三豪华七小对 + public static final String ROOM_CONFIG_GANGSHANGKAIHUA_2bei = "gangshangkaihua"; //杠上开花2倍 + public static final String ROOM_CONFIG_GANGSHANGPAO_2bei = "gangshangpao_2bei"; //杠上炮2倍 + public static final String ROOM_CONFIG_SHISHANGYAO = "shishanyao"; //十三幺 + public static final String ROOM_CONFIG_TIANDIHU = "tiandihu"; //天地胡 + public static final String ROOM_CONFIG_SHIBALUOHAN = "shibaluohan"; //十八罗汉 + public static final String ROOM_CONFIG_XIAOSHANYUAN = "xiaoshanyuan"; //小三元 + public static final String ROOM_CONFIG_XIAOSIXI = "xiaosixi"; //小四喜 + public static final String ROOM_CONFIG_DASHANYUAN = "dashanyuan"; //大三元 + public static final String ROOM_CONFIG_DASIXI = "dasixi"; //大四喜 + public static final String ROOM_CONFIG_LOUHU = "louhu"; //漏胡 + public static final String ROOM_CONFIG_GUO_PENG = "guopeng"; //过碰不碰 + public static final String ROOM_CONFIG_GUO_GONG = "guogang"; //过杠不杠 + public static final String ROOM_CONFIG_YAO_JIU = "yao_jiu"; //混幺九 + public static final String ROOM_CONFIG_QING_YAO_JIU = "qing_yao_jiu"; //清幺九 + public static final String ROOM_CONFIG_LAIZI4_HU = "laizi4_hu"; //四鬼胡牌 + public static final String ROOM_CONFIG_LAIZI4_HU_2BEI = "laizi4_hu_2bei"; //四鬼胡牌两倍 + public static final String ROOM_CONFIG_QUAN_FENG = "quan_feng"; //全风 + public static final String ROOM_CONFIG_12ZHANG_LUODI_QUANBAO = "twelve_zhang_luodi_quanbao";//12张落地全包 + public static final String ROOM_CONFIG_QUAN_FENG_SCORE = "quan_qiu_ren"; //全求人 + public static final String ROOM_CONFIG_han19 = "han19"; //含19即可 + public static final String ROOM_CONFIG_ZIYISE = "ziyise"; //字一色 + public static final String ROOM_CONFIG_HAI_DI_NAO_YUE = "haidinaoyue"; //海底捞月 + + 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_PIAO = "piao"; // 0:不嫖 1:热票 2:冷票 3:固定票分 + public static final String ROOM_CONFIG_PIAO_FEN = "piao_fen"; // 固定票分时, 票分 + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian"; + public static final String ROOM_CONFIG_QIDUI_JIA_FAN = "qidui_jiafan"; //七对2倍 + public static final String ROOM_CONFIG_QIDUI_4BEI = "qidui_4bei"; //七对4倍 + public static final String ROOM_CONFIG_NIAO = "niao"; //0无马 1有马 2爆炸马 3抓马 + public static final String ROOM_CONFIG_NIAO_OPT = "niao_opt"; //爆炸马 0 加分 1 加倍 + public static final String ROOM_CONFIG_MAI_NIAO = "mai_niao"; //0无马 1有马 + public static final String ROOM_CONFIG_MAI_NIAO_OPT = "mai_niao_opt"; //1买一码 2买二马 3罚一码 4罚二马 + public static final String ROOM_CONFIG_WU_FENG = "wu_feng"; + public static final String ROOM_CONFIG_LAIZI = "laizi"; ////0 无鬼 1白板做鬼 2翻鬼(随机一个牌做鬼) 3翻双鬼 4红中做鬼 + + public static final String ROOM_CONFIG_QIANGKONG = "qiangkong"; //可抢杠胡 + public static final String ROOM_CONFIG_QIANGKONG_2BEI = "qiangkong_2bei"; //可抢杠胡2倍 + public static final String ROOM_CONFIG_QIANGKONG_MING = "qiangkong_ming"; //明杠可抢 + public static final String ROOM_CONFIG_QIANGKONG_NIAO = "qiangkong_niao"; + public static final String ROOM_CONFIG_NONEALL = "none_is_all"; + public static final String ROOM_CONFIG_NIAO_SCORE = "niao_score"; + public static final String ROOM_CONFIG_QG_TYPE = "qianggang_type"; //抢杠全包 + public static final String ROOM_CONFIG_GANGBAO_TYPE = "gangbao_type"; //杠爆全包 + public static final String ROOM_CONFIG_JIANGMA = "jiangma"; + public static final String ROOM_CONFIG_HZ_HU = "hz_hu"; + public static final String ROOM_CONFIG_GENGZHUAN = "geng_zhuan"; + public static final String ROOM_CONFIG_JIEJIEGAO = "jiejiegao"; + public static final String ROOM_CONFIG_JIEJIEGAO_FIRST_NO = "jiejiegao_first"; + public static final String ROOM_CONFIG_LIAN_ZHUANG = "lian_zhuang"; + public static final String ROOM_CONFIG_WUGUI_JIABEI = "wuguijiabei"; + public static final String ROOM_CONFIG_NO_WAN = "no_wan"; + public static final String ROOM_CONFIG_MA_GEN_DI_FEN = "ma_gen_di_fen";//马跟底分 + public static final String ROOM_CONFIG_MA_GEN_GONG = "ma_gen_gong";//马跟杠 + public static final String ROOM_CONFIG_LIU_GOU_MA = "liu_gou_ma";//留够马牌 + public static final String ROOM_CONFIG_HUANGZHUANGHUANGGANG = "huangzhuang_huanggang";//荒庄荒杠 + public static final String ROOM_CONFIG_LIUJU_2BEI = "liuju_2bei";//流局翻倍 + public static final String ROOM_CONFIG_DAHU_CHENG = "da_hu_cheng";//大胡相乘 + public static final String ROOM_CONFIG_JIHU_NOTCHIHU = "jihunotchihu"; //鸡胡不能吃胡 + public static final String ROOM_CONFIG_XIAOHU_BEI = "xiaohu_bei"; //小胡的倍数另算 + public static final String ROOM_CONFIG_SPECAIL_ZIMO = "special_zimo"; //潮州特殊自摸 + public static final String ROOM_CONFIG_MUST_HU = "must_hu"; //必胡,必须胡牌,不能过 + public static final String ROOM_CONFIG_10_BEI_BUJIFEN = "10bei_bu_jifen"; //十倍不计分 + public static final String ROOM_CONFIG_10_BEI_FENGDING = "10bei_fengding"; //封顶十倍 + public static final String ROOM_CONFIG_ZI_DONG_HU = "zi_dong_hu"; //自动胡 + public static final String ROOM_CONFIG_USE_BASE_HU_SCORE = "use_base_hu_score"; //使用默认基础胡分 + public static final String ROOM_CONFIG_MENG_QING = "men qing"; //门清 + public static final String ROOM_CONFIG_JIHU_SHI_PINGHU = "ji hu shi ping hu"; //没有鸡胡,统一叫平胡 + + public static final String ROOM_CONFIG_XUAN_ZHUANG = "xuan_zhuang"; // 0:轮庄 1:胡牌庄 + public static final String ROOM_CONFIG_QING_ZUI_HU = "qing_zui_hu"; // 0:亲嘴0胡 1:亲嘴2胡 + public static final String ROOM_CONFIG_GANG_ZHAO_LIU_XI = "gang_zhao_liu_xi"; //杠招6息 bool + public static final String ROOM_CONFIG_SPECIAL_PENG_PENG_HU = "special_peng_peng_hu"; //碰碰胡每个字不少于2个 + public static final String ROOM_CONFIG_FEN_DIEJIA = "fen_diejia"; //算分叠加 + + + + public static final String SETTLE_DIAN_PAO = "dian_pao"; + public static final String SETTLE_JIE_PAO = "jie_pao"; + public static final String SETTLE_ZIMO = "zimo"; + public static final String SETTLE_AN_KONG = "an_kong"; + public static final String SETTLE_MING_KONG = "ming_kong"; + + public static final int MING_GANG_SCORE = 3; + public static final int BU_GANG_SCORE = 1; + public static final int AN_GANG_SCORE = 2; + + + public static final int NIAO_TYPE_WU =0; + public static final int NIAO_TYPE_159 =1; + public static final int NIAO_TYPE_ALL =2; //爆炸马 + public static final int NIAO_TYPE_ZHUAMA =3; + + /** + * + */ + 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_MAI_NIAO = "20822"; + + /** + * + */ + public static final String GAME_EVT_PIAONIAO_TIP = "833"; + + /** + * + */ + public static final String GAME_PIAO = "1015"; + + /** + * 飘鸟提示 + */ + public static final String GAME_EVT_PIAO_TIP = "2031"; + public static final String GAME_EVT_PIAO = "2032"; + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXActionEvent.java b/game_mj_fulushou/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..18229b3 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXActionEvent.java @@ -0,0 +1,19 @@ +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_OTHER_PAO = "other_pao"; + public static final String EVENT_PIAO= "1015"; +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXGameController.java b/game_mj_fulushou/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..7ccda6c --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXGameController.java @@ -0,0 +1,573 @@ +package extend.mj; + +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; +import extend.mj.uitl.WinCard; + +import java.util.*; +import java.util.Map.Entry; + +/** + * + * + * + * EXGameController.java + */ +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.weight+" 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); + } + + @ActionKey(Config.GAME_PIAO) + public void RouterPiao(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PIAO, 0, params); + } + + public void changeActiveSeat(EXRoom owner,int activeSeat) { + owner.activeSeat = activeSeat; + TObject 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.cardInhand.add(player.drawCard); + param.putTArray("card_list", Util.toTArray(player.cardInhand)); + param.putTArray("outcard_list", Util.toTArray(player.outcardList)); + long start_time = System.currentTimeMillis(); + param.putTArray("ting_list", getTingList(player)); + long use_time = System.currentTimeMillis() - start_time; + Global.logger.info("---------------getTingList use time:" + use_time); + player.sendEvent(Config.GAME_EVT_DRAW, param); + 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; + if (room.isGengZhuang) + { + if (room.bankerSeat == player.seat && player.opCardList.size() == 0 && player.outcardList.size() == 0) + { + if (room.gent_zhuan_nextSeat == 0 && room.first_zhuang_card == 0) + { + room.first_zhuang_card = discard; + room.geng_zhuan_num = 1; + room.gent_zhuan_nextSeat = player.nextSeat; + } + else + { + room.isGengZhuang = false; + } + } + else if (room.gent_zhuan_nextSeat == player.seat && player.opCardList.size() == 0 && player.outcardList.size() == 0 && room.first_zhuang_card == discard) + { + room.geng_zhuan_num += 1; + room.gent_zhuan_nextSeat = player.nextSeat; + if (room.geng_zhuan_num >= room.maxPlayers) + { + if (room.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + EXPlayer bankerPlayer = (EXPlayer)room.playerMapBySeat.get(room.bankerSeat); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer) entry.getValue(); + if (otherPlayer.playerid != bankerPlayer.playerid) + { + room.addScore(otherPlayer,bankerPlayer, 1, EXScore.GENG_ZHUAN); + } + } + } + room.isGengZhuang = false; + } + } + else + { + room.isGengZhuang = false; + } + } + + player.outcardList.add(discard); + Util.removeCard(player.cardInhand, discard, 1); + if(Global.loggerDebug) { + Global.logger.info(player + " outcard["+discard+"]"); + } + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){ + EXRoom room = player.getRoom(); + 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); + } + ITArray result = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer __player = (EXPlayer) entry.getValue(); + ITObject __info = new TObject(); + __info.putInt("playerid", __player.playerid); + __info.putTArray("outcard_list", Util.toTArray(__player.outcardList)); + result.addTObject(__info); + } + paramBroadCast.putTArray("outcard_list", result); + + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type)); + } + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, paramBroadCast); + + if (type == RuleWeight.TYPE_CHOW || type == RuleWeight.TYPE_PONG) + { + paramBroadCast.putTArray("ting_list", getTingList(player)); + } + + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + + ((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.cardInhand = owner.card.deal(); + Collections.sort(player.cardInhand); + if(Global.loggerDebug) { + Global.logger.info(player + " cardlist:" + player.cardInhand); + } + if (owner.config.getInt(Config.ROOM_CONFIG_MAI_NIAO) == 1) + { + int maiNiaoOpt = owner.config.getInt(Config.ROOM_CONFIG_MAI_NIAO_OPT); + //买一马 + if (maiNiaoOpt == 1) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + //买二马 + else if (maiNiaoOpt == 2) + { + for(int i = 0; i < 2; i++) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + //罚一马 + else if (maiNiaoOpt == 3) + { + if (player.seat == owner.bankerSeat) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + //罚二马 + else if (maiNiaoOpt == 4) + { + if (player.seat == owner.bankerSeat) + { + for(int i = 0; i < 2; i++) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + } + } + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + param.putInt("laiziCard", owner.card.laiziCard); + param.putInt("laiziCard2", owner.card.laiziCard2); + param.putInt("laiziCardBefore", owner.card.laiziCardBefore); + param.putInt("laiziCard2Before", owner.card.laiziCard2Before); + 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(); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + public void winEvent(EXPlayer owner,int from_seat,int win_card) { + 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("win_card", win_card); + param.putInt("from_seat", from_seat); + ITArray array = CardUtil.toMPData_WinMap(owner.winMap); + if (array != null) { + param.putTArray("win_list", array); + } + if(Global.loggerDebug) { + Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]"); + } + 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); + } + + public void sendMaiNiaoEvt(EXPlayer owner, int seat) { + EXRoom room = owner.getRoom(); + ITObject param = new TObject(); + ITArray array = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (int index = 0; index < player.mai_niao.size(); index++) { + array.addTObject(player.mai_niao.get(index).toMP()); + } + } + + param.putTArray("mai_niao", array); + param.putInt("start_seat", seat); + + room.broadCastToClient(0, Config.GAME_EVT_MAI_NIAO, param); + ((EXPlayBack)room.playBackData).addMaiNiaoCommand(owner.seat, param); + } + + /** + * Ʊ����ʾ + * @param owner + */ + public void piaoNiaoTipEvent(EXPlayer owner) { + owner.sendEvent(Config.GAME_EVT_PIAONIAO_TIP, null); + } + + private ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putInt("xipai_score", owner.xi_pai_score); + 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); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + ITArray infoList = new TArray(); + for (Entry 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.putInt("piao", player.piao); + param.putBoolean("is_win", player.winer == 1); + param.putInt("hu_score", player.score.round_log.get(EXScore.WIN)); + param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO)); + param.putInt("gang_score", player.score.round_log.get(EXScore.KONG)); + param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO)); + param.putInt("geng_zhuan", player.score.round_log.get(EXScore.GENG_ZHUAN)); + param.putInt("ma_geng_gong", player.score.round_log.get(EXScore.MA_GENG_GONG)); + if ((owner.config.getBoolean(Config.ROOM_CONFIG_JIEJIEGAO) || owner.config.getBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG)) && player.repeat_win > 0) + { + param.putInt("repeat_win", player.repeat_win); + } + else + { + param.putInt("repeat_win", 0); + } + + param.putInt("mai_niao_score", player.score.round_log.get(EXScore.MAI_NIAO)); + player.hp_info(param); + 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); + } + ITArray mai_niao = new TArray(); + for (int index = 0; index < player.mai_niao.size(); index++) { + mai_niao.addTObject(player.mai_niao.get(index).toMP()); + } + param.putTArray("mai_niao", mai_niao); + param.putInt("ming_gang_num", player.ming_gang_num); + param.putInt("an_gang_num", player.an_gang_num); + param.putInt("dian_gang_num", player.dian_gang_num); + ITArray opCardList = TArray.newInstance(); + + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("card", opCard.card); + if(opCard.opCard!=null) { + obj.putTArray("opcard", opCard.opCard); + } + opCardList.addTObject(obj); + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + 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); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.playBackData.addResult(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } + + /** + * 票鸟提示 + * @param owner + */ + public void piaoTipEvent(EXPlayer owner,int reload) { + ITObject response = new TObject(); + response.putInt("piao", owner.room.config.getInt(Config.ROOM_CONFIG_PIAO)); + response.putInt("last_piao", owner.last_piao); + response.putInt("last_winer", owner.last_winer); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_EVT_PIAO_TIP, response); + } + + /** + * 票鸟事件 + * @param owner + */ + public void piaoEvent(EXPlayer owner) { + if(owner.piao==-1)return; + + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("piao", owner.piao); + owner.room.broadCastToClient(0, Config.GAME_EVT_PIAO, param); + } + + public boolean isTingPai(EXPlayer player, int drawCard, List delPai, List opCards) + { + EXRoom room = player.getRoom(); + + List tempList = new ArrayList(); + for (int index = 1; index <= 8; index++) { + tempList.add(100*index + 1); + tempList.add(100*index + 2); + tempList.add(100*index + 3); + } + HashMap map = new HashMap(); + List tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + if (drawCard > 0) + { + Util.removeCard(tempCardList, drawCard, 1); + } + if (delPai != null) + { + for(int i = 0; i < delPai.size(); i++) + { + Util.removeCard(tempCardList, delPai.get(i), 1); + } + } + + for(int j = 0; j < tempList.size(); j++) + { + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + map.clear(); + WinCard win = new WinCard(tempCardList, tempList.get(j), room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true, true); + if (win.checkWinOpList(map, player, opCards, room, true)) { + return true; + } + } + + return false; + } + + public ITArray getTingList(EXPlayer player) + { + EXRoom room = player.getRoom(); + + Map cardMap = new HashMap<>(); + List tempList = new ArrayList(); + for (int index = 1; index <= 8; index++) { + tempList.add(100*index + 1); + tempList.add(100*index + 2); + tempList.add(100*index + 3); + } + HashMap map = new HashMap(); + + for(int i = 0; i < player.cardInhand.size(); i++) + { + int tempCard = player.cardInhand.get(i); + if (player.getRoom().isLaizi(tempCard)) + { + continue; + } + + List tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + Util.removeCard(tempCardList, tempCard, 1); + + for(int j = 0; j < tempList.size(); j++) + { + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + map.clear(); + WinCard win = new WinCard(tempCardList, tempList.get(j), room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true, true); + if (win.checkWin(map, player, room, true)) { + if (!cardMap.containsKey(tempCard)) + { + ITArray cardMapList = new TArray(); + cardMapList.addInt(tempList.get(j)); + cardMap.put(tempCard, cardMapList); + } + else + { + ITArray cardMapList = cardMap.get(tempCard); + cardMapList.addInt(tempList.get(j)); + } + } + } + } + + ITArray array = TArray.newInstance(); + for (Map.Entry entry : cardMap.entrySet()) { + ITObject obj = TObject.newInstance(); + obj.putInt("card", entry.getKey()); + obj.putTArray("value", entry.getValue()); + Global.logger.info("del card:"+entry.getKey()+" hu card:"+ entry.getValue().toJson()); + array.addTObject(obj); + } + + return array; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXMainServer.java b/game_mj_fulushou/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..f3a586a --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXMainServer.java @@ -0,0 +1,99 @@ +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.*; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDiscardState; +import extend.mj.player.state.EXPlayerDrawState; +import extend.mj.player.state.EXPlayerKongDrawState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.player.state.EXPlayerWaitState; +import extend.mj.room.state.EXRoomDealState; +import extend.mj.room.state.EXRoomPiaoState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.room.state.EXRoomStartGameState; + +/** + * + * + * EXMainServer.java + */ +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(EXRoomPiaoState.class, new EXRoomPiaoState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerKongDrawState.class, new EXPlayerKongDrawState()); + + 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(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + Global.registerState(PROtherKongState.class, new PROtherKongState()); + Global.registerState(PROtherWinState.class, new PROtherWinState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChowState.class, new PRChowState()); + Global.registerState(PRSelfKongState.class, new PRSelfKongState()); + Global.registerState(PRSelfWinState.class, new PRSelfWinState()); + Global.registerState(PROtherGongSelfWinState.class, new PROtherGongSelfWinState()); + + + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXPlayBack.java b/game_mj_fulushou/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..4349aa8 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXPlayBack.java @@ -0,0 +1,71 @@ +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", p.piao); + 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){ + 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); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + + public void addMaiNiaoCommand(int seat,ITObject param){ + addCommand("Mai_Niao",seat,param); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXPlayer.java b/game_mj_fulushou/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..0a0bc05 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXPlayer.java @@ -0,0 +1,199 @@ +package extend.mj; + +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; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + * + * + * 2017��8��30�� + * EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + + // ������ + public List outcardList; + + public ITArray opCard; + + public List pongGroup; + public List kongGroup; + public List selfKongGroup; + public List opCardList; + + public int drawCard = 0; + public int winCard = 0; + + public TipManager tipMgr; + + public SettleLog settleLog; + + /** + * ©�� + */ + public boolean louhu = false; + + /** + * ǿ�Ƽ����� + */ + public boolean forceCheckWin = false; + /** + * 0 С�� 1 ���ܺ� + */ + public int winType = 0; + + /** + * 0 无 1 胡 2 输 + */ + public int last_winer = 0; + + public List notPongKongList = new ArrayList<>(); + public List notPongList = new ArrayList<>(); + + public int niaoCount; + + public int repeat_win; + + public Map winMap; + + public int niao_score; + + public int hu_score; + + public int di_score; + + public ArrayList mai_niao; + + public int ming_gang_num = 0; + public int an_gang_num = 0; + public int dian_gang_num = 0; + + public boolean tinghu10bei = false; + + public boolean gangshangpao = false; + + public int piao = -1; + public int last_piao = -1; + + public boolean is_gang = false; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + + pongGroup = new ArrayList<>(); + kongGroup = new ArrayList<>(); + selfKongGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + + opCard = new TArray(); + + tipMgr = new TipManager(this); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_DIAN_PAO, 0); + settleLog.put(Config.SETTLE_JIE_PAO, 0); + settleLog.put(Config.SETTLE_ZIMO, 0); + settleLog.put(Config.SETTLE_AN_KONG, 0); + settleLog.put(Config.SETTLE_MING_KONG, 0); + + repeat_win = -1; + niao_score = 2; + hu_score = 0; + di_score = 0; + + ming_gang_num = 0; + an_gang_num = 0; + dian_gang_num = 0; + + last_winer = 0; + + tinghu10bei = false; + gangshangpao = false; + is_gang = false; + + this.mai_niao = 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.putInt("piao", this.piao); + playerData.putInt("last_piao", this.last_piao); + 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.notPongKongList.clear(); + this.notPongList.clear(); + this.winer = 0; + this.louhu = false; + this.outcardList.clear(); + this.drawCard = 0; + this.kongGroup.clear(); + this.pongGroup.clear(); + this.selfKongGroup.clear(); + this.opCardList.clear(); + this.score.resetRound(); + this.niaoCount = 0; + this.winMap = null; + this.niao_score = 2; + this.hu_score = 0; + this.di_score = 0; + this.mai_niao.clear(); + this.ming_gang_num = 0; + this.an_gang_num = 0; + this.dian_gang_num = 0; + this.tinghu10bei = false; + this.piao = -1; + this.is_gang = false; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXRoom.java b/game_mj_fulushou/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..a0e7eec --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,780 @@ +package extend.mj; + +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.player.state.EXPlayerDisCardTipState; +import extend.mj.tip.Action; +import extend.mj.tip.TipManager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winCount = 0; + public boolean liuju = false; + public boolean last_liuju = false; + + public ArrayList niao; + + public int piaoNiaoCount; + public int adminSeat = 0; + public int lastWinPlayerId = 0; + public boolean isGengZhuang = false; + public int first_zhuang_card = 0; + public int geng_zhuan_num = 0; + public int gent_zhuan_nextSeat = 0; + /* + * 上一次庄家座位号 + */ + public int lastBankerSeat = 0; + public int piaoCount = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.niao = new ArrayList(); + + if (!this.config.containsKey(Config.ROOM_CONFIG_DIANPAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HUNYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HUNYISE, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QINGYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QINGYISE, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_PENGPENGHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_PENGPENGHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHISHANGYAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHISHANGYAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_TIANDIHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_TIANDIHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHIBALUOHAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_LOUHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LOUHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_PENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GUO_PENG, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_GONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GUO_GONG, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false); + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO, true); + + //可抢杠胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG, false); + } + + //可抢杠胡2倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_2BEI, false); + } + + //明杠可抢 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_MING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_MING, false); + } + + //抢杠全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_QG_TYPE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QG_TYPE, false); + } + + //杠爆全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGBAO_TYPE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGBAO_TYPE, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU, false); + + if (!this.config.containsKey(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GENGZHUAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LIAN_ZHUANG)) { + this.config.putBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_JIABEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NO_WAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_NO_WAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_4BEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_GONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_GONG, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WU_FENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WU_FENG, false); + } + + ////幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_YAO_JIU, false); + } + + //清幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_QING_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QING_YAO_JIU, false); + } + + //有没有癞子 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI)) + { + this.config.putInt(Config.ROOM_CONFIG_LAIZI, 0); + } + + //四鬼胡牌 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false); + } + + //四鬼胡牌两倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU_2BEI, false); + } + + //全风 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG, false); + } + + ////12张落地全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO, false); + } + + ////留够马牌 + if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false); + } + + //全求人 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE, false); + } + + // ROOM_CONFIG_han19 = "han19"; //含19即可 + if (!this.config.containsKey(Config.ROOM_CONFIG_han19)) + { + this.config.putBoolean(Config.ROOM_CONFIG_han19, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZIYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZIYISE, false); + } + + + //大胡相乘 + if (!this.config.containsKey(Config.ROOM_CONFIG_DAHU_CHENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DAHU_CHENG, false); + } + + //鸡胡不能吃胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_NOTCHIHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU, false); + } + + //小胡的倍数另算 + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOHU_BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOHU_BEI, false); + } + + //流局两倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_LIUJU_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIUJU_2BEI, false); + } + + //荒庄荒杠 + if (!this.config.containsKey(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG, false); + } + + //潮州特殊自摸 + if (!this.config.containsKey(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO, false); + } + + //必胡,必须胡牌,不能过 + if (!this.config.containsKey(Config.ROOM_CONFIG_MUST_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MUST_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false); + } + + //买马,提前预定马,猜谁胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO, 0); + } + + //买马值 + if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO_OPT)) + { + this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO_OPT, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_DI_FEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_DI_FEN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT, 0); + } + + //10倍不计分 + if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_BUJIFEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_BUJIFEN, false); + } + + //封顶十倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_FENGDING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_FENGDING, false); + } + + //自动胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_ZI_DONG_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZI_DONG_HU, false); + } + + //海底捞月 + //自动胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE, false); + } + + ////使用默认基础胡分 + if (!this.config.containsKey(Config.ROOM_CONFIG_USE_BASE_HU_SCORE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE, false); + } + + //门清 + if (!this.config.containsKey(Config.ROOM_CONFIG_MENG_QING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, false); + } + + //没有鸡胡,统一叫平胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU, false); + } + + //杠上炮2倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_CHUIPAI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_CHUIPAI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_PIAO, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_FEN)) + { + this.config.putInt(Config.ROOM_CONFIG_PIAO_FEN, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_XUAN_ZHUANG)) + { + this.config.putInt(Config.ROOM_CONFIG_XUAN_ZHUANG, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QING_ZUI_HU)) + { + this.config.putInt(Config.ROOM_CONFIG_QING_ZUI_HU, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QING_ZUI_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_SPECIAL_PENG_PENG_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SPECIAL_PENG_PENG_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_FEN_DIEJIA)) + { + this.config.putInt(Config.ROOM_CONFIG_FEN_DIEJIA, 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); + } + + this.isEntrust=true; + this.adminSeat = 0; + this.lastWinPlayerId =0; + + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + + this.lastBankerSeat = 0; + this.last_liuju = false; + + //初始化房间的特殊参数 + WinCardType.InitRoomSpecialConfig(this); + } + + public boolean isLiuJu() + { + if (card.cardList.size() == 0) + { + return true; + } + + return false; + } + + public void endGameByLiuJu() + { + if (config.getBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG)) + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + int score = player.score.round_log.get(EXScore.KONG); + player.score.round_score -= score; + player.score.total_score -= score; + player.score.round_log.put(EXScore.KONG, 0); + } + } + liuju = true; + clear_repeatwin(); + + endGame(); + } + + public void endGame() + { + last_liuju = liuju; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer != 1) + { + player.last_winer = 0; + player.repeat_win = -1; + } + else + { + player.last_winer = 1; + } + } + super.endGame(); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + + checkAction(); + } + + public boolean isLaizi(int card) { + return this.card.isLaizi(card); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + + } + + /** + * 获取房间信息 + * + * @return + */ + public ITObject getRoomInfo() { + ITObject data = super.getRoomInfo(); + if (data != null) + { + data.putInt("laiziCard", this.card.laiziCard); + data.putInt("laiziCard2", this.card.laiziCard2); + data.putInt("laiziCardBefore", this.card.laiziCardBefore); + data.putInt("laiziCard2Before", this.card.laiziCard2Before); + } + + return data; + } + + 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); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN); + if(type == EXScore.WIN) { + if (zhuangxian) { + if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) { + score += 1; + } + } + } + + if (type == EXScore.WIN || type == EXScore.NIAO) + { + if (fromPlayer.tinghu10bei) + { + 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 addMaGengGongScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.MA_GENG_GONG); + } + + public void addAllMaGengGongScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addMaGengGongScore(destPlayer, fromPlayer, score); + } + } + + public int GetGongScore(EXPlayer destPlayer) + { + return destPlayer.score.round_log.get(EXScore.KONG); + } + + public void addAllScore(EXPlayer destPlayer, int socre, int type) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + this.addScore(destPlayer, fromPlayer, socre, type); + } + } + + public void addMaiNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.MAI_NIAO); + } + + public void addAllMaiNiaoScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addMaiNiaoScore(destPlayer, fromPlayer, score); + } + } + + public void addNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO); + } + + public void addAllNiaoScore(EXPlayer destPlayer, int score) { + for (Entry 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); //0:热票 1:冷票 2:不嫖 3:固定票分 + if(piao_niao == 0)return; + this.addScore(destPlayer, fromPlayer,destPlayer.piao + fromPlayer.piao, EXScore.PIAO_NIAO); + } + + public void addAllPiaoNiaoScore(EXPlayer destPlayer) { + int piao_niao = this.config.getInt(Config.ROOM_CONFIG_PIAO); //0:不嫖 1:冷票 2: 3:固定票分 + if(piao_niao == 0)return; + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addPiaoNiaoScore(destPlayer,fromPlayer); + } + } + + public void handle_repeatwin(EXPlayer owner) + { + if (owner.last_winer == 1) + { + owner.repeat_win += 1; + } + else + { + owner.repeat_win += 1; + } + } + + public void clear_repeatwin() + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.repeat_win = -1; + player.last_winer = 0; + } + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void clear() { + super.clear(); + + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.winCount = this.piaoNiaoCount = 0; + this.niao.clear(); + + this.isGengZhuang = false; + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + this.lastBankerSeat = 0; + } + + public void winCallback(EXPlayer owner, int card) { + this.endGame(); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/EXScore.java b/game_mj_fulushou/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..91596ad --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,29 @@ +package extend.mj; + +import com.game.data.Score; + + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int KONG = 2; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + public static final int GENG_ZHUAN = 5; + public static final int MA_GENG_GONG = 6; + public static final int MAI_NIAO = 7; + + public EXScore(EXPlayer owner){ + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(KONG, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + this.round_log.put(GENG_ZHUAN, 0); + this.round_log.put(MA_GENG_GONG, 0); + this.round_log.put(MAI_NIAO, 0); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/OpCard.java b/game_mj_fulushou/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..0ecca5e --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,22 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; + +public class OpCard { + public int type; + public int card; + public int card_seat; + public ITArray opCard; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + this.card_seat = 0; + } + + public OpCard(int type, int card, int card_seat) { + this.type = type; + this.card = card; + this.card_seat = card_seat; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_fulushou/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..edb6259 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,108 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.*; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.tip.IRuleBase; + +/** + * ����������� + * + * + * + * 2017��9��19�� PlayerRuleManager.java + */ +public class PlayerRuleManager { + + /** + * ����ץ�� + */ + public static final int DRAW_RULE = 1; + + /** + * ���˳��� + */ + public static final int OTHER_DISCARD_RULE = 2; + /** + * ���ܺ����� + */ + public static final int KONG_HU_RULE = 3; + /** + * �������Ժ���ƹ��� + */ + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public static final int KONG_DRAW_RULE = 8; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.KONG_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerKongWinState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerDrawTipState) Global.getState(EXPlayerDrawTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + //drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List kongDrawRuleList = new ArrayList(); + kongDrawRuleList.add(new RuleSelfKong()); + //kongDrawRuleList.add(new RulePongKong()); + kongDrawRuleList.add(new RuleOtherKongSelfWin()); + ruleMap.put(PlayerRuleManager.KONG_DRAW_RULE, kongDrawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChow()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + //cpDiscardRuleList.add(new RulePongKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/RoomCard.java b/game_mj_fulushou/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..6135fc1 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,138 @@ +package extend.mj; + +import com.game.Global; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + public Integer laiziCard; + public Integer laiziCard2; + public Integer laiziCardBefore; + public Integer laiziCard2Before; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + subCardList = new ArrayList<>(); + this.room = table; + laiziCard = 0; + laiziCard2 = 0; + laiziCardBefore = 0; + laiziCard2Before = 0; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 8; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100*index + 1); + this.cardList.add(100*index + 2); + this.cardList.add(100*index + 3); + } + this.cardList.add(100*index + 4); + } + } + + private void initCard2() { + List list = Arrays.asList(101, 101, 101, 202, 204, 302, 302, 304, 402, 403, 502, 502, 504, 801, 701, 701, 701); + List list2 = Arrays.asList(101, 101, 101, 802, 202, 204, 302, 302, 304, 402, 403, 502, 502, 504, 801, 701, 701, 701); + List list3 = Arrays.asList(701,202, 202, 203, 301,302, 303, 303, 304, 501, 502, 501, 502, 601, 602, 802); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public boolean isLaizi(int card) + { + return false; + } + + public void reInitCards(List cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } + +// public int pop() { +// +// if (this.cardList.size() == 0) { +// this.room.bankerSeat = this.room.activeSeat; +//// this.room.roundSettle(); +// } +// +// int card = this.cardList.remove(0); +// +// return card; +// +// } + + public int pop() { + Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < 18; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/RuleWeight.java b/game_mj_fulushou/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..a8e33f7 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,22 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 0b00001; + public final static int PONG = 0b00010; + public final static int ZHAO = 0b00100; + public final static int SELFZHAO = 0b00100; + public final static int KONG = 0b01000; + public final static int SELFKONG = 0b01000; + public final static int WIN = 0b10000; + public final static int SELF_WIN = 0b100000; + + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_ZHAO = 5; + public final static int TYPE_SELF_ZHAO = 6; + public final static int TYPE_WIN = 7; +} + diff --git a/game_mj_fulushou/src/main/java/extend/mj/SettleLog.java b/game_mj_fulushou/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/TagAnalyseItem.java b/game_mj_fulushou/src/main/java/extend/mj/TagAnalyseItem.java new file mode 100644 index 0000000..e61f46a --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/TagAnalyseItem.java @@ -0,0 +1,22 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; + +import java.util.ArrayList; +import java.util.List; + +public class TagAnalyseItem { + //分析子项 + public int cbCardEye; //牌眼麻将 + public int huxi; + public List cbCardEyeList; //牌眼麻将 + public List cbOpCard; //组合类型 + + public TagAnalyseItem() + { + this.huxi = 0; + this.cbCardEye = 0; + this.cbOpCard = new ArrayList(); + this.cbCardEyeList = new ArrayList(); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/TagKindItem.java b/game_mj_fulushou/src/main/java/extend/mj/TagKindItem.java new file mode 100644 index 0000000..fe18c06 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/TagKindItem.java @@ -0,0 +1,17 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagKindItem { + public int type; //组合类型 + public int card; //中心麻将 + public Integer[] cbCardList; //麻将索引 + + public TagKindItem() + { + type = 0; + card = 0; + cbCardList = new Integer[3]; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/WinCardType.java b/game_mj_fulushou/src/main/java/extend/mj/WinCardType.java new file mode 100644 index 0000000..29f18c8 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/WinCardType.java @@ -0,0 +1,173 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class WinCardType { + public static final int JIHU = 1; //鸡胡类型 + + public static final int PINGHU = 2; //平胡类型 + + public static final int QIXIAODUI = 3; //七小对 + + public static final int HAOHUA_QIXIAODUI = 4; //豪华七小对 + + public static final int HAOHUA2_QIXIAODUI = 5; //双豪华七小对 + + public static final int HAOHUA3_QIXIAODUI = 6; //三豪华七小对 + + public static final int QINGYISE = 7; //清一色 + + public static final int PENGPENGHU = 8; //碰碰胡 + + public static final int GANGSHANGHUA = 9; //杠上开花 + + public static final int GANGSHANGPAO = 10; //杠上炮 + + public static final int QIANG_GANG_HU = 11; //抢杠胡 + + public static final int HUN_YI_SE = 12; //混一色 + + public static final int SHI_SHAN_YAO = 13; //十三幺 + + public static final int TIAN_HU = 14; //天胡 十倍 + + public static final int DI_HU = 15; //地胡 十倍 + + public static final int REN_HU = 16; //人胡 十倍 + + public static final int SHI_BA_LUO_HAN = 17; //十八罗汉 + + public static final int XIAO_SHAN_YUAN = 18; //小三元 + + public static final int DA_SHAN_YUAN = 19; //大三元 + + public static final int XIAO_SI_XI = 20; //小四喜 + + public static final int DA_SI_XI = 21; //大四喜 + + public static final int YAO_JIU = 22; //幺九 + + public static final int LAIZI4_HU = 23; //四鬼胡牌 + + public static final int QUAN_FENG = 24;//全风 + + public static final int QUAN_QIU_REN = 25;//全求人 + + public static final int QING_YAO_JIU = 26; //清幺九 + + public static final int ZI_YI_SE = 27; //字一色 + + public static final int WU_GUI_JIABEI = 28; //无鬼两倍 + public static final int LIU_JU_2BEI = 29; //流局两倍 + public static final int HAI_DI_NAO_YUE = 30; //海底捞月 + public static final int MEN_QING = 31; //门清 捉炮门清 + public static final int XIAO_HU_ZHONG_DA_HU = 32; //选小胡有大胡的情况下,不显示具体的胡牌类型,只显示大胡几分 + public static final int MAN_TIAN_HU = 33; //满天胡 + public static final int ZIMO_MEN_QING = 34; //自摸门清 + public static final int GUN_GUN = 35; //滚滚 +//////////////////////////////////////////////////////////// + public static int BASE_HU_SCORE = 2; //基础分数 + public static int DA_HU_BEI_SCORE = 1; //大胡倍数 + public static int JIHU_SCORE = 1; //鸡胡类型 + public static int PINGHU_SCORE = 1; //平胡类型 + public static int MENGQING_SCORE = 3; //门清类型 + public static int QIXIAODUI_SOCRE = 1; //七小对 倍数 + public static int HAOHUA_QIXIAODUI_SCORE = 1; //豪华七小对 + public static int HAOHUA2_QIXIAODUI_SCORE = 1; //双豪华七小对 + public static int HAOHUA3_QIXIAODUI_SCORE = 1; //三豪华七小对 + public static int QINGYISE_SCORE = 1; //清一色 + public static int GANGSHANGHUA_SCORE = 3; //杠上开花 + public static int PENGPENGHU_SCORE = 3; //碰碰胡 + public static int GANGSHANGPAO_SOCRE = 3; //杠上炮 + public static int QIANG_GANG_HU_SOCRE = 1; //抢杠胡 + public static int HUN_YI_SE_SCORE = 1; //混一色 + public static int SHI_SHAN_YAO_SCORE = 1; //十三幺 + public static int TIAN_DI_HU_SCORE = 1; //天地胡 十倍 + public static int TIAN_HU_SCORE = 1; //天胡 20倍 + public static int DI_HU_SCORE = 1; //地胡 10倍 + public static int SHI_BA_LUO_HAN_SCORE = 1; //十八罗汉 + public static int DA_SHAN_YUAN_SCORE = 1; //大三元 + public static int XIAO_SHAN_YUAN_SCORE = 1; //小三元 + public static int XIAO_SI_XI_SCORE = 1; //小四喜 + public static int DA_SI_XI_SCORE = 1; //大四喜 + public static int YAO_JIU_SCORE = 1; //幺九 + public static int LAIZI4_HU_SCORE = 1; //四鬼胡牌 + public static int QUAN_FENG_SCORE = 1;//全风 + public static int QUAN_QIU_REN_SCORE = 1;//全求人 + public static int QING_YAO_JIU_SCORE = 1; //清幺九 + public static int ZI_YI_SE_SCORE = 1; //字一色 + public static int WU_GUI_JIABEI_SCORE = 1; //无鬼两倍 + public static int LIU_JU_2BEI_SCORE = 1; //流局两倍 + public static int HAI_DI_NAO_YUE_SCORE = 3; //海底捞月 + public static int MAN_TIAN_HU_SCORE = 1;//满天胡 + public static int ZIMO_MEN_QING_SCORE = 3; //自摸门清 + public static int GUN_GUN_SCORE = 5; //滚滚 + + public int type; + + public int value; + + public int score; + + public boolean is_dahu; + + public String desc; + + public ITArray opcard; + + //初始化房间的特殊参数 + static public void InitRoomSpecialConfig(EXRoom room) + { + //潮汕鬼牌特殊配置 + //this.config.putInt(Config.ROOM_CONFIG_LAIZI, 0); //没有癞子 + + room.config.putBoolean(Config.ROOM_CONFIG_PENGPENGHU, true); + room.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, true); + room.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, true); + room.config.putBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE, true); + room.config.putBoolean(Config.ROOM_CONFIG_CHUIPAI, true); + //荒庄荒杠 + if (!room.config.containsKey(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG)) + { + room.config.putBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG, true); + } + room.config.putBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE, true); + room.config.putBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU, true); + room.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, true); + + } + + public WinCardType(int type, int value, int score, boolean is_dahu, String desc) { + this.type = type; + this.value = value; + this.score = score; + this.is_dahu = is_dahu; + this.desc = desc; + } + + public boolean IsDaHu() + { + return is_dahu; + } + + public ITObject toTObject() { + return toTObject(false); + } + + public ITObject toTObject(boolean is_opcard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", type); + obj.putInt("value", value); + obj.putInt("score", score); + if(is_opcard&&opcard!=null) { + obj.putTArray("opcard", opcard); + } + return obj; + } + + public String toString() { + return "type:" + type + " value:" + value + " score:" + score + " desc:" + desc; + } +} \ No newline at end of file diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleChow.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleChow.java new file mode 100644 index 0000000..1feb523 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleChow.java @@ -0,0 +1,128 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRChowState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.List; + +/** + * ����״̬ + * + * + * 2017��11��2�� + * PRChowRule.java + */ +public class RuleChow implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (player.isEntrust() || !room.config.getBoolean(Config.ROOM_CONFIG_CHUIPAI)) { + return false; + } + + if (player.lastSeat != room.activeSeat) { + return false; + } + + if (player.is_gang) + { + return false; + } + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if (activePlayer.gangshangpao) + { + return false; + } + + int eventCard = room.activeCard; + boolean result = check(player,eventCard); + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + if (eventCard % 100 == 4) + { + return false; + } + + boolean result = false; + List cardInhand = player.cardInhand; + if (Util.checkCard(eventCard - 1, cardInhand) && Util.checkCard(eventCard - 2, cardInhand) && (eventCard-1) % 100 != 4 && (eventCard-2) % 100 != 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 1); + opcard.addInt(eventCard - 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + if (Util.checkCard(eventCard - 1, cardInhand) && (eventCard-1) % 100 != 4 && Util.checkCard(eventCard / 100 * 100 + 4, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 1); + opcard.addInt(eventCard / 100 * 100 + 4); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + if (Util.checkCard(eventCard - 2, cardInhand) && (eventCard-2) % 100 != 4 && Util.checkCard(eventCard / 100 * 100 + 4, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 2); + opcard.addInt(eventCard / 100 * 100 + 4); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard - 1, cardInhand) && (eventCard + 1) % 100 != 4 && (eventCard - 1) % 100 != 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard - 1); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + if (Util.checkCard(eventCard + 1, cardInhand) && (eventCard + 1) % 100 != 4 && Util.checkCard(eventCard / 100 * 100 + 4, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard / 100 * 100 + 4); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard + 2, cardInhand) && (eventCard + 1) % 100 != 4 && (eventCard + 2) % 100 != 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard + 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + if (Util.checkCard(eventCard + 2, cardInhand) && (eventCard + 2) % 100 != 4 && Util.checkCard(eventCard / 100 * 100 + 4, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 2); + opcard.addInt(eventCard / 100 * 100 + 4); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + player.tipMgr.addTip(tip); + result = result || true; + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRChowState.class)); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..3520ceb --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,158 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + if (player.is_gang) + { + return false; + } + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if (activePlayer.gangshangpao) + { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 3)) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(eventCard)) + { + return false; + } + } + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + player.is_gang = false; + + List delPai = new ArrayList<>(); + delPai.add(eventCard); + delPai.add(eventCard); + delPai.add(eventCard); + List opCards = new ArrayList<>(); + opCards.addAll(player.opCardList); + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, eventCard); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard); + opCards.add(pongCard); + if (((EXGameController) Global.gameCtr).isTingPai(player, 0, delPai, opCards)) + { + Tip tip = new Tip(eventCard,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + Tip tip2 = new Tip(eventCard,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_ZHAO); + player.tipMgr.addTip(tip2); + } + else { + Tip tip = new Tip(eventCard,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_ZHAO); + player.tipMgr.addTip(tip); + } + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(eventCard); + } + return true; + } + else if (Util.checkCard(eventCard, player.cardInhand, 2) && Util.checkCard(eventCard /100 * 100 + 4, player.cardInhand, 1)) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(eventCard)) + { + return false; + } + } + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard /100 * 100 + 4); + player.is_gang = false; + List delPai = new ArrayList<>(); + delPai.add(eventCard); + delPai.add(eventCard); + delPai.add(eventCard /100 * 100 + 4); + List opCards = new ArrayList<>(); + opCards.addAll(player.opCardList); + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, eventCard); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard); + pongCard.opCard.addInt(eventCard /100 * 100 + 4); + opCards.add(pongCard); + if (((EXGameController) Global.gameCtr).isTingPai(player, 0, delPai, opCards)) + { + Tip tip = new Tip(eventCard,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + Tip tip2 = new Tip(eventCard,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_ZHAO); + player.tipMgr.addTip(tip2); + } + else { + Tip tip = new Tip(eventCard, opcard, RuleWeight.ZHAO, this, RuleWeight.TYPE_ZHAO); + player.tipMgr.addTip(tip); + } + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(eventCard); + } + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + Util.removeCard(player.notPongKongList, tip.card, 4); + } + if (tip.type == RuleWeight.TYPE_KONG) + { + player.is_gang = true; + if (tip.card > 0) + { + for (Map.Entry entry : player.getRoom().playerMapById.entrySet()) { + EXPlayer pp = (EXPlayer) entry.getValue(); + pp.notPongList.add(tip.card/100*100+1); + pp.notPongList.add(tip.card/100*100+2); + pp.notPongList.add(tip.card/100*100+3); + pp.notPongList.add(tip.card/100*100+4); + } + } + } + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java new file mode 100644 index 0000000..c7cf4d7 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java @@ -0,0 +1,100 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherGongSelfWinState; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleOtherKongSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + int laizi = config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + if (player.is_gang) + { + if (room.config.getBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei)) + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.GANGSHANGHUA_SCORE*2, true, "杠上开花"); + } + else + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.GANGSHANGHUA_SCORE, true, "杠上开花"); + } + } + + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, true)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + player.tipMgr.addTip(tip); + + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.is_gang = false; + player.winType = 1; + player.winCard = tip.card; + player.drawCard = tip.card; + + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + player.niao_score = WinCardType.BASE_HU_SCORE; + player.hu_score = WinCardType.BASE_HU_SCORE; + player.di_score = WinCardType.BASE_HU_SCORE; + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + room.handle_repeatwin(player); + boolean isDaHu = false; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + isDaHu = true; + } + } + + if (isDaHu) + { + player.hu_score = 3; + } + + if (player.is_gang) + { + player.stateMachine.changeState(Global.getState(PROtherGongSelfWinState.class)); + } + else { + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + } + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..7d84f7b --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,107 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.HashMap; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + if (!config.getBoolean(Config.ROOM_CONFIG_DIANPAO)) { + if (!config.getBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + return false; + } + } + + if (player.lastSeat != room.activeSeat) { + return false; + } + + if(room.activeSeat == player.seat)return false; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + + if (player.cardInhand.size() == 1 && room.isLaizi(player.cardInhand.get(0))) + { + return false; + } + + if (room.activeCard % 100 == 4) + { + return false; + } + + int activieCard = room.activeCard; + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + if (activePlayer.gangshangpao) + { + if ( room.config.getBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.GANGSHANGPAO_SOCRE*2, true, "杠上炮"); + } + else { + WinCard.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.GANGSHANGPAO_SOCRE, true, "杠上炮"); + } + } + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false, false); + if (win.checkWin(map, player, room, false)) { + if (map.containsKey(WinCardType.MEN_QING) || map.containsKey(WinCardType.PENGPENGHU) || map.containsKey(WinCardType.GANGSHANGPAO)) + { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + tip.winMap = map; + player.tipMgr.addTip(tip); + + return true; + } + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + player.getRoom().activeCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + player.niao_score = WinCardType.BASE_HU_SCORE; + + player.hu_score = 1; + player.di_score = 1; + + if (tip.winMap.containsKey(WinCardType.PENGPENGHU)) + { + player.hu_score = WinCardType.PENGPENGHU_SCORE; + } + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + room.handle_repeatwin(player); + + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..b77d885 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,97 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + if (player.notPongList.contains(eventCard)) + { + return false; + } + } + + if (eventCard % 100 == 4) + { + return false; + } + + if (player.is_gang) + { + return false; + } + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if (activePlayer.gangshangpao) + { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + player.notPongList.add(eventCard); + } + return true; + } + else if (Util.checkCard(eventCard, player.cardInhand, 1) && Util.checkCard(eventCard /100 * 100 + 4, player.cardInhand, 1)) + { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard /100 * 100 + 4); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + player.notPongList.add(eventCard); + } + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + Util.removeCard(player.notPongList, tip.card, 4); + } + + player.stateMachine.changeState(Global.getState(PRPongState.class)); + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..41cb634 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,165 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if (player.isEntrust()) { + return false; + } + + if (player.is_gang) + { + return false; + } + + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + + int num = entry.getValue(); + if (num >= 4) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(card)) + { + continue; + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + player.is_gang = false; + List delPai = new ArrayList<>(); + delPai.add(card); + delPai.add(card); + delPai.add(card); + delPai.add(card); + List opCards = new ArrayList<>(); + opCards.addAll(player.opCardList); + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + opCards.add(pongCard); + if (((EXGameController) Global.gameCtr).isTingPai(player, 0, delPai, opCards)) + { + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + Tip tip2 = new Tip(card,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_SELF_ZHAO); + player.tipMgr.addTip(tip2); + } + else { + Tip tip = new Tip(card,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_SELF_ZHAO); + player.tipMgr.addTip(tip); + } + + result = true; + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(card); + } + } + else if (num == 3 && Util.checkCard(card /100 * 100 + 4, player.cardInhand, 1)) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(card)) + { + continue; + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card /100 * 100 + 4); + player.is_gang = false; + + List delPai = new ArrayList<>(); + delPai.add(card); + delPai.add(card); + delPai.add(card); + delPai.add(card /100 * 100 + 4); + List opCards = new ArrayList<>(); + opCards.addAll(player.opCardList); + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card /100 * 100 + 4); + opCards.add(pongCard); + if (((EXGameController) Global.gameCtr).isTingPai(player, 0, delPai, opCards)) + { + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + Tip tip2 = new Tip(card,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_SELF_ZHAO); + player.tipMgr.addTip(tip2); + } + else { + Tip tip = new Tip(card,opcard, RuleWeight.SELFZHAO,this, RuleWeight.TYPE_SELF_ZHAO); + player.tipMgr.addTip(tip); + } + + result = true; + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(card); + } + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + Util.removeCard(player.notPongKongList, tip.card, 4); + } + if (tip.type == RuleWeight.TYPE_SELF_KONG) + { + player.is_gang = true; + if (tip.card > 0) + { + for (Entry entry : player.getRoom().playerMapById.entrySet()) { + EXPlayer pp = (EXPlayer) entry.getValue(); + pp.notPongList.add(tip.card/100*100+1); + pp.notPongList.add(tip.card/100*100+2); + pp.notPongList.add(tip.card/100*100+3); + pp.notPongList.add(tip.card/100*100+4); + } + } + } + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..a36c241 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,93 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + int laizi = config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, true)) { + if (player.cardInhand.size() == 0 && player.opCardList.size() == 6) + { + //WinCard.putWinCardType(map, WinCardType.MAN_TIAN_HU, 1,WinCardType.MAN_TIAN_HU_SCORE, false, "满天胡"); + } + + if (map.containsKey(WinCardType.PENGPENGHU)) + { + if (room.maxPlayers == 4 && (room.bankerSeat+2)%room.maxPlayers+1 == player.seat) + { + map.remove(WinCardType.PENGPENGHU); + WinCard.putWinCardType(map, WinCardType.GUN_GUN, 1,WinCardType.GUN_GUN_SCORE, true, "滚滚"); + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + tip.self = true; + player.tipMgr.addTip(tip); + + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.winCard = tip.card; + player.drawCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + player.niao_score = WinCardType.BASE_HU_SCORE; + player.hu_score = WinCardType.BASE_HU_SCORE; + player.di_score = WinCardType.BASE_HU_SCORE; + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + room.handle_repeatwin(player); + boolean isDaHu = false; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + isDaHu = true; + } + } + + if (isDaHu) + { + player.hu_score = 3; + } + + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRChowState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRChowState.java new file mode 100644 index 0000000..f6a9125 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRChowState.java @@ -0,0 +1,62 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRChowState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + ITArray opcard = owner.opCard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + int card= room.activeCard; + Util.removeCard(owner.cardInhand, chowcard1, 1); + Util.removeCard(owner.cardInhand, chowcard2, 1); + room.activeCard = 0; + + + OpCard opc = new OpCard(RuleWeight.TYPE_CHOW, card); + opc.opCard = new TArray(); + opc.opCard.addInt(card); + opc.opCard.addInt(chowcard1); + opc.opCard.addInt(chowcard2); + owner.opCardList.add(opc); + + ITArray opcard2 = TArray.newInstance(); + opcard2.addInt(chowcard1); + opcard2.addInt(chowcard2); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_CHOW, fromseat, opcard2); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java new file mode 100644 index 0000000..ff1aee8 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java @@ -0,0 +1,104 @@ +package extend.mj.player.rulestate; + + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PROtherGongSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + Util.removeCard(owner.cardInhand, owner.winCard, 1); + if (owner.opCardList.size() > 0) + { + OpCard opCard = owner.opCardList.get(owner.opCardList.size()-1); + if ((opCard.type == RuleWeight.TYPE_KONG) && opCard.card_seat > 0) + { + owner.room.activeSeat = opCard.card_seat; + + room.addAllScore(owner, owner.hu_score, EXScore.WIN); + + room.addAllPiaoNiaoScore(owner); + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + + room.endGame(); + return; + } + else if (opCard.type == RuleWeight.TYPE_SELF_KONG + || (opCard.type == RuleWeight.TYPE_KONG && opCard.card_seat == 0)) + { + room.addAllScore(owner, owner.hu_score,EXScore.WIN); + + room.addAllPiaoNiaoScore(owner); + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + + room.endGame(); + return; + } + } + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..af62fce --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,165 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; +import extend.mj.player.state.EXPlayerWaitKongWinState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PROtherKongState.java + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size()-1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + //room.addScore(owner,activePlayer, Config.MING_GANG_SCORE,EXScore.KONG); + owner.ming_gang_num++; + activePlayer.dian_gang_num++; + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(owner.getRoom().activeCard); + + + int [] kongGroup = new int [4]; + int card = room.activeCard; + if (Util.checkCard(card, owner.cardInhand, 4)) { + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + + owner.kongGroup.add(kongGroup); + if (owner.is_gang) + { + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, card, activePlayer.seat); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + owner.opCardList.add(pongCard); + owner.gangshangpao = true; + } + else { + OpCard pongCard = new OpCard(RuleWeight.TYPE_ZHAO, card, activePlayer.seat); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + owner.opCardList.add(pongCard); + } + + Util.removeCard(owner.cardInhand, card, 4); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + if (owner.is_gang) + { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + } + else { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_ZHAO, fromseat,opcard); + } + } + else if (Util.checkCard(card, owner.cardInhand, 3) && Util.checkCard(card /100 * 100 + 4, owner.cardInhand, 1)) { + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card /100 * 100 + 4; + + owner.kongGroup.add(kongGroup); + if (owner.is_gang) + { + OpCard pongCard = new OpCard(RuleWeight.TYPE_KONG, card, activePlayer.seat); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card /100 * 100 + 4); + owner.opCardList.add(pongCard); + owner.gangshangpao = true; + } + else { + OpCard pongCard = new OpCard(RuleWeight.TYPE_ZHAO, card, activePlayer.seat); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card /100 * 100 + 4); + owner.opCardList.add(pongCard); + } + + Util.removeCard(owner.cardInhand, card, 3); + Util.removeCard(owner.cardInhand, card /100 * 100 + 4, 1); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card /100 * 100 + 4); + if (owner.is_gang) + { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + } + else { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_ZHAO, fromseat,opcard); + } + } + + room.activeCard = card; + boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG_MING); + if(qiangkong) { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + if(room.tipMap.size() == 0){ + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + toNextState(owner); + }else{ + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..383fe48 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,43 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; +import extend.mj.*; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.winer = 1; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + + room.addScore(owner,activePlayer, owner.hu_score, EXScore.WIN); + + room.addPiaoNiaoScore(owner, activePlayer); + activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO); + activePlayer.winer = 2; + activePlayer.last_winer = 2; + + owner.settleLog.add(Config.SETTLE_JIE_PAO); + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + room.bankerSeat = owner.seat; + room.winCount += 1; + + owner.winCard = room.activeCard; + + room.winCallback( owner ,owner.winCard); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..1493738 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,92 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PRPongState.java + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + OpCard pongCard = new OpCard(RuleWeight.TYPE_PONG, card, activePlayer.seat); + pongCard.opCard = new TArray(); + if (Util.checkCard(card, owner.cardInhand, 3)) { + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 3); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + + + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + owner.opCardList.add(pongCard); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + } + else if (Util.checkCard(card, owner.cardInhand, 2) && Util.checkCard(card / 100 * 100 + 4, owner.cardInhand, 1)) { + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card / 100 * 100 + 4; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 2); + Util.removeCard(owner.cardInhand, card / 100 * 100 + 4, 1); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + + + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card / 100 * 100 + 4); + owner.opCardList.add(pongCard); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card / 100 * 100 + 4); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + } + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..5177fdf --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,119 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRSelfKongState.java + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + int [] kongGroup = new int [4]; + if (opCard.size() >= 2) + { + Util.removeCard(owner.cardInhand, card, 3); + Util.removeCard(owner.cardInhand, card/100*100+4, 1); + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card/100*100+4; + owner.selfKongGroup.add(kongGroup); + if (owner.is_gang) + { + OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_KONG, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card/100*100+4); + owner.opCardList.add(pongCard); + owner.gangshangpao = true; + } + else { + OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_ZHAO, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card/100*100+4); + owner.opCardList.add(pongCard); + } + + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card/100*100+4); + if (owner.is_gang) + { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + } + else { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_ZHAO, owner.seat,opcard); + } + } + else { + Util.removeCard(owner.cardInhand, card, 4); + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + owner.selfKongGroup.add(kongGroup); + if (owner.is_gang) + { + OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_KONG, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + owner.opCardList.add(pongCard); + owner.gangshangpao = true; + } + else { + OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_ZHAO, card); + pongCard.opCard = new TArray(); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + pongCard.opCard.addInt(card); + owner.opCardList.add(pongCard); + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + if (owner.is_gang) + { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + } + else { + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_ZHAO, owner.seat,opcard); + } + } + + + //room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.KONG); + owner.an_gang_num++; + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + owner.settleLog.add(Config.SETTLE_AN_KONG); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..810c451 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,70 @@ +package extend.mj.player.rulestate; + + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map.Entry; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + + Util.removeCard(owner.cardInhand, owner.winCard, 1); + + room.addAllScore(owner, owner.hu_score,EXScore.WIN); + + room.addAllPiaoNiaoScore(owner); + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.endGame(); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..2e3d968 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ��ҳ�����ʾ״̬ + * + * + * 2017��8��30�� + * EXPlayerDisCardTipState.java + */ +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..855805d --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,111 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.*; + +import extend.mj.*; +import extend.mj.room.state.EXRoomSetpState; + +/** + * �ȴ���ҳ���״̬ + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (owner.is_gang) + { + owner.louhu = false; + int discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + else { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.louhu = false; + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_TIMER_AUTO: + owner.louhu = false; + discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..7f29a50 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,199 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + boolean laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI) > 0 ? true : false; + + if(owner.seat == room.adminSeat) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + if (owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else if (owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else { + owner.drawCard = room.card.pop(); + } + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + + private boolean IsGoodCard(EXPlayer player, int drawCard, boolean laizi) { + if (player.getRoom().isLaizi(drawCard)) + { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + for (int[] cardGroup : player.pongGroup) { + if (drawCard == cardGroup[0]) { + return true; + } + } + + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, drawCard, player.getRoom().card.laiziCard, player.getRoom().card.laiziCard2, laizi, true, true); + if (win.checkWin(map, player, player.getRoom(), true)) { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } + + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..f2b5baf --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,43 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ���ץ����ʾ״̬ + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ; + if(Global.gameId == 1 && win && id == 0)return; + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java new file mode 100644 index 0000000..5ca4c87 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java @@ -0,0 +1,139 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import com.taurus.permanent.TPServer; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerKongDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.pop(); + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.KONG_DRAW_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.is_gang) + { + timer(owner); + } + else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + public static void timer(EXPlayer owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null || owner.getRoom() == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.getRoom().isDestroy) + return; + + owner.getRoom().enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + }); + } + }, 1000, TimeUnit.MILLISECONDS); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..441c172 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,42 @@ +package extend.mj.player.state; + +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * ���������ʾ�ȴ� + * + * + * 2017��8��30�� + * EXPlayerKongWinState.java + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..4d6945a --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,63 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.piaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piao = id; + owner.last_piao = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + EXMainServer.gameCtr.piaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_PIAO)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..db227ac --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,61 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * �����ʾ������� + * + * + * 2017��8��30�� + * EXPlayerTipState.java + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_ZI_DONG_HU)) + { + Tip tip = owner.tipMgr.getTip(RuleWeight.TYPE_WIN); + if (tip != null) + { + owner.startActionTimer(1000); + return; + } + } + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tipEvent(owner); + } + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if(cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..dff6a34 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,24 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * ������ҵȴ��������ǹ�ܺ� + * + * + * 2017��8��30�� + * EXPlayerWaitKongWinState.java + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..858aee0 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,39 @@ +package extend.mj.player.state; + + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * ��ҵȴ�״̬ + * + * + * 2017��8��30�� + * EXPlayerWaitState.java + */ +public class EXPlayerWaitState extends StateBase { + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.forceCheckWin = true; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + owner.forceCheckWin = false; + break; + default: + break; + } + + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..6a9e5da --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,105 @@ +package extend.mj.room.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import com.taurus.permanent.TPServer; +import extend.mj.*; + +/** + * ���䷢��״̬ + * + * + * 2017��8��30�� + * EXRoomDealState.java + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + ArrayList randPlayer = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + Integer seat = entry.getKey(); + randPlayer.add(seat); + } + + Collections.shuffle(randPlayer); + if (randPlayer.size() > 0) + { + owner.bankerSeat = randPlayer.get(0); + } + } + else { + if (owner.config.getInt(Config.ROOM_CONFIG_XUAN_ZHUANG) == 0) + { + owner.bankerSeat = (owner.bankerSeat)%owner.maxPlayers+1; + } + } + + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomPiaoState.java b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..0a522d7 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomPiaoState.java @@ -0,0 +1,30 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.EXActionEvent; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; + +import java.util.Map.Entry; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO)) { + if(owner.piaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..47fbd44 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,42 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ����ת����λ + * + * + * 2017��8��30�� + * EXRoomSetpState.java + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + this.toNextState(owner); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..1a2b807 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,58 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; + +import java.util.Map; + +/** + * ���俪ʼ״̬ + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + if(owner.config.containsKey(Config.ROOM_CONFIG_PIAO) && owner.config.getInt(Config.ROOM_CONFIG_PIAO) != 0) { + if (owner.config.getInt(Config.ROOM_CONFIG_PIAO) == 3) + { + int piaofen = owner.config.getInt(Config.ROOM_CONFIG_PIAO_FEN); + + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.piao = piaofen; + player.last_piao = piaofen; + EXMainServer.gameCtr.piaoEvent(player); + } + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + else { + owner.stateMachine.changeState(Global.getState(EXRoomPiaoState.class)); + } + } + else{ + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/tip/Action.java b/game_mj_fulushou/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..454d9ca --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + + */ +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_fulushou/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..79f1ab8 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * ����������� + * + * + * 2017��8��30�� + * RuleBase.java + */ +public interface IRuleBase { + + /** + * ������� + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * ִ�иù��� + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/tip/Tip.java b/game_mj_fulushou/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..b4f6ce4 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,46 @@ +package extend.mj.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.mj.WinCardType; + +import java.util.Map; + +/** + * tip������ + * + * + * + * 2017��8��30�� Tip.java + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int winType; + public int type; + public boolean self; + public Map winMap; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + this.self = false; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/tip/TipManager.java b/game_mj_fulushou/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..9f40ee2 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,142 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; + +/** + * + * + * + * 2017��9��18�� TipManager.java + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + public Tip getTip(int type) + { + for (Entry entry : this.tipMap.entrySet()) + { + Tip tip = entry.getValue(); + if (tip.type == type) + { + return tip; + } + } + return null; + } + + private void checkLouhu() { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_LOUHU)) + { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + } + + public void choicAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_fulushou/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..e8ed060 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,51 @@ +package extend.mj.uitl; + +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.OpCard; +import extend.mj.WinCardType; + +public class CardUtil { + + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card == opcards.get(i).card) { + opcards.remove(i); + return; + } + + } + + } + + static public ITArray toMPData_WinMap(Map map) { + return toMPData_WinMap(map,false); + } + + static public ITArray toMPData_WinMap(Map map,boolean is_opcard) { + if (map != null && map.size() > 0) { + ITArray array = TArray.newInstance(); + for (Map.Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + array.addTObject(wct.toTObject(is_opcard)); + } + return array; + } + return null; + } +} diff --git a/game_mj_fulushou/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_fulushou/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..5647791 --- /dev/null +++ b/game_mj_fulushou/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,1466 @@ +package extend.mj.uitl; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; + +import java.util.*; + +public class WinCard { + + public List cardList; + public int laizi_count; + public int laizi1_count; + public int laizi2_count; + public int laizi1 = 0; + public int laizi2 = 0; + public boolean zi_mo = false; + public boolean ting_pai = false; + public Map cbCardMap; + public int addCard = 0; + public boolean selfCard = false; + + public WinCard(List cardInhand, int addCard, int laizi1, int laizi2, boolean islaizi, boolean selfCard, boolean ting_pai) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + this.ting_pai = ting_pai; + this.selfCard = selfCard; + this.addCard = addCard; + if (selfCard) + { + this.cardList.add(addCard); + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + } + else { + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + this.cardList.add(addCard); + } + + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + public WinCard(List cardInhand, int laizi1, int laizi2, boolean islaizi, boolean ting_pai) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + this.ting_pai = ting_pai; + this.selfCard = true; + this.addCard = 0; + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + public boolean checkWin(Map map, EXPlayer player, EXRoom room, boolean zimo) { + return checkWinOpList(map, player, player.opCardList, room, zimo); + } + + public boolean checkWinOpList(Map map, EXPlayer player, List opList, EXRoom room, boolean zimo) { + if (this.cardList.size() == 0) { + return false; + } + + this.zi_mo = zimo; + + boolean hu = AnalyseChiHuCard(map, opList, room.config); + if (hu) + { + if (zimo) + { + if (room.card.cardList.size() == 0 && room.config.getBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + WinCard.putWinCardType(map, WinCardType.HAI_DI_NAO_YUE, 1,WinCardType.HAI_DI_NAO_YUE_SCORE, true, "海底捞月"); + } + } + else { + + } + } + + if (zimo) + { + if (room.config.getBoolean(Config.ROOM_CONFIG_MENG_QING)) + { + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.type == WinCardType.JIHU || cardType.type == WinCardType.PINGHU) + { + boolean flag = true; + for(int i = 0; i < opList.size(); i++) + { + OpCard op_card = opList.get(i); + if (op_card.type != RuleWeight.TYPE_SELF_KONG && op_card.type != RuleWeight.TYPE_SELF_ZHAO) + { + flag = false; + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.ZIMO_MEN_QING, 1,WinCardType.ZIMO_MEN_QING_SCORE, true, "门清自摸"); + } + break; + } + } + } + } + else + { + if (room.config.getBoolean(Config.ROOM_CONFIG_MENG_QING)) + { + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.type == WinCardType.JIHU || cardType.type == WinCardType.PINGHU) + { + boolean flag = true; + for(int i = 0; i < opList.size(); i++) + { + OpCard op_card = opList.get(i); + if (op_card.type != RuleWeight.TYPE_SELF_KONG && op_card.type != RuleWeight.TYPE_SELF_ZHAO) + { + flag = false; + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.MEN_QING, 1,WinCardType.MENGQING_SCORE, true, "门清捉炮"); + } + break; + } + } + } + + + if (room.config.getBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU)) + { + WinCardType jihuType = map.get(WinCardType.JIHU); + if (jihuType != null) + { + //鸡胡不能吃胡 + return false; + } + } + + if (room.config.getBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + int hu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE)) + { + hu_score = WinCardType.BASE_HU_SCORE; + } + else + { + player.hu_score = room.maxPlayers - 1; + player.di_score = room.maxPlayers - 1; + } + + int dahu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + dahu_score = 1; + } + int cheng_score = 1; + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + { + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + cheng_score *= cardType.score; + } + } + else + { + if (cardType.IsDaHu()) + { + dahu_score += cardType.score*WinCardType.DA_HU_BEI_SCORE; + } + else + { + cheng_score *= cardType.score; + } + } + } + } + + if (dahu_score > 0) + { + hu_score *= dahu_score; + } + + hu_score *= cheng_score; + + if (hu_score < 20) + { + return false; + } + } + } + + return hu; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score, boolean isDaHu, String desc) { + if (map == null) + return null; + if (isDaHu) + { + map.remove(WinCardType.JIHU); + map.remove(WinCardType.PINGHU); + } + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score, isDaHu, desc); + map.put(type, wct); + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } + } + + public boolean AnalyseChiHuCard(Map map, List opCards, ITObject config) + { + Map tempCardList = new HashMap(); + tempCardList.putAll(this.cbCardMap); + + if (AnalyseChiHuCardEx(map, tempCardList, 0, opCards, config)) + { + return true; + } + + return false; + } + + boolean AnalyseChiHuCardEx(Map map, Map cardListParam, int curCard, List opCards, ITObject config) + { + Map tempCardList = new HashMap<>(); + tempCardList.putAll(cardListParam); + + if (curCard > 0) + { + tempCardList.put(curCard, tempCardList.getOrDefault(curCard, 0)+1); + } + + List clearCardList = new ArrayList<>(); + for (Map.Entry entry : tempCardList.entrySet()) { + if (entry.getValue() == 0) + { + clearCardList.add(entry.getKey()); + } + } + + for(int i = 0; i < clearCardList.size(); i++) + { + tempCardList.remove(clearCardList.get(i)); + } + + //变量定义 + List tagAnalyseItemList = new ArrayList(); + List wChiHuKind = new ArrayList(); + + //分析麻将 + AnalyseCard(tempCardList, opCards, tagAnalyseItemList, config); + + //胡牌分析 + if (tagAnalyseItemList.size() > 0) + { + //牌型分析 + for (int i = 0;i < tagAnalyseItemList.size();i++) + { + //变量定义 + boolean bLianCard=false,bPengCard=false,b258Card=false; + TagAnalyseItem pAnalyseItem= tagAnalyseItemList.get(i); + + if (pAnalyseItem.huxi < 11) + { + if (this.zi_mo || this.zi_mo == false && config.getInt(Config.ROOM_CONFIG_QING_ZUI_HU) > 0) + { + boolean erxiaosheng = false; + boolean bajiuzi = false; + boolean jiazuoren = false; + for (int j = 0;j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + if (cbWeaveKind.card % 100 == 5) + { + erxiaosheng = true; + } + else if (cbWeaveKind.card % 100 == 6) + { + bajiuzi = true; + } + else if (cbWeaveKind.card % 100 == 7) + { + jiazuoren = true; + } + } + } + + if (erxiaosheng == false || bajiuzi == false || jiazuoren == false) + { + continue; + } + } + else { + continue; + } + } + + //牌型分析 + for (int j = 0;j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_ZHAO + || cbWeaveKind.type == RuleWeight.TYPE_SELF_ZHAO) { + bPengCard = true; + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + bLianCard = true; + } + } + + //牌型判断 + if (bLianCard==false && bPengCard==false) + { + return false; + } + + if (bLianCard && bPengCard == false) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else if (bLianCard && bPengCard) + { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + + //特殊--碰碰胡 + if ((bLianCard==false)&&(bPengCard==true)) + { + if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) + { + if (config.getBoolean(Config.ROOM_CONFIG_SPECIAL_PENG_PENG_HU)) + { + if (pAnalyseItem.cbCardEye > 0 && pAnalyseItem.cbCardEyeList.size() == 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + else if (pAnalyseItem.cbCardEyeList.size() > 0) + { + boolean flag = true; + for(int x = 0; x < pAnalyseItem.cbCardEyeList.size(); x++) + { + ITArray xCardList = pAnalyseItem.cbCardEyeList.get(x); + int card1 = xCardList.getInt(0); + int card2 = xCardList.getInt(1); + if (card1 != card2) + { + if (card1 % 100 != 4 && card2 % 100 != 4) + { + flag = false; + } + } + } + + if (flag) + { + wChiHuKind.add(WinCardType.PENGPENGHU); + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.PENGPENGHU_SCORE, true, "碰碰胡"); + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + } + else { + if (pAnalyseItem.cbCardEyeList.size() > 0) + { + boolean flag = true; + for(int x = 0; x < pAnalyseItem.cbCardEyeList.size(); x++) + { + ITArray xCardList = pAnalyseItem.cbCardEyeList.get(x); + int card1 = xCardList.getInt(0); + int card2 = xCardList.getInt(1); + if (card1 != card2) + { + if (card1 % 100 != 4 && card2 % 100 != 4) + { + flag = false; + } + } + } + + if (flag) + { + wChiHuKind.add(WinCardType.PENGPENGHU); + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.PENGPENGHU_SCORE, true, "碰碰胡"); + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + } + } + + //结果判断 + if (wChiHuKind.size() > 0) + { + return true; + } + + return false; + } + + public boolean IsShangFu(int card) + { + if (card == 101 || card == 801) + { + return true; + } + return false; + } + + public boolean IsDaRen(int card) + { + if (card == 102 || card == 103) + { + return true; + } + return false; + } + + boolean IsLuShou(int card) + { + if (card == 802 || card == 803) + { + return true; + } + return false; + } + + public boolean IsDaRenLuShou(int card) + { + if (card == 102 || card == 103 || card == 802 || card == 803) + { + return true; + } + return false; + } + + public boolean IsShangDaRen(int card) + { + if (card / 100 == 1) + { + return true; + } + return false; + } + + public boolean IsFuLuShou(int card) + { + if (card / 100 == 8) + { + return true; + } + return false; + } + + public boolean IsShangDaRenFuLuShou(int card) + { + if (card / 100 == 1 || card / 100 == 8) + { + return true; + } + return false; + } + + public boolean AnalyseCardFuLuShou(int cbLessKindItem, TagKindItem[] pKindItem, int eyeCard, List opCards, List tagAnalyseItemList, ITObject config) { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置结果 + for (int i = 0; i < opCards.size(); i++) { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(src_card); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + if (IsShangDaRenFuLuShou(src_card.card)) + { + AnalyseItem.huxi += 4; + } + } + else if (src_card.type == RuleWeight.TYPE_PONG) + { + if (IsShangFu(src_card.card)) + { + AnalyseItem.huxi += 3 * 4; + } + else { + AnalyseItem.huxi += 2; + } + } + else + { + if (IsShangFu(src_card.card)) + { + AnalyseItem.huxi += 4 * 4; + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI)) + { + AnalyseItem.huxi += 6; + } + else { + AnalyseItem.huxi += 4; + } + } + } + } + + //设置牌型 + boolean useOther = false; + boolean usePong = false; + if (pKindItem != null) + { + for (int i = 0; i < cbLessKindItem; i++) { + OpCard op_card = new OpCard(pKindItem[i].type, pKindItem[i].card); + AnalyseItem.cbOpCard.add(op_card); + if (op_card.type == RuleWeight.TYPE_CHOW) + { + if (IsShangDaRenFuLuShou(op_card.card)) + { + AnalyseItem.huxi += 4; + } + if (!this.selfCard && (pKindItem[i].cbCardList[0] == this.addCard) || (pKindItem[i].cbCardList[1] == this.addCard) || (pKindItem[i].cbCardList[2] == this.addCard)) + { + useOther = true; + } + } + else if (op_card.type == RuleWeight.TYPE_PONG) + { + if (IsShangFu(op_card.card)) + { + AnalyseItem.huxi += 3 * 4; + } + else { + AnalyseItem.huxi += 3; + if (!this.selfCard && op_card.card == this.addCard) + { + usePong = true; + } + } + } + else + { + if (!this.selfCard && op_card.card == this.addCard) + { + useOther = true; + } + if (IsShangFu(op_card.card)) + { + AnalyseItem.huxi += 4 * 4; + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI)) + { + AnalyseItem.huxi += 6; + } + else { + AnalyseItem.huxi += 4; + } + } + } + } + } + + if (eyeCard > 0) { + AnalyseItem.cbCardEye = eyeCard; + if (!this.selfCard && eyeCard == this.addCard) + { + useOther = true; + } + if (IsShangFu(eyeCard)) + { + AnalyseItem.huxi += 8; + } + else if (IsDaRenLuShou(eyeCard)) { + AnalyseItem.huxi += 4; + } + else if (eyeCard == 104 || eyeCard == 804) + { + AnalyseItem.huxi += 8; + } + } + + if (useOther == false && usePong) + { + AnalyseItem.huxi -= 1; + } + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + if (AnalyseItem.huxi >= 11) + { + return true; + } + return false; + } + + public boolean AnalyseCardFuLuShouJiang(int cbLessKindItem, TagKindItem[] pKindItem, int card1, int card2, int card3, int card4, List opCards, List tagAnalyseItemList, ITObject config) { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置结果 + //设置结果 + boolean diJin = false; + boolean shangDaRenFuLuShou = false; + boolean ban_shangDaRenFuLuShou = false; + boolean hasKan = false; + for (int i = 0; i < opCards.size(); i++) { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(src_card); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + if (IsShangDaRenFuLuShou(src_card.card)) + { + shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + } + else if (src_card.type == RuleWeight.TYPE_PONG) + { + hasKan = true; + if (IsShangFu(src_card.card)) + { + AnalyseItem.huxi += 3 * 4; + } + else { + AnalyseItem.huxi += 2; + } + } + else + { + hasKan = true; + if (IsShangFu(src_card.card)) + { + AnalyseItem.huxi += 4 * 4; + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI)) + { + AnalyseItem.huxi += 6; + } + else { + AnalyseItem.huxi += 4; + } + } + } + } + + //设置牌型 + boolean useOther = false; + boolean usePong = false; + if (pKindItem != null) + { + for (int i = 0; i < cbLessKindItem; i++) { + OpCard op_card = new OpCard(pKindItem[i].type, pKindItem[i].card); + AnalyseItem.cbOpCard.add(op_card); + if (op_card.type == RuleWeight.TYPE_CHOW) + { + if (IsShangDaRenFuLuShou(op_card.card)) + { + shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + if (!this.selfCard && (pKindItem[i].cbCardList[0] == this.addCard) || (pKindItem[i].cbCardList[1] == this.addCard) || (pKindItem[i].cbCardList[2] == this.addCard)) + { + useOther = true; + } + } + else if (op_card.type == RuleWeight.TYPE_PONG) + { + hasKan = true; + if (IsShangFu(op_card.card)) + { + AnalyseItem.huxi += 3 * 4; + } + else { + AnalyseItem.huxi += 3; + if (!this.selfCard && op_card.card == this.addCard) + { + usePong = true; + } + } + } + else + { + if (!this.selfCard && op_card.card == this.addCard) + { + useOther = true; + } + hasKan = true; + if (IsShangFu(op_card.card)) + { + AnalyseItem.huxi += 4 * 4; + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI)) + { + AnalyseItem.huxi += 6; + } + else { + AnalyseItem.huxi += 4; + } + } + } + } + } + + ITArray eyeCard1 = new TArray(); + eyeCard1.addInt(card1); + eyeCard1.addInt(card2); + AnalyseItem.cbCardEyeList.add(eyeCard1); + + ITArray eyeCard2 = new TArray(); + eyeCard2.addInt(card3); + eyeCard2.addInt(card4); + AnalyseItem.cbCardEyeList.add(eyeCard2); + + if (!this.selfCard && (card1 == this.addCard || card2 == this.addCard || card3 == this.addCard || card4 == this.addCard)) + { + useOther = true; + } + + //一对上、福,就可以胡了 + if (card1 == card2 && IsShangFu(card1)) + { + AnalyseItem.huxi += 12; + } + else if (card1 == card2 && (card1 == 104 || card1 == 804)) + { + AnalyseItem.huxi += 12; + } + else if (card1 == 101 && card2 == 104 || card2 == 101 && card1 == 104) + { + AnalyseItem.huxi += 12; + } + else if (card1 == 801 && card2 == 804 || card2 == 801 && card1 == 804) + { + AnalyseItem.huxi += 12; + } + else if ((card1 == 101 || card2 == 101 ) && card1 != card2) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card1 == 104 || card2 == 104 ) && card1 != card2) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card1 == 801 || card2 == 801 ) && card1 != card2) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card1 == 804 || card2 == 804 ) && card1 != card2) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + + if (card3 == card4 && IsShangFu(card3)) + { + AnalyseItem.huxi += 12; + } + else if (card3 == card4 && (card3 == 104 || card3 == 804)) + { + AnalyseItem.huxi += 12; + } + else if (card3 == 101 && card4 == 104 || card4 == 101 && card3 == 104) + { + AnalyseItem.huxi += 12; + } + else if (card3 == 801 && card4 == 804 || card4 == 801 && card3 == 804) + { + AnalyseItem.huxi += 12; + } + else if ((card3 == 101 || card4 == 101) && card3 != card4) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card3 == 104 || card4 == 104) && card3 != card4) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card3 == 801 || card4 == 801) && card3 != card4) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + else if ((card3 == 804 || card4 == 804) && card3 != card4) + { + ban_shangDaRenFuLuShou = true; + AnalyseItem.huxi += 4; + } + + if (shangDaRenFuLuShou || ban_shangDaRenFuLuShou || hasKan) { + if (card1 != card2 && IsDaRen(card1) && IsDaRen(card2) || card3 != card4 && IsDaRen(card3) && IsDaRen(card4)) + { + if (!diJin) { + diJin = true; + AnalyseItem.huxi += 4; + } + } + if (card1 != card2 && IsLuShou(card1) && IsLuShou(card2) || card3 != card4 && IsLuShou(card3) && IsLuShou(card4)) + { + if (!diJin) { + diJin = true; + AnalyseItem.huxi += 4; + } + } + if ((card1 == card2 && !IsShangFu(card1) && card1 != 104 && card1 != 804) || + (card3 == card4 && !IsShangFu(card3) && card3 != 104 && card3 != 804)) + { + if (!diJin) { + diJin = true; + AnalyseItem.huxi += 3; + } + } + else if ((card1 != card2 && ((card1 / 100 != 1 && card1 / 100 != 8 && card1 % 100 == 4) || (card2 / 100 != 1 && card2 / 100 != 8 && card2 % 100 == 4)) && !IsShangFu(card1)) || + (card3 != card4 && ((card3 / 100 != 1 && card3 / 100 != 8 && card3 % 100 == 4) || (card4 / 100 != 1 && card4 / 100 != 8 && card4 % 100 == 4)) && !IsShangFu(card3))) + { + if (!diJin) { + diJin = true; + AnalyseItem.huxi += 3; + } + } + } + + if (useOther == false && usePong) + { + AnalyseItem.huxi -= 1; + } + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + if (AnalyseItem.huxi >= 11) + { + return true; + } + return false; + } + + boolean AnalyseCard(Map tempCardList, List opCards, List tagAnalyseItemList, ITObject config) { + //计算数目 + int cbCardCount = 0; + for (Map.Entry entry : tempCardList.entrySet()) { + cbCardCount += entry.getValue(); + } + + //效验数目 + if ((cbCardCount < 1) || (cbCardCount > 19)) { + return false; + } + + //变量定义 + List tagKindList = new ArrayList(); + + do { + int cbLessKindItem = (cbCardCount - 1) / 3; + if (cbLessKindItem + opCards.size() != 6) { + break; + } + + //单吊判断 + if (cbLessKindItem == 0) { + //效验参数 + if (!((cbCardCount == 1) && (opCards.size() == 6))) { + return false; + } + + //牌眼判断 + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 1) { + return AnalyseCardFuLuShou(cbLessKindItem, null, card, opCards, tagAnalyseItemList, config); + } + } + + return false; + } + + //拆分分析 + if (cbCardCount >= 3) { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + //同牌判断 + if (num >= 2 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) == 1) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card / 100 * 100 + 4; + tagKindList.add(kindItem); + } + + if (num >= 3) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card; + tagKindList.add(kindItem); + } + + //连牌判断 + if (card % 100 >= 1 && card % 100 <= 4 && num > 0) { + for (int i = 1; i <= num; i++) { + if (tempCardList.getOrDefault(card + 1, 0) >= i && tempCardList.getOrDefault(card + 2, 0) >= i && (card+1)%100 != 4 && (card+2)%100 != 4) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + if (tempCardList.getOrDefault(card + 1, 0) >= i && (card+1)%100 != 4 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) >= i) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card / 100 * 100 + 4; + tagKindList.add(kindItem); + } + if (tempCardList.getOrDefault(card + 2, 0) >= i && (card+2)%100 != 4 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) >= i) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card / 100 * 100 + 4; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + } + } + } + } + + //组合分析 + if (tagKindList.size() >= cbLessKindItem) { + //变量定义 + Integer[] cbIndex = new Integer[6]; //{0,1,2,3}; + cbIndex[0] = 0; + cbIndex[1] = 1; + cbIndex[2] = 2; + cbIndex[3] = 3; + cbIndex[4] = 4; + cbIndex[5] = 5; + + TagKindItem[] pKindItem = new TagKindItem[6]; + pKindItem[0] = null; + pKindItem[1] = null; + pKindItem[2] = null; + pKindItem[3] = null; + pKindItem[4] = null; + pKindItem[5] = null; + + int count = 0; + //开始组合 + do { + count++; + //设置变量 + Map cbCardMap_temp = new HashMap(); + cbCardMap_temp.putAll(tempCardList); + + for (int i = 0; i < cbLessKindItem; i++) { + pKindItem[i] = tagKindList.get(cbIndex[i]); + } + + //数量判断 + boolean bEnoughCard = true; + for (int i = 0; i < cbLessKindItem * 3; i++) { + //存在判断 + int cbCardIndex = pKindItem[i / 3].cbCardList[i % 3]; + if (cbCardMap_temp.getOrDefault(cbCardIndex, 0) <= 0) { + bEnoughCard = false; + break; + } else { + if (cbCardMap_temp.containsKey(cbCardIndex)) { + cbCardMap_temp.put(cbCardIndex, cbCardMap_temp.get(cbCardIndex) - 1); + } + } + } + + //胡牌判断 + if (bEnoughCard == true) { + //牌眼判断 + int cbCardEye = 0; + for (Map.Entry entry : cbCardMap_temp.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 1) { + cbCardEye = card; + break; + } + } + + //组合类型 + if (cbCardEye != 0) { + boolean result = AnalyseCardFuLuShou(cbLessKindItem, pKindItem, cbCardEye, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + } + + //设置索引 + if (cbIndex[cbLessKindItem - 1] == (tagKindList.size() - 1)) { + int i = cbLessKindItem - 1; + for (; i > 0; i--) { + if ((cbIndex[i - 1] + 1) != cbIndex[i]) { + int cbNewIndex = cbIndex[i - 1]; + for (int j = (i - 1); j < cbLessKindItem; j++) { + cbIndex[j] = cbNewIndex + j - i + 2; + } + break; + } + } + if (i == 0) break; + } else { + cbIndex[cbLessKindItem - 1]++; + } + + } while (true); + //Global.logger.info("count:" + count); + } + + if (tagAnalyseItemList.size() > 0) { + break; + } + } + while (false); + tagKindList.clear(); + + do { + int cbLessKindItem = (cbCardCount - 4) / 3; + if (cbLessKindItem + opCards.size() != 5) { + break; + } + + //单吊判断 + if (cbLessKindItem == 0) { + //效验参数 + if (!((cbCardCount == 4) && (opCards.size() == 5))) { + return false; + } + + //牌眼判断 + ArrayList eyeList = new ArrayList(); + ArrayList eyeCardList = new ArrayList(); + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num > 0) { + for(int i = 0; i < num; i++) + { + eyeCardList.add(card); + } + } + } + + if (eyeCardList.size() != 4) + { + return false; + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(1) / 100 && eyeCardList.get(2) / 100 == eyeCardList.get(3) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(1); + int card3 = eyeCardList.get(2); + int card4 = eyeCardList.get(3); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, null, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(2) / 100 && eyeCardList.get(1) / 100 == eyeCardList.get(3) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(2); + int card3 = eyeCardList.get(1); + int card4 = eyeCardList.get(3); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, null, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(3) / 100 && eyeCardList.get(2) / 100 == eyeCardList.get(1) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(3); + int card3 = eyeCardList.get(2); + int card4 = eyeCardList.get(1); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, null, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + + if (tagAnalyseItemList.size() > 0) + { + return true; + } + else { + return false; + } + } + + //拆分分析 + if (cbCardCount >= 3) { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + //同牌判断 + if (num >= 2 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) == 1) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card / 100 * 100 + 4; + tagKindList.add(kindItem); + } + + if (num >= 3) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card; + tagKindList.add(kindItem); + } + + //连牌判断 + if (card % 100 >= 1 && card % 100 <= 4 && num > 0) { + for (int i = 1; i <= num; i++) { + if (tempCardList.getOrDefault(card + 1, 0) >= i && tempCardList.getOrDefault(card + 2, 0) >= i && (card+1)%100 != 4 && (card+2)%100 != 4) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + if (tempCardList.getOrDefault(card + 1, 0) >= i && (card+1)%100 != 4 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) >= i) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card / 100 * 100 + 4; + tagKindList.add(kindItem); + } + if (tempCardList.getOrDefault(card + 2, 0) >= i && (card+2)%100 != 4 && tempCardList.getOrDefault(card / 100 * 100 + 4, 0) >= i) { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card / 100 * 100 + 4; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + } + } + } + } + + //组合分析 + if (tagKindList.size() >= cbLessKindItem) { + //变量定义 + Integer[] cbIndex = new Integer[5]; //{0,1,2,3}; + cbIndex[0] = 0; + cbIndex[1] = 1; + cbIndex[2] = 2; + cbIndex[3] = 3; + cbIndex[4] = 4; + + TagKindItem[] pKindItem = new TagKindItem[5]; + pKindItem[0] = null; + pKindItem[1] = null; + pKindItem[2] = null; + pKindItem[3] = null; + pKindItem[4] = null; + + //开始组合 + int count = 0; + do { + count++; + //设置变量 + Map cbCardMap_temp = new HashMap(); + cbCardMap_temp.putAll(tempCardList); + + for (int i = 0; i < cbLessKindItem; i++) { + pKindItem[i] = tagKindList.get(cbIndex[i]); + } + + //数量判断 + boolean bEnoughCard = true; + for (int i = 0; i < cbLessKindItem * 3; i++) { + //存在判断 + int cbCardIndex = pKindItem[i / 3].cbCardList[i % 3]; + if (cbCardMap_temp.getOrDefault(cbCardIndex, 0) <= 0) { + bEnoughCard = false; + break; + } else { + if (cbCardMap_temp.containsKey(cbCardIndex)) { + cbCardMap_temp.put(cbCardIndex, cbCardMap_temp.get(cbCardIndex) - 1); + } + } + } + + //胡牌判断 + if (bEnoughCard == true) { + //牌眼判断 + ArrayList eyeList = new ArrayList(); + ArrayList eyeCardList = new ArrayList(); + for (Map.Entry entry : cbCardMap_temp.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num > 0) { + for(int i = 0; i < num; i++) + { + eyeCardList.add(card); + } + } + } + + if (eyeCardList.size() != 4) + { + return false; + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(1) / 100 && eyeCardList.get(2) / 100 == eyeCardList.get(3) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(1); + int card3 = eyeCardList.get(2); + int card4 = eyeCardList.get(3); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, pKindItem, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(2) / 100 && eyeCardList.get(1) / 100 == eyeCardList.get(3) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(2); + int card3 = eyeCardList.get(1); + int card4 = eyeCardList.get(3); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, pKindItem, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + + if (eyeCardList.get(0) / 100 == eyeCardList.get(3) / 100 && eyeCardList.get(2) / 100 == eyeCardList.get(1) / 100) + { + int card1 = eyeCardList.get(0); + int card2 = eyeCardList.get(3); + int card3 = eyeCardList.get(2); + int card4 = eyeCardList.get(1); + + boolean result = AnalyseCardFuLuShouJiang(cbLessKindItem, pKindItem, card1, card2, card3, card4, opCards, tagAnalyseItemList, config); + if (ting_pai && result) + { + return true; + } + } + } + + //设置索引 + if (cbIndex[cbLessKindItem - 1] == (tagKindList.size() - 1)) { + int i = cbLessKindItem - 1; + for (; i > 0; i--) { + if ((cbIndex[i - 1] + 1) != cbIndex[i]) { + int cbNewIndex = cbIndex[i - 1]; + for (int j = (i - 1); j < cbLessKindItem; j++) { + cbIndex[j] = cbNewIndex + j - i + 2; + } + break; + } + } + if (i == 0) break; + } else { + cbIndex[cbLessKindItem - 1]++; + } + + } while (true); + //Global.logger.info("count:" + count); + } + + if (tagAnalyseItemList.size() > 0) { + break; + } + } + while (false); + + if (tagAnalyseItemList.size() > 0) { + return true; + } + return false; + } +} diff --git a/game_mj_fulushou/src/test/java/game_mj_fulushou/Main.java b/game_mj_fulushou/src/test/java/game_mj_fulushou/Main.java new file mode 100644 index 0000000..3ff39ef --- /dev/null +++ b/game_mj_fulushou/src/test/java/game_mj_fulushou/Main.java @@ -0,0 +1,9 @@ +package game_mj_fulushou; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_gejiu/config/game-config.xml b/game_mj_gejiu/config/game-config.xml new file mode 100644 index 0000000..3e6f73d --- /dev/null +++ b/game_mj_gejiu/config/game-config.xml @@ -0,0 +1,11 @@ + + + + + 127.0.0.1 + 0.0.0.0 + 8333 + 8333 + 33 + true + \ No newline at end of file diff --git a/game_mj_gejiu/config/log4j.properties b/game_mj_gejiu/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_gejiu/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_gejiu/config/taurus-core.xml b/game_mj_gejiu/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_mj_gejiu/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_gejiu/config/taurus-permanent.xml b/game_mj_gejiu/config/taurus-permanent.xml new file mode 100644 index 0000000..4fcbd92 --- /dev/null +++ b/game_mj_gejiu/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_gejiu/pom.xml b/game_mj_gejiu/pom.xml new file mode 100644 index 0000000..d3e2324 --- /dev/null +++ b/game_mj_gejiu/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_gejiu + 1.0.0 + jar + + game_mj_gejiu + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_gejiu + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_gejiu/src/main/java/extend/mj/CardNiao.java b/game_mj_gejiu/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..12b4af9 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/CardNiao.java @@ -0,0 +1,22 @@ +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 seat = 0; + public int score = 0; + + + public ITObject toMP(){ + ITObject obj = TObject.newInstance(); + obj.putInt("card", card); + obj.putInt("score", score); + obj.putInt("playerId", playerId); + obj.putInt("seat", seat); + return obj; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/Config.java b/game_mj_gejiu/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..ecf64a8 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/Config.java @@ -0,0 +1,136 @@ +package extend.mj; + +public class Config { + //400 东风 403南风 406西风 409北风 412红中 415发财 418白板 + public static final int DONGFENG = 400; + public static final int NANFENG = 403; + public static final int XIFENG = 406; + public static final int BEIFENG = 409; + public static final int HONGZHONG = 412; + public static final int FACAI = 415; + public static final int BAIBAN = 418; + + public static final String ROOM_CONFIG_DIANPAO = "dianpao"; //接炮胡 + public static final String ROOM_CONFIG_HUNYISE = "hunyise"; //混一色 + public static final String ROOM_CONFIG_QINGYISE = "qingyise"; //清一色 + public static final String ROOM_CONFIG_PENGPENGHU = "pengpenghu"; //碰碰胡 + public static final String ROOM_CONFIG_QIDUI = "qidui"; //七小对 + public static final String ROOM_CONFIG_HAOHUA_QIDUI = "haohua_qidui"; //豪华七小对 + public static final String ROOM_CONFIG_HAOHUA2_QIDUI = "haohua2_qidui"; //双豪华七小对 + public static final String ROOM_CONFIG_HAOHUA3_QIDUI = "haohua3_qidui"; //三豪华七小对 + public static final String ROOM_CONFIG_GANGSHANGKAIHUA_2bei = "gangshangkaihua"; //杠上开花2倍 + public static final String ROOM_CONFIG_GANGSHANGPAO_2bei = "gangshangpao_2bei"; //杠上炮2倍 + public static final String ROOM_CONFIG_SHISHANGYAO = "shishanyao"; //十三幺 + public static final String ROOM_CONFIG_TIANDIHU = "tiandihu"; //天地胡 + public static final String ROOM_CONFIG_SHIBALUOHAN = "shibaluohan"; //十八罗汉 + public static final String ROOM_CONFIG_XIAOSHANYUAN = "xiaoshanyuan"; //小三元 + public static final String ROOM_CONFIG_XIAOSIXI = "xiaosixi"; //小四喜 + public static final String ROOM_CONFIG_DASHANYUAN = "dashanyuan"; //大三元 + public static final String ROOM_CONFIG_DASIXI = "dasixi"; //大四喜 + public static final String ROOM_CONFIG_LOUHU = "louhu"; //漏胡 + public static final String ROOM_CONFIG_YAO_JIU = "yao_jiu"; //混幺九 + public static final String ROOM_CONFIG_QING_YAO_JIU = "qing_yao_jiu"; //清幺九 + public static final String ROOM_CONFIG_QUAN_FENG = "quan_feng"; //全风 + public static final String ROOM_CONFIG_QUAN_FENG_SCORE = "quan_qiu_ren"; //全求人 + public static final String ROOM_CONFIG_ZIYISE = "ziyise"; //字一色 + public static final String ROOM_CONFIG_HAI_DI_NAO_YUE = "haidinaoyue"; //海底捞月 + + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian"; + + + //------------------配置----------------------------------- + public static final String ROOM_CONFIG_WANFA = "wanfa";//玩法 + public static final String ROOM_CONFIG_QIDUI_JIA_FAN = "qiduijiafan"; //七对加番 + + public static final String ROOM_CONFIG_SHOUDAILONGJIAFAN = "shoudailongjiafan"; //手逮龙加番 + public static final String ROOM_CONFIG_LOUDILONGJIAFAN = "loudilongjiafan"; //落地龙 + public static final String ROOM_CONFIG_BUNENGCHI = "bunengchi"; //不能吃 + + + public static final String ROOM_CONFIG_HZ_HU = "hz_hu"; + public static final String ROOM_CONFIG_GENGZHUAN = "geng_zhuan"; + public static final String ROOM_CONFIG_LIAN_ZHUANG = "lian_zhuang"; + public static final String ROOM_CONFIG_10_BEI_FENGDING = "fengding"; //封顶十倍 + public static final String ROOM_CONFIG_MENG_QING = "men_qing"; //门清 + //public static final String ROOM_CONFIG_JIHU_SHI_PINGHU = "ji hu shi ping hu"; //没有鸡胡,统一叫平胡 + + + public static final String SETTLE_ZIMO = "zimo"; + public static final String SETTLE_AN_KONG = "an_kong"; + public static final String SETTLE_MING_KONG = "ming_kong"; + + public static final int MING_GANG_SCORE = 1; + public static final int BU_GANG_SCORE = 1; + public static final int AN_GANG_SCORE = 2; + + + + /** + * + */ + 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_OPENKONG = "824"; + + public static final String GAME_EVT_GANGZI = "837"; + public static final String GAME_EVT_BUGANG = "838"; + + public static final String GAME_EVT_DOGANG = "839"; + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXActionEvent.java b/game_mj_gejiu/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..42c5690 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXActionEvent.java @@ -0,0 +1,22 @@ +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_DOGANG = "do_gang"; + + 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_PIAO_NIAO = "piao_niao"; + + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXGameController.java b/game_mj_gejiu/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..d17dc39 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXGameController.java @@ -0,0 +1,326 @@ +package extend.mj; + +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; + +import java.util.Collections; +import java.util.Map.Entry; + +/** + * + * + * + * EXGameController.java + */ +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.weight+" 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); + } + + @ActionKey(Config.GAME_EVT_DOGANG) + public void RouterGangCard(Session sender,ITObject params,int gid,Player owner) { + Global.logger.info("GAME_EVT_DOGANG:"+params); + owner.stateMachine.execute(EXActionEvent.EVENT_DOGANG, 0, params); + } + + public void changeActiveSeat(EXRoom owner,int activeSeat) { + owner.activeSeat = activeSeat; + TObject 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); + if (player.getRoom().isLaizi(discard)) + { + response.putBoolean("is_cheng", true); + player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + else { + response.putBoolean("is_cheng", false); + 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; + + + if(Global.loggerDebug) { + Global.logger.info(player + " outcard["+discard+"]"); + } + if (player.getRoom().isLaizi(discard)) + { + player.chengList.add(discard); + Util.removeCard(player.cardInhand, discard, 1); + } + else { + player.outcardList.add(discard); + + Util.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + } + + + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){ + 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); + } + EXRoom room = player.getRoom(); + + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type)); + } + room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast); + ((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.cardInhand = owner.card.deal(); + Collections.sort(player.cardInhand); + if(Global.loggerDebug) { + Global.logger.info(player + " cardlist:" + player.cardInhand); + } + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + param.putInt("laiziCard", owner.card.laiziCard); + param.putInt("laiziCard2", owner.card.laiziCard2); + param.putInt("laiziCardBefore", owner.card.laiziCardBefore); + param.putInt("laiziCard2Before", owner.card.laiziCard2Before); + 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(); + 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 sendGangZiEvent(EXRoom room){ + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer owner = (EXPlayer)entry.getValue(); + owner.getRoom().currenDiscardSeat = owner.seat; + ITObject param = new TObject(); + param.putInt("gangnum", room.gangnum); + param.putInt("gangzi1", room.gangzi1); + param.putInt("gangzi2", room.gangzi2); + owner.sendEvent(Config.GAME_EVT_GANGZI, param); + } + } + + public void kaiGangEvent(EXPlayer owner){ + owner.getRoom().currenDiscardSeat = owner.seat; + EXRoom room = owner.getRoom(); + ITArray cardInHand = TArray.newInstance(); + cardInHand.addInt(room.gangzi1); + cardInHand.addInt(room.gangzi2); + ITObject param = new TObject(); + param.putInt("seat",owner.seat); + param.putTArray("info", cardInHand); + owner.sendEvent(Config.GAME_EVT_BUGANG, param); + } + + public void winEvent(EXPlayer owner,int from_seat,int win_card) { + 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("win_card", win_card); + param.putInt("from_seat", from_seat); + ITArray array = CardUtil.toMPData_WinMap(owner.winMap); + if (array != null) { + param.putTArray("win_list", array); + } + if(Global.loggerDebug) { + Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]"); + } + 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(); + + param.putTArray("niao", array); + param.putInt("start_seat", seat); + + ((EXPlayBack)room.playBackData).addNiaoCommand(owner.seat, param); + } + + + private ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + 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(); + mp.putTArray("niao", niao); + ITArray infoList = new TArray(); + for (Entry 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); + Global.logger.info("getRoomResultData:" + player.playerid +"hu_score:"+player.hu_score); + param.putInt("hu_score", player.score.round_log.get(EXScore.WIN)); + int gs = player.score.round_log.get(EXScore.KONG) + player.score.round_log.get(EXScore.AN_KONG); + param.putInt("gang_score", gs); + param.putInt("geng_zhuan", player.score.round_log.get(EXScore.GENG_ZHUAN)); + param.putInt("ma_geng_gong", player.score.round_log.get(EXScore.MA_GENG_GONG)); + param.putInt("zhong_jiang", player.score.round_log.get(EXScore.ZHONG_JIANG)); + + param.putInt("repeat_win", 0); + + + player.hp_info(param); + 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); + } + param.putInt("ming_gang_num", player.ming_gang_num); + param.putInt("an_gang_num", player.an_gang_num); + param.putInt("dian_gang_num", player.dian_gang_num); + param.putInt("cheng_num", player.cheng_num); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + 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); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.playBackData.addResult(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXMainServer.java b/game_mj_gejiu/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..17569b3 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXMainServer.java @@ -0,0 +1,91 @@ +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.*; +import extend.mj.player.state.*; +import extend.mj.room.state.EXRoomDealState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.room.state.EXRoomStartGameState; + +/** + * + * + * EXMainServer.java + */ +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(EXPlayerKongDrawState.class, new EXPlayerKongDrawState()); + Global.registerState(EXPlayerChengDrawState.class, new EXPlayerChengDrawState()); + + 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(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + Global.registerState(PRChowState.class, new PRChowState()); + + Global.registerState(PROtherKongState.class, new PROtherKongState()); + Global.registerState(PROtherWinState.class, new PROtherWinState()); + Global.registerState(PRPongKongWinState.class, new PRPongKongWinState()); + 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(PROtherGongSelfWinState.class, new PROtherGongSelfWinState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXPlayBack.java b/game_mj_gejiu/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..d29006c --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXPlayBack.java @@ -0,0 +1,74 @@ +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()); + info.putInt("laiziCard", room.card.laiziCard); + info.putInt("laiziCard2", room.card.laiziCard2); + info.putInt("laiziCardBefore", room.card.laiziCardBefore); + info.putInt("laiziCard2Before", room.card.laiziCard2Before); + } + + 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); + 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){ + 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); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + + public void addMaiNiaoCommand(int seat,ITObject param){ + addCommand("Mai_Niao",seat,param); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXPlayer.java b/game_mj_gejiu/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..777c1f4 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXPlayer.java @@ -0,0 +1,203 @@ +package extend.mj; + +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; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + * + * + * 2017��8��30�� + * EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + + // ������ + public List outcardList; + + public List outputCardList;//打出过的牌,包括被吃碰杠 + + public boolean istangzihu = false;//是否是塘子胡 + + public ITArray opCard; + + public List pongGroup; + public List kongGroup; + public List selfKongGroup; + public List opCardList; + + public int drawCard = 0; + public int winCard = 0; + + public TipManager tipMgr; + + public SettleLog settleLog; + + public boolean autoOutCard = false; + /** + * ©�� + */ + public boolean louhu = false; + + /** + * ǿ�Ƽ����� + */ + public boolean forceCheckWin = false; + /** + * 0 С�� 1 ���ܺ� + */ + public int winType = 0; + + /** + * 0 无 1 胡 2 输 + */ + public int last_winer = 0; + + public List notPongKongList = new ArrayList<>(); + public List notPongList = new ArrayList<>(); + public List chengList = new ArrayList<>(); + + public int repeat_win; + + public Map winMap; + + + public int hu_score; + + public int di_score; + + + public int ming_gang_num = 0; + public int an_gang_num = 0; + public int dian_gang_num = 0; + public int cheng_num = 0; + public boolean is_cheng = false; + + public boolean tinghu10bei = false; + + public boolean gangshangpao = false; + + + public int liangang = 0; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outputCardList = new ArrayList<>(); + pongGroup = new ArrayList<>(); + kongGroup = new ArrayList<>(); + selfKongGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + + opCard = new TArray(); + + tipMgr = new TipManager(this); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_ZIMO, 0); + settleLog.put(Config.SETTLE_AN_KONG, 0); + settleLog.put(Config.SETTLE_MING_KONG, 0); + + repeat_win = -1; + hu_score = 0; + di_score = 0; + + ming_gang_num = 0; + an_gang_num = 0; + dian_gang_num = 0; + + last_winer = 0; + + tinghu10bei = false; + gangshangpao = false; + } + + 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); + ITArray chengList = Util.toTArray(this.chengList); + playerData.putTArray("cheng_list", chengList); + playerData.putInt("card_count", cardInhand.size()); + playerData.putInt("score", score.total_score); + 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) + { + List tempOpCard = new ArrayList<>(); + for(int i = 0; i < opcard.opcard.length; i++) + { + if (opcard.opcard[i] > 0) + { + tempOpCard.add(opcard.opcard[i]); + } + } + opcardParam.putTArray("opcard", Util.toTArray(tempOpCard)); + } + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + + return playerData; + } + + public void clear() { + super.clear(); + this.cardInhand.clear(); + this.notPongKongList.clear(); + this.notPongList.clear(); + this.winer = 0; + this.louhu = false; + this.outcardList.clear(); + this.outputCardList.clear(); + this.drawCard = 0; + this.kongGroup.clear(); + this.pongGroup.clear(); + this.selfKongGroup.clear(); + this.opCardList.clear(); + this.score.resetRound(); + this.winMap = null; + this.hu_score = 0; + this.istangzihu = false; + this.di_score = 0; + this.ming_gang_num = 0; + this.an_gang_num = 0; + this.dian_gang_num = 0; + this.tinghu10bei = false; + this.cheng_num = 0; + this.chengList.clear(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXRoom.java b/game_mj_gejiu/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..194ac32 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,578 @@ +package extend.mj; + +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.player.state.EXPlayerDisCardTipState; +import extend.mj.tip.Action; +import extend.mj.tip.TipManager; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winCount = 0; + public boolean liuju = false; + public boolean last_liuju = false; + + public boolean activeHaidi = false; + public int haidiCard; + + public OpenKong activeKong = null; + + public int adminSeat = 0; + public int lastWinPlayerId = 0; + public boolean isGengZhuang = false; + public int first_zhuang_card = 0; + public int geng_zhuan_num = 0; + public int gent_zhuan_nextSeat = 0; + + public int gangnum = 0; + public int gangzi1 = 0; + public int gangzi2 = 0; + /* + * 上一次庄家座位号 + */ + public int lastBankerSeat = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + + if (!this.config.containsKey(Config.ROOM_CONFIG_DIANPAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HUNYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HUNYISE, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QINGYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QINGYISE, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_PENGPENGHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_PENGPENGHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHISHANGYAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHISHANGYAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_TIANDIHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_TIANDIHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHIBALUOHAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_LOUHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LOUHU, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU, false); + + if (!this.config.containsKey(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GENGZHUAN, false); + } + + + if (!this.config.containsKey(Config.ROOM_CONFIG_LIAN_ZHUANG)) { + this.config.putBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG, false); + } + + + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN, false); + } + + + ////幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_YAO_JIU, false); + } + + //清幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_QING_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QING_YAO_JIU, false); + } + + + //全风 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG, false); + } + + + + //全求人 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE, false); + } + + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZIYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZIYISE, false); + } + + //封顶十倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_FENGDING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_FENGDING, false); + } + + //海底捞月 + //自动胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE, false); + } + + //门清 + if (!this.config.containsKey(Config.ROOM_CONFIG_MENG_QING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, false); + } + + //杠上炮2倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei, false); + } + + this.isEntrust=true; + this.adminSeat = 0; + this.lastWinPlayerId =0; + + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + + this.lastBankerSeat = 0; + this.last_liuju = false; + + //初始化房间的特殊参数 + WinCardType.InitRoomSpecialConfig(this); + } + + public boolean isLiuJu() + { + + if (card.cardList.size() == 0) + { + return true; + } + + + return false; + } + + public void endGameByLiuJu() + { + liuju = true; + clear_repeatwin(); + + endGame(); + } + + public void endGame() + { + last_liuju = liuju; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer != 1) + { + player.last_winer = 0; + player.repeat_win = -1; + } + else + { + player.last_winer = 1; + } + } + super.endGame(); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + + checkAction(); + } + + public boolean isLaizi(int card) { + return this.card.isLaizi(card); + } + + public boolean isFanPai(int card) { + return this.card.isFanPai(card); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + + } + + /** + * 获取房间信息 + * + * @return + */ + public ITObject getRoomInfo() { + ITObject data = super.getRoomInfo(); + if (data != null) + { + data.putInt("laiziCard", this.card.laiziCard); + data.putInt("laiziCard2", this.card.laiziCard2); + data.putInt("laiziCardBefore", this.card.laiziCardBefore); + data.putInt("laiziCard2Before", this.card.laiziCard2Before); + } + + return data; + } + + 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); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN); + if(type == EXScore.WIN) { + if (zhuangxian) { + if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) { + score += 1; + } + } + } + + Global.logger.info("destPlayer:"+destPlayer+"type:"+destPlayer.score.round_log.get(type)+"|"+score); + 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 addMaGengGongScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.MA_GENG_GONG); + } + + public void addAllMaGengGongScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addMaGengGongScore(destPlayer, fromPlayer, score); + } + } + + public int GetGongScore(EXPlayer destPlayer) + { + return destPlayer.score.round_log.get(EXScore.KONG); + } + + public void addAllScore(EXPlayer destPlayer, int socre, int type) { + Global.logger.info("add score:"+socre+"type:"+type); + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + this.addScore(destPlayer, fromPlayer, socre, type); + } + } + + + + public void handle_repeatwin(EXPlayer owner) + { + if (owner.last_winer == 1) + { + owner.repeat_win += 1; + } + else + { + owner.repeat_win += 1; + } + } + + public void clear_repeatwin() + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.repeat_win = -1; + player.last_winer = 0; + } + } + + + + + + public void winCallback(EXPlayer owner, int card) { + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + } else { + } + + this.endGame(); + } + } + + public void winCallback_qiangkong(EXPlayer owner, int card) { + + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + } else { + } + + this.endGame(); + } + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void clear() { + super.clear(); + + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + + this.isGengZhuang = false; + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + this.lastBankerSeat = 0; + } + + public void handle10BeiBuJiFen(EXPlayer winner) + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (winner.playerid != player.playerid) + { + if (IsTingHu10Bei(player)) + { + player.tinghu10bei = true; + } + } + } + } + + public boolean IsTingHu10Bei(EXPlayer player) + { + List tempList = new ArrayList(); + + for (int index = 1; index <= 9; index++) { + tempList.add(100 + index); + tempList.add(200 + index); + tempList.add(300 + index); + } + + + //400 东风 403南风 406西风 409北风 412红中 415发财 418白板 + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + + + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, card, this.card.laiziCard, this.card.laiziCard2, false, false); + if (win.checkWin(map, player, this, true)) { + int dahu_score = 0; + int cheng_score = 1; + for (Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + + if (cardType.IsDaHu()) + { + dahu_score += cardType.score*WinCardType.DA_HU_BEI_SCORE; + } + else + { + cheng_score *= cardType.score; + } + } + + } + } + + return false; + } + + public EXPlayer get12ZhangLuoDi(EXPlayer owner) + { + if (owner.opCardList.size() >= 4) + { + OpCard opCard = owner.opCardList.get(owner.opCardList.size() - 1); + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.KONG) + { + if (opCard.card_seat > 0) + { + EXPlayer badPlayer = (EXPlayer)this.playerMapBySeat.get(opCard.card_seat); + if (badPlayer != null) + { + return badPlayer; + } + } + } + } + return null; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/EXScore.java b/game_mj_gejiu/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..8c04b2d --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,28 @@ +package extend.mj; + +import com.game.data.Score; + + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int KONG = 2; + public static final int AN_KONG = 4; + public static final int GENG_ZHUAN = 5; + public static final int MA_GENG_GONG = 6; + //public static final int MAI_NIAO = 7; + public static final int ZHONG_JIANG = 8; + + public EXScore(EXPlayer owner){ + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(KONG, 0); + this.round_log.put(AN_KONG,0); + this.round_log.put(GENG_ZHUAN, 0); + this.round_log.put(MA_GENG_GONG, 0); + this.round_log.put(ZHONG_JIANG, 0); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/OpCard.java b/game_mj_gejiu/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..58028b5 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,49 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; + +public class OpCard { + public int type; + public int card; + public int card_seat; + public int card2; + public int card3; + public int card4; + public int[] opcard; + + public ITArray opCard; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card4 = 0; + this.card_seat = 0; + } + + public OpCard(int type, int card, int card_seat, int[] card_list) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card_seat = card_seat; + this.opcard = card_list; + } + + public OpCard(int type, int card, int card2, int card3) { + this.type = type; + this.card = card; + this.card2 = card2; + this.card3 = card3; + this.card_seat = 0; + } + + public OpCard(int type, int card, int card_seat) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card_seat = card_seat; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/OpenKong.java b/game_mj_gejiu/src/main/java/extend/mj/OpenKong.java new file mode 100644 index 0000000..9d5f614 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/OpenKong.java @@ -0,0 +1,52 @@ +package extend.mj; + +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.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.List; + +public class OpenKong { + + public int diceNum1; + public int diceNum2; + + /** + * + */ + public int fromSeat; + + + public int kongSeat; + public List drawList; + + public boolean haidi; + + public int tipActionSeat = -1; + + public OpenKong() { + drawList = new ArrayList(); + + diceNum1 = CardUtil.randomDiceNum(); + diceNum2 = CardUtil.randomDiceNum(); + } + + public ITObject getTObject() { + ITObject data = TObject.newInstance(); + data.putInt("diceNum1", diceNum1); + data.putInt("diceNum2", diceNum2); + + data.putInt("from_seat", fromSeat); + data.putInt("kong_seat", kongSeat); + + ITArray cardList = TArray.newInstance(); + for (int card : drawList) { + cardList.addInt(card); + } + data.putTArray("cardList", cardList); + return data; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_gejiu/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..abd9a44 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,118 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.*; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.tip.IRuleBase; + +/** + * ����������� + * + * + * + * 2017��9��19�� PlayerRuleManager.java + */ +public class PlayerRuleManager { + + /** + * ����ץ�� + */ + public static final int DRAW_RULE = 1; + + /** + * ���˳��� + */ + public static final int OTHER_DISCARD_RULE = 2; + /** + * ���ܺ����� + */ + public static final int KONG_HU_RULE = 3; + /** + * �������Ժ���ƹ��� + */ + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public static final int KONG_DRAW_RULE = 8; + public static final int CHENG_DRAW_RULE = 9; + public static final int CHENG_RULE = 10; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.KONG_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.CHENG_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerKongWinState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerDrawTipState) Global.getState(EXPlayerDrawTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List kongDrawRuleList = new ArrayList(); + kongDrawRuleList.add(new RuleSelfKong()); + kongDrawRuleList.add(new RulePongKong()); + kongDrawRuleList.add(new RuleOtherKongSelfWin()); + ruleMap.put(PlayerRuleManager.KONG_DRAW_RULE, kongDrawRuleList); + + List chengDrawRuleList = new ArrayList(); + chengDrawRuleList.add(new RuleSelfKong()); + chengDrawRuleList.add(new RulePongKong()); + chengDrawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.CHENG_DRAW_RULE, chengDrawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleChow()); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RulePongKongWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + cpDiscardRuleList.add(new RulePongKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/RoomCard.java b/game_mj_gejiu/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..87f00b2 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,1669 @@ +package extend.mj; + +import com.game.Global; +import com.game.Util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + public Integer laiziCard; + public Integer laiziCard2; + public Integer laiziCardBefore; + public Integer laiziCard2Before; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + subCardList = new ArrayList<>(); + this.room = table; + laiziCard = 0; + laiziCard2 = 0; + laiziCardBefore = 0; + laiziCard2Before = 0; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + + //this.cardList.add(106); + //this.cardList.add(109); + //this.cardList.add(107); + //this.cardList.add(108); + //this.cardList.add(109); + this.setbugang(); + } + + private void setbugang(){ + // 136 - 13- 14 = 109 + this.room.gangnum = 0; + this.room.gangzi1 = this.cardList.get(this.cardList.size()-1); + this.room.gangzi2 = this.cardList.get(this.cardList.size()-2); + } + private void initCard() { + + boolean notiao = false; + boolean notuo = false; + + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + this.cardList.add(300 + index); + } + } + + + for(int i =0;i<4;++i) { + this.cardList.add(Config.DONGFENG); + this.cardList.add(Config.NANFENG); + this.cardList.add(Config.XIFENG); + this.cardList.add(Config.BEIFENG); + this.cardList.add(Config.HONGZHONG); + this.cardList.add(Config.FACAI); + this.cardList.add(Config.BAIBAN); + } + + + //0 无鬼 1白板做鬼 2翻鬼(随机一个牌做鬼) 3翻双鬼 + int laizi = 0; + + + + deal_select++; + //deal_select = 9; + + deal_index = 1; + deal_tempCards_1 = 0; + deal_tempCards_2 = 0; + deal_tempCards_3 = 0; + deal_tempCards_4 = 0; + } + + private int GetBeforeCard(int card) + { + if (card < 400) + { + if (card % 100 >= 2 && card % 100 <= 9) + { + return card - 1; + } + else if (card % 100 == 1) + { + return card / 100 + 9; + } + else + { + return card; + } + } + else + { + if (card == Config.DONGFENG) + { + return Config.BAIBAN; + } + else if (card ==Config.NANFENG) + { + return Config.DONGFENG; + } + else if (card ==Config.XIFENG) + { + return Config.NANFENG; + } + else if (card ==Config.BEIFENG) + { + return Config.XIFENG; + } + else if (card ==Config.HONGZHONG) + { + return Config.BEIFENG; + } + else if (card ==Config.FACAI) + { + return Config.HONGZHONG; + } + else if (card ==Config.BAIBAN) + { + return Config.FACAI; + } + else + { + return Config.BAIBAN; + } + } + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public boolean isLaizi(int card) + { + if (laiziCard != 0 && card == laiziCard) + { + return true; + } + else if (laiziCard2 != 0 && card == laiziCard2) + { + return true; + } + + return false; + } + + public boolean isFanPai(int card) + { + if (laiziCardBefore != 0 && card == laiziCardBefore) + { + return true; + } + else if (laiziCard2Before != 0 && card == laiziCard2Before) + { + return true; + } + + return false; + } + + public void reInitCards(List cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } + +// public int pop() { +// +// if (this.cardList.size() == 0) { +// this.room.bankerSeat = this.room.activeSeat; +//// this.room.roundSettle(); +// } +// +// int card = this.cardList.remove(0); +// +// return card; +// +// } + + public int pop() { + Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public int deal_select = 0; + public List deal() { + if (deal_select >= 0) + //if (deal_select == 0) + { + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + if (deal_select == 1) + { + return deal_shishanyao(); + } + else if (deal_select == 2) + { + return deal_qixiaodui(); + } + else if (deal_select == 3) + { + return deal_shibaluohan(); + } + else if (deal_select == 4) + { + return deal_hunyise(); + } + else if (deal_select == 5) + { + return deal_xiaoshanyuan(); + } + else if (deal_select == 6) + { + return deal_dashanyuan(); + } + else if (deal_select == 7) + { + return deal_xiaosixi(); + } + else if (deal_select == 8) + { + return deal_dasixi(); + } + else if (deal_select == 9) + { + return deal_qiangganghu(); + } + else if (deal_select == 10) + { + return deal_gangshangkaihua(); + } + else if(deal_select==11){ + return deal_ceshigang(); + }else if(deal_select==12){ + return deal_pengpenghu(); + }else if(deal_select==13){ + return deal_yibangao(); + }else{ + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + } + + public int deal_index = 1; + public int deal_tempCards_1 = 0; + public int deal_tempCards_2 = 0; + public int deal_tempCards_3 = 0; + public int deal_tempCards_4 = 0; + public List deal_shishanyao() { + List dealCards = new ArrayList(); + + dealCards.add(101); + dealCards.add(104); + dealCards.add(107); + //dealCards.add(101); + + dealCards.add(201); + dealCards.add(204); + dealCards.add(207); + //dealCards.add(203); + + //dealCards.add(204); + //dealCards.add(204); + // dealCards.add(309); + //dealCards.add(309); + + dealCards.add(301); + //dealCards.add(305); + + // dealCards.add(309); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + //dealCards.add(Config.DONGFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + //dealCards.add(Config.XIFENG); + //dealCards.add(Config.XIFENG); + //dealCards.add(Config.DONGFENG); + dealCards.add(Config.FACAI); + //dealCards.add(Config.BAIBAN); + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + + deal_index++; + + return dealCards; + } + + public List deal_qixiaodui() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(105); + dealCards.add(105); + dealCards.add(105); + dealCards.add(105); + dealCards.add(107); + deal_tempCards_1 = 107; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(301); + dealCards.add(301); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + dealCards.add(205); + dealCards.add(206); + deal_tempCards_2 = 206; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(305); + deal_tempCards_4 = 305; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_pengpenghu() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_1 = 105; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_4 = Config.HONGZHONG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index >= 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_yibangao() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(104); + dealCards.add(107); + dealCards.add(201); + dealCards.add(204); + dealCards.add(207); + dealCards.add(302); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = 104; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = Config.BEIFENG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_shibaluohan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_1 = 105; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = Config.BEIFENG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_hunyise() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_3 = Config.HONGZHONG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_4 = Config.HONGZHONG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index >= 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_xiaoshanyuan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.NANFENG); + deal_tempCards_3 = Config.NANFENG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(301); + dealCards.add(301); + dealCards.add(303); + dealCards.add(304); + deal_tempCards_4 = 304; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_dashanyuan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.NANFENG); + deal_tempCards_3 = Config.NANFENG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(305); + deal_tempCards_4 = 305; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_xiaosixi() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(109); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(109); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(109); + dealCards.add(Config.BEIFENG); + deal_tempCards_1 = Config.BEIFENG; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_4 = 105; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_dasixi() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(104); + dealCards.add(103); + dealCards.add(102); + dealCards.add(105); + deal_tempCards_1 = 109; + } + else if (deal_index == 2) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_4 = 105; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_qiangganghu() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(106); + dealCards.add(106); + dealCards.add(106); + dealCards.add(107); + dealCards.add(107); + dealCards.add(107); + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + dealCards.add(109); + deal_tempCards_1 = 101; + } + else if (deal_index == 1) + { + + dealCards.add(102); + dealCards.add(103); + + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + dealCards.add(305); + deal_tempCards_3 = 301; + } + else if (deal_index == 4) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = 303; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_gangshangkaihua() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(106); + dealCards.add(106); + dealCards.add(106); + dealCards.add(107); + dealCards.add(107); + dealCards.add(107); + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + dealCards.add(109); + deal_tempCards_1 = 102; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 109; + } + else if (deal_index == 3) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + dealCards.add(305); + deal_tempCards_3 = 109; + } + else if (deal_index == 4) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = 109; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + + public List deal_ceshigang() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(105); + dealCards.add(106); + dealCards.add(103); + dealCards.add(102); + dealCards.add(107); + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + dealCards.add(109); + dealCards.add(109); + //dealCards.add(102); + //dealCards.add(103); + deal_tempCards_1 = 101; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(105); + dealCards.add(106); + dealCards.add(107); + dealCards.add(108); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 109; + } + else if (deal_index == 3) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + dealCards.add(305); + deal_tempCards_3 = 109; + } + else if (deal_index == 4) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = 109; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/RuleWeight.java b/game_mj_gejiu/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..200ac8b --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,20 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 0b00001; + public final static int PONG = 0b00010; + public final static int KONG = 0b00100; + public final static int SELFKONG = 0b00100; + public final static int WIN = 0b01000; + public final static int SELF_WIN = 0b10000; + + public final static int GROUP_CHOW = 1; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_PONG_KONG = 5; + public final static int TYPE_WIN = 6; +} + diff --git a/game_mj_gejiu/src/main/java/extend/mj/SettleLog.java b/game_mj_gejiu/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/TagAnalyseItem.java b/game_mj_gejiu/src/main/java/extend/mj/TagAnalyseItem.java new file mode 100644 index 0000000..dc9f797 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/TagAnalyseItem.java @@ -0,0 +1,20 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagAnalyseItem { + //分析子项 + public int cbCardEye; //牌眼麻将 + public int cbCardEye2; //牌眼麻将 + public List cbOpCard; //组合类型 + public boolean isPengPengHu; + + public TagAnalyseItem() + { + this.cbCardEye = 0; + this.cbCardEye2 = 0; + this.cbOpCard = new ArrayList(); + this.isPengPengHu = false; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/TagKindItem.java b/game_mj_gejiu/src/main/java/extend/mj/TagKindItem.java new file mode 100644 index 0000000..fe18c06 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/TagKindItem.java @@ -0,0 +1,17 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagKindItem { + public int type; //组合类型 + public int card; //中心麻将 + public Integer[] cbCardList; //麻将索引 + + public TagKindItem() + { + type = 0; + card = 0; + cbCardList = new Integer[3]; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/WinCardType.java b/game_mj_gejiu/src/main/java/extend/mj/WinCardType.java new file mode 100644 index 0000000..4997ba3 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/WinCardType.java @@ -0,0 +1,189 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class WinCardType { + public static final int DIANPAO = 1; //点炮类型 + + public static final int PINGHU = 2; //平胡类型 + + public static final int QIXIAODUI = 3; //七小对 + + public static final int YIBANGAO = 4; //一般高 手牌里每种花色的牌最多只有3张,必须全部是147、258、369组合,且组合一致,加上5张不重复的字牌 + + public static final int QIXING = 5; //七星 手牌里每种花色的牌最多只有3张,且必须是147、258、369组合,加上7张不重复的字牌 + + public static final int LONGJIABEI = 6; //龙夹背 手中的牌有7个对子,且有1组4张相同的牌 + + public static final int QINGDADUI = 7; //清大对 手牌只有刻子、杠和1对将,且全都是同一种花色。 + + public static final int QIXINGYIBANGAO = 8; //七星一般高 手牌里每种花色的牌最多只有3张,必须全部是147、258、369组合,且组合一致,加上7张不重复的字牌。 + + public static final int SHUANGLONGJIABEI = 9; //双龙夹背 手中的牌有7个对子,且有2组4张相同的牌 + + public static final int SANLONGJIABEI = 10; //三龙夹背 手中的牌有7个对子,日有3组4张相同的牌。 + + public static final int SHILAOTOU = 11; //十老头 从第一张打到桌面上的牌算起,不间断打出10张字牌即可胡牌 + + public static final int TANGZISHISANYAO = 12; //塘子十三ㄠ 从第一张牌达到桌面上的牌算起,不间断打出十三张1、9、字牌即可直接胡牌 + + public static final int TANGZIQIXIAODUI = 13; //塘子小七对 从第一张牌达到桌面上的牌算起,不间断打出十三张牌,打出的牌可以组成6个对子+单张,即可直接胡牌 + + public static final int DADUIZI = 14; //大对子 手牌只有刻子、杠和1对将。 + public static final int LANPAI = 15; //烂牌 手牌只有刻子、杠和1对将。 + + public static final int YI_TIAO_LONG = 16; //一条龙 手中的牌有同一花色的1-9,目胡牌时1-9必须组成123、456、789的顺子。1-9的顺子必须在手中,吃的牌不算 + + public static final int LOU_DI_LONG = 17;//落地龙 + + public static final int HUN_YI_SE = 18; //混一色 + + public static final int ZHUANGJIA = 19; //庄家 庄家胡牌时,庄家额外加番。闲家胡牌时,庄家额外付番 + + public static final int QINGYISE = 20; //清一色 + public static final int ZI_YI_SE = 21; //字一色 手牌只有字牌 + + public static final int QIANG_GANG_HU = 22; //抢杠胡 抢杠 抢杠胡时,被抢杠玩家额外付番 + + public static final int GANGSHANGHUA = 23; //杠上开花 + + public static final int GANGSHANGPAO = 24; //杠上炮 + + public static final int SHI_SHAN_YAO = 103; //十三幺 + + + public static final int SHUANGGANGHUA = 25; //双杠花 + + public static final int SHUANGGANGPAO = 26; //双杠上炮 + + + public static final int SANGANGHUA = 27; //三杠花 + + public static final int SANGANGPAO = 28; //三杠上炮 + + public static final int SIGANGHUA = 29; //四杠花 + + public static final int SIGANGPAO = 30; //四杠上炮 + + public static final int TANGZIQIXING = 31; //塘子七星 + + public static final int TANGZIYIBANGAO = 32;//塘子一般高 + + public static final int TANGZIQIXINGYIBANGAO = 33;//塘子七星一般高 + + public static final int TANGZILANPAI = 34;//塘子烂牌 + + public static final int XIANJIA = 35;//闲家 + + public static final int TANGZIHU = 36; + + + + public static final int YING_MO = 50; // 自摸胡牌 + public static final int YING_MO_SCORE = 2; //硬摸 自摸胡牌,每个玩家出4分 + public static int BASE_HU_SCORE = 2; //基础分数 + public static int DA_HU_BEI_SCORE = 2; //大胡倍数 + public static int PINGHU_SCORE = 2; //平胡类型 + public static int QIXIAODUI_SOCRE = 4; //七小对 倍数 + public static int YIBANGAO_SCORE = 4; //一般高 + public static int QIXING_SCORE = 4; //七星 + public static int LONGJIABEI_SCORE = 8; //龙夹背 + + public static int QINGDADUI_SCORE = 8; //清大对 + + public static int QIXINGYIBANGAO_SCORE= 8;//七星一般高 + + public static int SHUANGLONGJIABEI_SCORE = 16;//双龙夹背 + + public static int SANLONGJIABEI_SCORE = 32;//三龙夹背 + + public static int SHILAOTOU_SCORE = 1;//十老头 + + public static int TANGZISHISANYAO_SCORE = 1;//塘子十三ㄠ; + + public static int DADUIZI_SCORE = 2;//大对子 + + public static int LANPAI_SCORE = 2;//烂牌 + + public static int YI_TIAO_LONG_SCORE = 2;//一条龙 + public static int LUO_DI_LONG_SCORE = 2;//一条龙 + + public static int HUN_YI_SE_SCORE = 2; //混一色 + + public static int ZHUANGJIA_SCORE = 2;//庄家分 + + public static int QINGYISE_SCORE = 4; //清一色 + public static int ZI_YI_SE_SCORE = 8; //字一色 + public static int GANGSHANGHUA_SCORE = 10; //杠上开花 + + public static int GANGSHANGPAO_SOCRE = 10; //杠上炮 + public static int QIANG_GANG_HU_SOCRE = 10; //抢杠胡 + + public static int SHUANGGANGHUA_SCORE = 20;//双杠花 + public static int SHUANGGANGPAO_SOCRE = 20; //双杠上炮 + + public static int SANGANGHUA_SCORE = 30;//三杠花 + public static int SANGANGPAO_SOCRE = 30; //三杠上炮 + + public static int SIGANGHUA_SCORE = 40;//四杠花 + public static int SIGANGPAO_SCORE = 40; //四杠上炮 + + public static int TANGZIQIXING_SCORE = 1;// + public static int TANGZIYIBANGAO_SCORE = 1;// + public static int TANGZIQIXINGYIBANGAO_SCORE = 1;// + public static int TANGZILANPAI_SCORE = 1;// + + public static int TANGZIQIXIAODUI_SCORE = 1; + + + public int type; + public int value; + + public int score; + + public boolean is_dahu; + + public String desc; + + public ITArray opcard; + + //初始化房间的特殊参数 + static public void InitRoomSpecialConfig(EXRoom room) + { + + } + + public WinCardType(int type, int value, int score, boolean is_dahu, String desc) { + this.type = type; + this.value = value; + this.score = score; + this.is_dahu = is_dahu; + this.desc = desc; + } + + public boolean IsDaHu() + { + return is_dahu; + } + + public ITObject toTObject() { + return toTObject(false); + } + + public ITObject toTObject(boolean is_opcard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", type); + obj.putInt("value", value); + obj.putInt("score", score); + if(is_opcard&&opcard!=null) { + obj.putTArray("opcard", opcard); + } + return obj; + } + + public String toString() { + return "type:" + type + " value:" + value + " score:" + score + " desc:" + desc; + } +} \ No newline at end of file diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleChow.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleChow.java new file mode 100644 index 0000000..e207cc0 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleChow.java @@ -0,0 +1,93 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRChowState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.List; + +/** + * ����״̬ + * + * + * 2017��11��2�� + * PRChowRule.java + */ +public class RuleChow implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (player.lastSeat != room.activeSeat) { + return false; + } + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + if(room.activeKong.kongSeat == player.seat)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + boolean result = false; + List cardInhand = player.cardInhand; + if (Util.checkCard(eventCard - 1, cardInhand) && Util.checkCard(eventCard - 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 1); + opcard.addInt(eventCard - 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard - 1, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard - 1); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard + 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard + 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRChowState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleHaidi.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleHaidi.java new file mode 100644 index 0000000..036ab06 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleHaidi.java @@ -0,0 +1,37 @@ +package extend.mj.player.rule; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���׼�� + * + * + * 2017��11��8�� + * RuleHaidi.java + */ +public class RuleHaidi implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (room.card.getCount() == 1) { + player.tipMgr.clean(); + room.tipMap.clear(); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..637feda --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,68 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + + Global.logger.info("RuleOtherKong"); + + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + if (player.getRoom().isLaizi(eventCard)) + { + return false; + } + + if (player.getRoom().isFanPai(eventCard)) + { + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + else { + if (Util.checkCard(eventCard, player.cardInhand, 3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java new file mode 100644 index 0000000..d09b4da --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java @@ -0,0 +1,120 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherGongSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleOtherKongSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + + HashMap map = new HashMap(); + Global.logger.info("liangang:"+player.liangang); + if (player.liangang==1){ + WinCard.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.GANGSHANGHUA_SCORE, false, "杠上开花"); + } + if (player.liangang==2){ + WinCard.putWinCardType(map, WinCardType.SHUANGGANGHUA, 1,WinCardType.SHUANGGANGHUA_SCORE, false, "双杠花"); + } + if (player.liangang==3){ + WinCard.putWinCardType(map, WinCardType.SANGANGHUA, 1,WinCardType.SANGANGHUA_SCORE, false, "三杠花"); + } + if (player.liangang==4){ + WinCard.putWinCardType(map, WinCardType.SIGANGHUA, 1,WinCardType.SIGANGHUA_SCORE, false, "四杠花"); + } + + + + boolean flag = false; + + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + player.tipMgr.addTip(tip); + + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, false); + + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + + if (player.seat==room.bankerSeat){ + WinCard.putWinCardType(map, WinCardType.ZHUANGJIA, 1,WinCardType.BASE_HU_SCORE, false, "庄家"); + }else{ + WinCard.putWinCardType(map, WinCardType.XIANJIA, 1,WinCardType.BASE_HU_SCORE, false, "闲家"); + } + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.winType = 1; + player.winCard = tip.card; + player.drawCard = tip.card; + + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + Global.logger.info("OtherKong player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score ); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + if (cardType.type != WinCardType.DIANPAO && cardType.type != WinCardType.PINGHU) + { + jia_score += cardType.score; + } + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score; + + player.stateMachine.changeState(Global.getState(PROtherGongSelfWinState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..8a1225f --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,119 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.HashMap; +import java.util.Map; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + + + if(room.activeSeat == player.seat)return false; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + + if (player.cardInhand.size() == 1 && room.isLaizi(player.cardInhand.get(0))) + { + return false; + } + + if (room.isLaizi(room.activeCard)) + { + return false; + } + + int activieCard = room.activeCard; + int laizi = 0; + HashMap map = new HashMap(); + if (activePlayer.gangshangpao && room.config.getBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.GANGSHANGPAO_SOCRE*2, false, "杠上炮"); + } + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, false)) { + Global.logger.info("other win"+map); + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + tip.winMap = map; + player.tipMgr.addTip(tip); + + if (player.seat==room.bankerSeat){ + WinCard.putWinCardType(map, WinCardType.ZHUANGJIA, 1,WinCardType.BASE_HU_SCORE, false, "庄家"); + }else{ + WinCard.putWinCardType(map, WinCardType.XIANJIA, 1,WinCardType.BASE_HU_SCORE, false, "闲家"); + } + + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + player.getRoom().activeCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + int laizi = 0; + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + + player.hu_score = 4; + player.di_score = 2; + HashMap map = new HashMap(); + + Global.logger.info("other win player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score ); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + jia_score += cardType.score; + } + } + + Global.logger.info("other win player:" + player.playerid +"jia_score:"+jia_score+"dahu_score:"+dahu_score); + + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score; + Global.logger.info("other win player:" + player.playerid +"hu_score:"+player.hu_score); + + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..da68511 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,61 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + + if (player.getRoom().isFanPai(eventCard)) + { + return false; + } + + if (player.getRoom().isLaizi(eventCard)) + { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + player.stateMachine.changeState(Global.getState(PRPongState.class)); + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..629da0b --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,67 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + Global.logger.info("RulePongKong"); + boolean result = false; + if (player.isEntrust()) { + return false; + } + for (int card : player.cardInhand) { + result = conditionCard(player, card) || result; + } + return result; + + } + + public boolean conditionCard(EXPlayer player, int card) { + + for (int[] cardGroup : player.pongGroup) { + if (card == cardGroup[0]) { + if (player.getRoom().isLaizi(card)) + { + continue; + } + if (player.getRoom().isFanPai(card)) + { + continue; + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_PONG_KONG); + player.tipMgr.addTip(tip); + + return true; + } + } + return false; + + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKongWin.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKongWin.java new file mode 100644 index 0000000..0ab6102 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RulePongKongWin.java @@ -0,0 +1,153 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRPongKongWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RulePongKongWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + + if(room.activeSeat == player.seat)return false; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + + int activieCard = room.activeCard; + int laizi = 0; + HashMap map = new HashMap(); + + WinCard.putWinCardType(map, WinCardType.QIANG_GANG_HU, 1, WinCardType.QIANG_GANG_HU_SOCRE, false, "抢杠胡"); + + + boolean flag = false; + if (WinCard.IsDiaoYu(player, player.cardInhand, player.drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false)) + { + WinCard win = new WinCard(player.cardInhand, room.activeCard, 0, 0, false, false); + if (win.checkWin(map, player, room, false)) { + flag = true; + } + } + else { + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, false)) { + flag = true; + } + } + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + tip.winMap = map; + player.tipMgr.addTip(tip); + + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + Util.removeCard(tempCardList, player.drawCard, 1); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + int cheng_num = 0; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer)entry.getValue(); + cheng_num += tempPlayer.cheng_num; + } + if (player.is_cheng) + { + + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + + + } + else { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + + if (player.seat==room.bankerSeat){ + WinCard.putWinCardType(map, WinCardType.ZHUANGJIA, 1,WinCardType.BASE_HU_SCORE, false, "庄家"); + }else{ + WinCard.putWinCardType(map, WinCardType.XIANJIA, 1,WinCardType.BASE_HU_SCORE, false, "闲家"); + } + + + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + EXRoom room = player.getRoom(); + room.activeCard = tip.card; + player.winMap = tip.winMap; + + Global.logger.info("PongKong player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score ); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + jia_score += cardType.score; + } + + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score;; + + player.stateMachine.changeState(Global.getState(PRPongKongWinState.class)); + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..91d73d2 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,75 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.Map; +import java.util.Map.Entry; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + + Global.logger.info("RuleSelfKong"); + if (player.isEntrust()) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + + int num = entry.getValue(); + if (player.getRoom().isLaizi(card)) + { + continue; + } + if (player.getRoom().isFanPai(card)) + { + if (num >= 3) + { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + + } + } + else { + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + + } + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..4fa5180 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,106 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + int laizi = 0; + HashMap map = new HashMap(); + + boolean flag = false; + + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + tip.self = true; + player.tipMgr.addTip(tip); + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + int cheng_num = 0; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer)entry.getValue(); + cheng_num += tempPlayer.cheng_num; + } + + //WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "自摸"); + if (player.seat==room.bankerSeat){ + WinCard.putWinCardType(map, WinCardType.ZHUANGJIA, 1,WinCardType.BASE_HU_SCORE, false, "庄家"); + }else{ + WinCard.putWinCardType(map, WinCardType.XIANJIA, 1,WinCardType.BASE_HU_SCORE, false, "闲家"); + } + return true; + } + player.is_cheng = false; + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.winCard = tip.card; + player.drawCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + Global.logger.info("self win player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + jia_score += cardType.score; + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + Global.logger.info("self win player:" + player.playerid +"jia_score:"+jia_score+"dahu_score:"+dahu_score ); + player.hu_score += jia_score; + Global.logger.info("self win player:" + player.playerid +"hu_score:"+player.hu_score); + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRChowState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRChowState.java new file mode 100644 index 0000000..c270316 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRChowState.java @@ -0,0 +1,60 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRChowState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + ITArray opcard = owner.opCard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + int card= room.activeCard; + Util.removeCard(owner.cardInhand, chowcard1, 1); + Util.removeCard(owner.cardInhand, chowcard2, 1); + room.activeCard = 0; + + + OpCard opc = new OpCard(RuleWeight.TYPE_CHOW, card); + opc.opCard = new TArray(); + opc.opCard.addInt(chowcard1); + opc.opCard.addInt(chowcard2); + owner.opCardList.add(opc); + + + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_CHOW, fromseat,opc.opCard); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java new file mode 100644 index 0000000..69bc37d --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java @@ -0,0 +1,141 @@ +package extend.mj.player.rulestate; + + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PROtherGongSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + Util.removeCard(owner.cardInhand, owner.winCard, 1); + if (owner.opCardList.size() > 0) + { + OpCard opCard = owner.opCardList.get(owner.opCardList.size()-1); + if (opCard.type == RuleWeight.TYPE_KONG && opCard.card_seat > 0) + { + + + owner.room.activeSeat = opCard.card_seat; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + + + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + int score = 1; + for (Map.Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i1){ + room.addAllScore(owner,score,EXScore.WIN); + } + + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + // room.niao_dianPao_quanbao(owner ,owner.winCard, qg_type, true); + + room.endGame(); + return; + } + else if (opCard.type == RuleWeight.TYPE_SELF_KONG || (opCard.type == RuleWeight.TYPE_KONG && opCard.card_seat == 0)) + { + + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + int score = 1; + for (Map.Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i1){ + room.addAllScore(owner,score,EXScore.WIN); + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + + room.endGame(); + return; + } + } + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..bc2e0f1 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,117 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; + +import java.util.Collections; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PROtherKongState.java + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size()-1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + room.addScore(owner,activePlayer, Config.MING_GANG_SCORE,EXScore.KONG); + owner.ming_gang_num++; + //activePlayer.dian_gang_num++; + owner.liangang++; + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(owner.getRoom().activeCard); + + int card = room.activeCard; + + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + + owner.kongGroup.add(kongGroup); + owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, activePlayer.seat, kongGroup)); + Util.removeCard(owner.cardInhand, card, 4); + owner.gangshangpao = true; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + + + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + //杠之后选择两个牌,未能下一轮 + + room.gangnum = room.gangnum+1; + EXMainServer.gameCtr.kaiGangEvent(owner); + + //toNextState(owner); + + + } + + @Override + public void toNextState(EXPlayer owner) { + + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + + case EXActionEvent.EVENT_DOGANG: + ITObject netParam2 = (ITObject) param; + int discard2 = netParam2.getInt("card"); + EXRoom room = owner.getRoom(); + RoomCard cards = room.card; + Global.logger.info("cards list1:"+cards.cardList); + Collections.reverse(cards.cardList); + Util.removeCard(cards.cardList, discard2, 1); + Global.logger.info("cards list2:"+cards.cardList); + cards.cardList.add(discard2); + Collections.reverse(cards.cardList); + + room.gangzi1 = cards.cardList.get(cards.cardList.size()-1); + room.gangzi2 = cards.cardList.get(cards.cardList.size()-2); + + EXMainServer.gameCtr.sendGangZiEvent(room); + //} + Global.logger.info("cards list3:"+cards.cardList); + Global.logger.info("PROtherKongState:"+discard2); + toNextState(owner); + break; + default: + break; + } + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..9d2c411 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,50 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.winer = 1; + int score = 1; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + for (Map.Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i1){ + room.addScore(owner,activePlayer,score,EXScore.WIN); + } + + + activePlayer.winer = 2; + activePlayer.last_winer = 2; + + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + room.bankerSeat = owner.seat; + room.winCount += 1; + + owner.winCard = room.activeCard; + + room.winCallback( owner ,owner.winCard); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongState.java new file mode 100644 index 0000000..3a97622 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongState.java @@ -0,0 +1,100 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; +import extend.mj.uitl.CardUtil; + +import java.util.Collections; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRPongKongState.java + */ +public class PRPongKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + Global.logger.info("PRPongKongState opcard:"); + Global.logger.info(opCard); + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + CardUtil.removeGroup(owner.pongGroup, card); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_PONG, card)); + + int[] kong = new int[4]; + kong[0] = card; + kong[1] = card; + kong[2] = card; + kong[3] = card; + owner.kongGroup.add(kong); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_KONG, card)); + owner.gangshangpao = true; + + + + room.activeCard = card; + + room.gangnum = room.gangnum+1; + EXMainServer.gameCtr.kaiGangEvent(owner); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opCard); + + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.settleLog.add(Config.SETTLE_MING_KONG); + owner.getRoom().addAllScore(owner, Config.BU_GANG_SCORE, EXScore.KONG); + owner.getRoom().activeCard = 0; + owner.ming_gang_num++; + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + + case EXActionEvent.EVENT_DOGANG: + ITObject netParam2 = (ITObject) param; + int discard2 = netParam2.getInt("card"); + EXRoom room = owner.getRoom(); + RoomCard cards = room.card; + Global.logger.info("cards list1:"+cards.cardList); + Collections.reverse(cards.cardList); + Util.removeCard(cards.cardList, discard2, 1); + Global.logger.info("cards list2:"+cards.cardList); + cards.cardList.add(discard2); + Collections.reverse(cards.cardList); + + room.gangzi1 = cards.cardList.get(cards.cardList.size()-1); + room.gangzi2 = cards.cardList.get(cards.cardList.size()-2); + + EXMainServer.gameCtr.sendGangZiEvent(room); + //} + Global.logger.info("cards list3:"+cards.cardList); + Global.logger.info("PROtherKongState:"+discard2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(discard2); + + toNextState(owner); + break; + default: + break; + } + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java new file mode 100644 index 0000000..df6dbd4 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java @@ -0,0 +1,40 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; +import extend.mj.*; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PRPongKongWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.winer = 1; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.winer = 2; + activePlayer.last_winer = 2; + + + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + room.bankerSeat = owner.seat; + room.winCount += 1; + + owner.winCard = room.activeCard; + + room.winCallback_qiangkong( owner ,owner.winCard); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..6c31a40 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,61 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PRPongState.java + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..5b4b507 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,104 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; + +import java.util.Collections; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRSelfKongState.java + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 4); + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + owner.selfKongGroup.add(kongGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card, owner.seat, kongGroup)); + owner.gangshangpao = true; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + + + + EXMainServer.gameCtr.kaiGangEvent(owner); + + Global.logger.info("angang:"+Config.AN_GANG_SCORE); + Global.logger.info("angang:"+EXScore.AN_KONG); + room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.AN_KONG); + + room.gangnum = room.gangnum+1; + owner.liangang++; + owner.an_gang_num++; + + owner.settleLog.add(Config.SETTLE_AN_KONG); + + + + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + // owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + + case EXActionEvent.EVENT_DOGANG: + ITObject netParam2 = (ITObject) param; + int discard2 = netParam2.getInt("card"); + EXRoom room = owner.getRoom(); + RoomCard cards = room.card; + Global.logger.info("cards list1:"+cards.cardList); + Collections.reverse(cards.cardList); + Util.removeCard(cards.cardList, discard2, 1); + Global.logger.info("cards list2:"+cards.cardList); + cards.cardList.add(discard2); + Collections.reverse(cards.cardList); + + room.gangzi1 = cards.cardList.get(cards.cardList.size()-1); + room.gangzi2 = cards.cardList.get(cards.cardList.size()-2); + + EXMainServer.gameCtr.sendGangZiEvent(room); + //} + Global.logger.info("cards list3:"+cards.cardList); + Global.logger.info("PRSelfKongState:"+discard2); + + + toNextState(owner); + break; + default: + break; + } + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..179ec58 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,84 @@ +package extend.mj.player.rulestate; + + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map.Entry; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + + Util.removeCard(owner.cardInhand, owner.winCard, 1); + + + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + int score = 1; + for (Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i1){ + room.addAllScore(owner,score,EXScore.WIN); + } + + + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.endGame(); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java new file mode 100644 index 0000000..19e76bf --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java @@ -0,0 +1,105 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerChengDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + int laizi = 0; + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.pop(); + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHENG_DRAW_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..349c126 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,57 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * ��ҳ�����ʾ״̬ + * + * + * 2017��8��30�� + * EXPlayerDisCardTipState.java + */ +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + /* + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + */ + owner.tipMgr.choicAction(id); + }else if(cmd.equals(EXActionEvent.EVENT_DOGANG)){ + ITObject netParam2 = (ITObject) param; + int discard2 = netParam2.getInt("card"); + Global.logger.info("EVENT_DOGANG dis tip:"+discard2); + } + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..39d1eed --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,224 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +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.*; +import extend.mj.player.rule.RuleSelfWin; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; + +/** + * �ȴ���ҳ���״̬ + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + Global.logger.info("jefe discard:"+discard); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + //ITObject reconParam = new TObject(); + //owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + //return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.outputCardList.add(discard); + Global.logger.info("logger jefe"+owner.outputCardList); + if (owner.outputCardList.size()==13||owner.outputCardList.size()==10){ + HashMap map = new HashMap(); + // WinCard win = new WinCard(owner.cardInhand, discard, owner.getRoom().card.laiziCard, owner.getRoom().card.laiziCard2, false, true); + //if (win.checkWin(map, owner, owner.getRoom(), true)) { + int tangzihu = WinCard.isTangZiHu(owner.outputCardList); + Global.logger.info("tangzihu jefe"+tangzihu); + if (tangzihu>0){ + ITArray opcard = TArray.newInstance(); + opcard.addInt(discard); + Tip tip = new Tip(discard,opcard, RuleWeight.SELF_WIN,new RuleSelfWin(), RuleWeight.TYPE_WIN); + tip.winMap = map; + tip.self = true; + owner.tipMgr.addTip(tip); + owner.winMap = tip.winMap; + if (tangzihu==1){ + WinCard.putWinCardType(map, WinCardType.SHILAOTOU, 1,WinCardType.SHILAOTOU_SCORE, false, "十老头"); + }else if(tangzihu==2){ + WinCard.putWinCardType(map, WinCardType.TANGZISHISANYAO, 1,WinCardType.TANGZISHISANYAO_SCORE, false, "塘子十三ㄠ"); + }else if(tangzihu==3){ + WinCard.putWinCardType(map, WinCardType.TANGZIQIXIAODUI, 1,WinCardType.TANGZIQIXIAODUI_SCORE, false, "塘子小七对"); + }else if(tangzihu==4){ + //塘子胡七星 + WinCard.putWinCardType(map, WinCardType.TANGZIQIXING, 1,WinCardType.TANGZIQIXING_SCORE, false, "塘子胡七星"); + }else if(tangzihu==5){ + WinCard.putWinCardType(map, WinCardType.TANGZIYIBANGAO, 1,WinCardType.TANGZIYIBANGAO_SCORE, false, "塘子一般高"); + }else if(tangzihu==6){ + WinCard.putWinCardType(map, WinCardType.TANGZIQIXINGYIBANGAO, 1,WinCardType.TANGZIQIXINGYIBANGAO_SCORE, false, "塘子七星一般高"); + }else if(tangzihu==7){ + WinCard.putWinCardType(map, WinCardType.TANGZILANPAI, 1,WinCardType.TANGZILANPAI_SCORE, false, "塘子烂牌"); + } + owner.istangzihu = true; + if (owner.seat==owner.getRoom().bankerSeat){ + WinCard.putWinCardType(map, WinCardType.ZHUANGJIA, 1,WinCardType.BASE_HU_SCORE, false, "庄家"); + }else{ + WinCard.putWinCardType(map, WinCardType.XIANJIA, 1,WinCardType.BASE_HU_SCORE, false, "闲家"); + } + owner.winCard = discard; + owner.drawCard = discard; + owner.cardInhand = owner.outputCardList; + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.BASE_HU_SCORE, false, "塘子胡"); + + owner.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + break; + } + + //} + } + + owner.notPongList.clear(); + owner.louhu = false; + owner.liangang=0; + + EXMainServer.gameCtr.outCard(owner, discard); + + + owner.gangshangpao = false; + if (owner.getRoom().isLaizi(discard)) + { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + owner.cheng_num++; + owner.is_cheng = true; + owner.stateMachine.changeState(Global.getState(EXPlayerChengDrawState.class)); + } + } + else { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + break; + case ActionEvent.EVENT_TIMER_AUTO: + owner.louhu = false; + discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + + owner.notPongList.clear(); + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + + if (owner.getRoom().isLaizi(discard)) + { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + owner.cheng_num++; + owner.is_cheng = true; + owner.stateMachine.changeState(Global.getState(EXPlayerChengDrawState.class)); + } + } + else { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + + default: + break; + } + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..12ef6fe --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,200 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + boolean laizi = false; + + if(owner.seat == room.adminSeat) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + if (owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else if (owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else { + owner.drawCard = room.card.pop(); + } + } + } + + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + + private boolean IsGoodCard(EXPlayer player, int drawCard, boolean laizi) { + if (player.getRoom().isLaizi(drawCard)) + { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + for (int[] cardGroup : player.pongGroup) { + if (drawCard == cardGroup[0]) { + return true; + } + } + + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, drawCard, player.getRoom().card.laiziCard, player.getRoom().card.laiziCard2, laizi, true); + if (win.checkWin(map, player, player.getRoom(), true)) { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } + + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..a731cc4 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,69 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.taurus.core.entity.ITObject; + +import com.taurus.core.entity.TObject; +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ���ץ����ʾ״̬ + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ; + if(Global.gameId == 1 && win && id == 0)return; + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + /* + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + */ + owner.tipMgr.doAction(id); + } + else if (cmd.equals(EXActionEvent.EVENT_DISCARD)) + { + boolean flag = false; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + flag = true; + } + else { + flag = false; + } + } + if (flag) + { + int id = 0; + owner.tipMgr.doAction(id); + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, param); + } + else { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + } + } + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java new file mode 100644 index 0000000..eba39d9 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java @@ -0,0 +1,105 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerKongDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + Global.logger.info("EXPlayerKongDrawState"); + ITObject config = room.config; + + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + int laizi = 0; + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.pop(); + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.KONG_DRAW_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..fae3c10 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,58 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +import java.util.Map; + +/** + * ���������ʾ�ȴ� + * + * + * 2017��8��30�� + * EXPlayerKongWinState.java + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } + else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Map.Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d29abf3 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,49 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * Ʊ����ʾ״̬ + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + owner.startActionTimer(); + }else{ + _action(owner, 0, 0); + } + } + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + } + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..304de57 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,49 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * �����ʾ������� + * + * + * 2017��8��30�� + * EXPlayerTipState.java + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tipEvent(owner); + } + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if(cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..dff6a34 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,24 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * ������ҵȴ��������ǹ�ܺ� + * + * + * 2017��8��30�� + * EXPlayerWaitKongWinState.java + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..89d33db --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,47 @@ +package extend.mj.player.state; + + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * ��ҵȴ�״̬ + * + * + * 2017��8��30�� + * EXPlayerWaitState.java + */ +public class EXPlayerWaitState extends StateBase { + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + Global.logger.info("EXPlayerWaitState cmd:"+cmd); + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.forceCheckWin = true; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + owner.forceCheckWin = false; + break; + case EXActionEvent.EVENT_DOGANG: + ITObject netParam2 = (ITObject) param; + int discard2 = netParam2.getInt("card"); + Global.logger.info("EVENT_DOGANG:"+discard2); + break; + default: + break; + } + + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..be87d03 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,48 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayBack; +import extend.mj.EXRoom; + +/** + * ���䷢��״̬ + * + * + * 2017��8��30�� + * EXRoomDealState.java + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } +// owner.isplaying = true; +// owner.round += 1; + + + this.toNextState(owner); + + + } + + @Override + public void toNextState(EXRoom owner) { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + EXMainServer.gameCtr.sendGangZiEvent(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..47fbd44 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,42 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ����ת����λ + * + * + * 2017��8��30�� + * EXRoomSetpState.java + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + this.toNextState(owner); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..1272100 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,33 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * ���俪ʼ״̬ + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/tip/Action.java b/game_mj_gejiu/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..454d9ca --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + + */ +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_gejiu/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..79f1ab8 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * ����������� + * + * + * 2017��8��30�� + * RuleBase.java + */ +public interface IRuleBase { + + /** + * ������� + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * ִ�иù��� + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/tip/Tip.java b/game_mj_gejiu/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..d69849a --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,47 @@ +package extend.mj.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.mj.WinCardType; + +import java.util.Map; + +/** + * tip������ + * + * + * + * 2017��8��30�� Tip.java + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int winType; + public int type; + public int group_type; + public boolean self; + public Map winMap; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + this.self = false; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/tip/TipManager.java b/game_mj_gejiu/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..9f40ee2 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,142 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; + +/** + * + * + * + * 2017��9��18�� TipManager.java + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + public Tip getTip(int type) + { + for (Entry entry : this.tipMap.entrySet()) + { + Tip tip = entry.getValue(); + if (tip.type == type) + { + return tip; + } + } + return null; + } + + private void checkLouhu() { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_LOUHU)) + { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + } + + public void choicAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_gejiu/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..f408b99 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,62 @@ +package extend.mj.uitl; + +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.OpCard; +import extend.mj.WinCardType; + +import java.util.Random; + +public class CardUtil { + + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + + } + } + + final static Random random = new Random(); + static { + random.setSeed(System.currentTimeMillis()); + } + static public int randomDiceNum() { + int result = random.nextInt(5); + return result + 1; + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card == opcards.get(i).card) { + opcards.remove(i); + return; + } + + } + + } + + static public ITArray toMPData_WinMap(Map map) { + return toMPData_WinMap(map,false); + } + + static public ITArray toMPData_WinMap(Map map,boolean is_opcard) { + if (map != null && map.size() > 0) { + ITArray array = TArray.newInstance(); + for (Map.Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + array.addTObject(wct.toTObject(is_opcard)); + } + return array; + } + return null; + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_gejiu/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..0f096e2 --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,1874 @@ +package extend.mj.uitl; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITObject; +import extend.mj.*; + +import java.util.*; + +public class WinCard { + + public List cardList; + public int laizi_count; + public int laizi1_count; + public int laizi2_count; + public int laizi1 = 0; + public int laizi2 = 0; + public Map cbCardMap; + + public WinCard(List cardInhand, int addCard, int laizi1, int laizi2, boolean islaizi, boolean selfCard) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + if (selfCard) + { + this.cardList.add(addCard); + } + else { + this.cardList.add(addCard); + } + + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + //钓鱼 + static public boolean IsDiaoYu(EXPlayer player, List cardInhand, int drawCard, int laizi1, int laizi2, boolean islaizi) + { + EXRoom room = player.getRoom(); + WinCard win = new WinCard(cardInhand, laizi1, laizi2, islaizi); + if (drawCard > 0 && drawCard != laizi1 && drawCard != laizi2 && win.laizi_count == 1) + { + ArrayList cardList = new ArrayList(); + cardList.addAll(cardInhand); + + Util.removeCard(cardList, drawCard, 1); + for (int index = 1; index <= 9; index++) { + for(int index2 = 1; index2 <= 3; index2++) + { + int card = index2 * 100 + index; + if (card == laizi1 || card == laizi2) + continue; + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(cardList); + tempCardList.add(card); + WinCard temp = new WinCard(tempCardList, laizi1, laizi2, islaizi); + HashMap map = new HashMap(); + if (!temp.checkWin(map, player, room, true)) { + return false; + } + } + } + + return true; + } + return false; + } + + public WinCard(List cardInhand, int laizi1, int laizi2, boolean islaizi) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + public boolean checkWin(Map map, EXPlayer player, EXRoom room, boolean zimo) { + if (this.cardList.size() == 0) { + return false; + } + + Global.logger.info(this.cardList); + Global.logger.info(this.laizi_count); + long startTime = System.currentTimeMillis(); + int[] intListCard = WinSplitCard.SwitchToCardData(this.cardList); + List tagAnalyseItemList = new ArrayList(); + Global.logger.info(map); + Global.logger.info(room.config); + Global.logger.info(player.outcardList); + Global.logger.info("checkwin"); + if (!player.opCardList.isEmpty()){ + for (int i=0;i typeList = new ArrayList(); + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + int type = cardType.type; + Global.logger.info("type:"+cardType.type+"isdahu:"+cardType.IsDaHu()+"score:"+cardType.score); + if (cardType.IsDaHu()) + { + typeList.add(type); + } + } + + if (maxType > 0) + { + for(int i = 0; i < typeList.size(); i++) + { + int type = typeList.get(i); + if (type != maxType) + { + map.remove(type); + } + } + } + + if (zimo) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.BASE_HU_SCORE, false, "自摸"); + }else if(tangzihu>0){ + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.BASE_HU_SCORE, false, "塘子胡"); + }else{ + WinCard.putWinCardType(map, WinCardType.DIANPAO, 1,WinCardType.BASE_HU_SCORE, false, "点炮"); + } + + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info player:" + player.playerid + " hu:" + cardType.toString()); + } + } + + return hu; + } + + + public final static WinCardType putWinCardType(Map map, int type, int value,int score, boolean isDaHu, String desc) { + if (map == null) + return null; + if (isDaHu) + { + map.remove(WinCardType.DIANPAO); + map.remove(WinCardType.PINGHU); + } + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score, isDaHu, desc); + map.put(type, wct); + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } + } + + + + //七小对 + public int IsQiXiaoDui(Map tempCardList, List opCards) + { + //组合判断 + if (opCards.size() != 0) return -1; + + //麻将判断 + int mCountTmp = 0; + int mDaDuiNum = 0; + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if ((num!=0) && (num!=2) && (num!=4)) + { + return -1; + } + if (num == 2) { + mCountTmp++; + } + else if (num == 4) { + mCountTmp += 2; + mDaDuiNum++; + } + } + + if (mCountTmp == 7) + { + return mDaDuiNum; + } + + return -1; + } + + public boolean IsZiYiSe(Map tempCardList, List opCards) + { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + if (card < 400) + { + return false; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card < 400) + { + return false; + } + } + + return true; + } + + public boolean IsQingYiSe(Map tempCardList, List opCards) + { + int perColor = -1; + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + return true; + } + + public boolean IsHunYiSe(Map tempCardList, List opCards) + { + int perColor = -1; + boolean hunyise = false; + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + boolean IsShiBaLuoHan(Map tempCardList, List opCards) + { + int count = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.type == RuleWeight.TYPE_KONG || op_card.type == RuleWeight.TYPE_SELF_KONG) + { + count++; + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + //混幺九 + boolean IsHuYaoJiu(TagAnalyseItem item) { + boolean yaoKeZe = false; + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } else { + yaoKeZe = true; + } + } + } + } + + if (yaoKeZe) + { + return true; + } + + return false; + } + + //清幺九 + boolean IsQingYaoJiu(TagAnalyseItem item) { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + } + + return true; + } + + boolean IsQuanFeng(TagAnalyseItem item) { + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + return false; + } + } + } + + return true; + } + + int IsDaXiaoSanYuan(Map tempCardList, List opCards) + { + byte mKeCount = 0; + byte mDuiCount = 0; + //组合判断 + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.HONGZHONG + || op_card.card == Config.FACAI + || op_card.card == Config.BAIBAN) + { + mKeCount++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + + if (card == Config.HONGZHONG + || card == Config.FACAI + || card == Config.BAIBAN) + { + if (num == 2) + { + mDuiCount++; + } + + if (num == 3) + { + mKeCount++; + } + } + } + + //大三元 + if (mKeCount ==3) + { + return 1; + } + + //小三元 + if ((mKeCount ==2) && (mDuiCount ==1)) + { + return 2; + } + + return 0; + } + + boolean QuanQiuRen(Map tempCardList, List opCards) + { + if (opCards.size() != 4) + { + return false; + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num != 0 && num != 2) + { + return false; + } + } + return false; + } + + static boolean ThirteenOne(Map tempCardList, List opCards) + { + if (opCards.size() > 0) + { + return false; + } + + List tempList = new ArrayList(); + tempList.add(101); + tempList.add(109); + tempList.add(201); + tempList.add(209); + tempList.add(301); + tempList.add(309); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + + int jiangnum = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + if (tempCardList.getOrDefault(card, 0) != 1) + { + if (tempCardList.getOrDefault(card, 0) == 2) + { + jiangnum++; + if (jiangnum >= 2) + { + return false; + } + } + else { + return false; + } + } + } + + if (jiangnum == 1) + { + return true; + } + return false; + } + + int IsDaXiaoSiXi(Map tempCardList, List opCards) + { + int keCount = 0; + int duiCount = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + keCount++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == Config.DONGFENG + || card == Config.NANFENG + || card == Config.XIFENG + || card == Config.BEIFENG) + { + if (num == 3) + { + keCount++; + } + + if (num == 2) + { + duiCount++; + } + } + } + + //大四喜 + if (keCount >= 4) + { + return 1; + } + //小四喜 + else if (keCount >= 3 && duiCount >= 1) + { + return 2; + } + + return 0; + } + + boolean DaSiXi(Map tempCardList, List opCards) + { + int count = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + count++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 3) + { + if (card == Config.DONGFENG + || card == Config.NANFENG + || card == Config.XIFENG + || card == Config.BEIFENG) + { + count++; + } + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + /* + 一条龙判断 + */ + int isShouDaiLong(Map tempCardList, List opCards) + { + + return 0; + } + + //落地龙判断 + int isLuoDiLong(Map tempCardList, List opCards) + { + return 0; + } + + int isTangZiHu(Map tempCardList, List opCards) + { + + return 0; + } + + boolean AnalyseChiHuCard(Map map, List opCards, ITObject config) + { + Map tempCardList = new HashMap(); + tempCardList.putAll(this.cbCardMap); + + List tempCardListEx = new ArrayList(); + for (int index = 1; index <= 9; index++) { + + tempCardListEx.add(100 + index); + + tempCardListEx.add(200 + index); + tempCardListEx.add(300 + index); + } + + + tempCardListEx.add(Config.DONGFENG); + tempCardListEx.add(Config.NANFENG); + tempCardListEx.add(Config.XIFENG); + tempCardListEx.add(Config.BEIFENG); + tempCardListEx.add(Config.HONGZHONG); + tempCardListEx.add(Config.FACAI); + tempCardListEx.add(Config.BAIBAN); + + + if (AnalyseChiHuCardEx(map, tempCardList, 0, opCards, config)) + { + return true; + } + + return false; + } + + boolean AnalyseChiHuCardEx(Map map, Map cardListParam, int curCard, List opCards, ITObject config) + { + Map tempCardList = new HashMap<>(); + tempCardList.putAll(cardListParam); + + if (curCard > 0) + { + tempCardList.put(curCard, tempCardList.getOrDefault(curCard, 0)+1); + } + + List clearCardList = new ArrayList<>(); + for (Map.Entry entry : tempCardList.entrySet()) { + if (entry.getValue() == 0) + { + clearCardList.add(entry.getKey()); + } + } + + for(int i = 0; i < clearCardList.size(); i++) + { + tempCardList.remove(clearCardList.get(i)); + } + + //变量定义 + List tagAnalyseItemList = new ArrayList(); + List wChiHuKind = new ArrayList(); + + //分析麻将 + AnalyseCard(tempCardList, opCards, tagAnalyseItemList); + + //胡牌分析 + if (tagAnalyseItemList.size() > 0) + { + //牌型分析 + for (int i = 0;i < tagAnalyseItemList.size();i++) + { + //变量定义 + boolean bLianCard=false,bPengCard=false,b258Card=false; + TagAnalyseItem pAnalyseItem= tagAnalyseItemList.get(i); + + //牌型分析 + for (int j = 0;j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) { + bPengCard = true; + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + bLianCard = true; + } + } + + //牌型判断 + if (bLianCard==false && bPengCard==false) + { + return false; + } + + if (bLianCard && bPengCard == false) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + } + else if (bLianCard && bPengCard) + { + + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + + } + + //特殊--碰碰胡 + if ((bLianCard==false)&&(bPengCard==true)) + { + + + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, false, "平胡"); + + + } + } + } + + //特殊胡牌 + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + int DaDuiNum = IsQiXiaoDui(tempCardList, opCards); + if (DaDuiNum >= 0) + { + wChiHuKind.add(WinCardType.QIXIAODUI); + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + if (DaDuiNum == 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + + } + } + + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + } + } + + + + //结果判断 + if (wChiHuKind.size() > 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + return true; + } + + return false; + } + + boolean AnalyseCard(Map tempCardList, List opCards, List tagAnalyseItemList) + { + //计算数目 + int cbCardCount = 0; + for (Map.Entry entry : tempCardList.entrySet()) { + cbCardCount += entry.getValue(); + } + + //效验数目 + if ((cbCardCount<2)||(cbCardCount>14)||((cbCardCount-2)%3!=0)) { + return false; + } + + //变量定义 + List tagKindList = new ArrayList(); + + //需求判断 + int cbLessKindItem=(cbCardCount-2)/3; + if (cbLessKindItem+opCards.size()!=4) + { + return false; + } + + //单吊判断 + if (cbLessKindItem==0) + { + //效验参数 + if (!((cbCardCount==2)&&(opCards.size()==4))) + { + return false; + } + + //牌眼判断 + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) + { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置结果 + for (int i = 0; i < opCards.size(); i++) + { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(src_card); + } + AnalyseItem.cbCardEye = card; + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + + return true; + } + } + + return false; + } + + //拆分分析 + if (cbCardCount>=3) + { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + //同牌判断 + if (num >= 3) + { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card; + tagKindList.add(kindItem); + } + + //连牌判断 + if (card < 400 && card % 100 <= 7 && num >0) + { + for(int i = 1; i <= num; i++) + { + if (tempCardList.getOrDefault(card + 1, 0) >= i && tempCardList.getOrDefault(card + 2, 0) >= i) + { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + } + } + } + } + + //组合分析 + if (tagKindList.size() >= cbLessKindItem) + { + //变量定义 + Integer[] cbIndex = new Integer[4]; //{0,1,2,3}; + cbIndex[0] = 0; + cbIndex[1] = 1; + cbIndex[2] = 2; + cbIndex[3] = 3; + + TagKindItem[] pKindItem = new TagKindItem[4]; + pKindItem[0] = null; + pKindItem[1] = null; + pKindItem[2] = null; + pKindItem[3] = null; + + //开始组合 + do + { + //设置变量 + Map cbCardMap_temp = new HashMap(); + cbCardMap_temp.putAll(tempCardList); + + for (int i = 0;i < cbLessKindItem; i++) { + pKindItem[i] = tagKindList.get(cbIndex[i]); + } + + //数量判断 + boolean bEnoughCard=true; + for (int i = 0; i < cbLessKindItem * 3; i++) + { + //存在判断 + int cbCardIndex = pKindItem[i/3].cbCardList[i%3]; + if (cbCardMap_temp.getOrDefault(cbCardIndex, 0) <= 0) + { + bEnoughCard=false; + break; + } + else + { + if (cbCardMap_temp.containsKey(cbCardIndex)) + { + cbCardMap_temp.put(cbCardIndex, cbCardMap_temp.get(cbCardIndex)-1); + } + } + } + + //胡牌判断 + if (bEnoughCard == true) + { + //牌眼判断 + int cbCardEye = 0; + for (Map.Entry entry : cbCardMap_temp.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) + { + cbCardEye = card; + break; + } + } + + //组合类型 + if (cbCardEye != 0) + { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置组合 + for (int i = 0; i < opCards.size(); i++) + { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(op_card); + } + + //设置牌型 + for (int i = 0; i < cbLessKindItem; i++) + { + OpCard op_card = new OpCard(pKindItem[i].type, pKindItem[i].card); + AnalyseItem.cbOpCard.add(op_card); + } + + //设置牌眼 + AnalyseItem.cbCardEye = cbCardEye; + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + } + } + + //设置索引 + if (cbIndex[cbLessKindItem-1] == (tagKindList.size()-1)) + { + int i = cbLessKindItem-1; + for (;i>0;i--) + { + if ((cbIndex[i-1]+1) != cbIndex[i]) + { + int cbNewIndex=cbIndex[i-1]; + for (int j=(i-1);j 0); + } + + public static int isTangZiHu(List list){ + if (list.size()==10){ + int lt = 0; + for (int i=0;i= 400){ + lt++; + } + } + if (lt==10){ + return 1; + } + } + if(list.size()==13){ + //判断是否满足塘子胡 + //boolean ssy =ThirteenYao(list); + boolean ssy = shiSanYao(list); + if (ssy){ + return 2; + } + // + int qxd = tzQixiaodui(list); + if (qxd==6){ + return 3; + } + //塘子胡七星 一般高 + boolean tzqxybg = tzQiXingYiBanGao(list); + if (tzqxybg){ + System.out.println("塘子胡七星一般高"); + return 6; + } + + boolean tzqx = tzQiXing(list); + if(tzqx){ + System.out.println("塘子胡七星"); + return 4; + } + boolean tzybg = tzYiBangao(list); + if (tzybg){ + System.out.println("塘子胡一般高"); + return 5; + } + boolean tzlp = tzLanPai(list); + if (tzlp){ + System.out.println("塘子胡烂牌"); + return 7; + } + + } + return 0; + } + + static boolean tzLanPai(List list){ + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + + if (wangzicard.size()>0){ + + if (wangzicard.size()==3){ + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3!=wangzicard.get(1)){ + return false; + } + } + } + if (tongzicard.size()>0){ + + if (tongzicard.size()==3){ + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3!=tongzicard.get(1)){ + return false; + } + } + } + if(tiaozicard.size()>0){ + + if (tiaozicard.size()==3){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)){ + return false; + } + } + } + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + return true; + } + + static boolean tzQiXingYiBanGao(List list){ + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>3?1:wangzicard.get(0)%100); + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.size()==3){ + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3!=wangzicard.get(1)){ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>3?1:tongzicard.get(0)%100); + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.size()==3){ + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3!=tongzicard.get(1)){ + return false; + } + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>3?1:tiaozicard.get(0)%100); + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.size()==3){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)){ + return false; + } + } + } + + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + if (uniqueList.size()>1){ + return false; + } + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + if (ziList.size()<7){ + return false; + } + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + static boolean tzYiBangao(List list){ + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>3?1:wangzicard.get(0)%100); + if (wangzicard.size()==3){ + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3!=wangzicard.get(1)&&wangzicard.get(0)+6!=wangzicard.get(1)){ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>3?1:tongzicard.get(0)%100); + if (tongzicard.size()==3){ + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3!=tongzicard.get(1)&&tongzicard.get(0)+6!=tongzicard.get(1)){ + return false; + } + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>3?1:tiaozicard.get(0)%100); + if (tiaozicard.size()==3){ + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)&&tiaozicard.get(0)+6!=tiaozicard.get(1)){ + return false; + } + } + } + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + if (uniqueList.size()>1){ + return false; + } + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + static boolean tzQiXing(List list){ + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + + //判断 147,258,369 + if (wangzicard.size()>0){ + + if (wangzicard.size()==3){ + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3!=wangzicard.get(1)){ + return false; + } + } + } + if (tongzicard.size()>0){ + + if (tongzicard.size()==3){ + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3!=tongzicard.get(1)){ + return false; + } + } + } + + if(tiaozicard.size()>0){ + + if (tiaozicard.size()==3){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3!=tiaozicard.get(1)){ + return false; + } + } + } + + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(6,list.size()); + System.out.println(ziList); + int jiangnum = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + jiangnum = Collections.frequency(ziList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + static int tzQixiaodui(List list){ + + //麻将判断 + int mCountTmp = 0; + int mDaDuiNum = 0; + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) { + mCountTmp++; + } + else if (num == 4) { + mCountTmp += 2; + } + } + if (mCountTmp == 6) + { + return mCountTmp; + } + return -1; + } + + static boolean shiSanYao(List list){ + List tempList = new ArrayList(); + int zcount = 0; + int flag = 0; + int dcount = 0; + for(int i = 0; i < list.size(); i++) + { + int card = list.get(i); + if(card>=400){ + zcount++; + }else { + dcount++; + if (card % 100 != 1 && card % 100 != 9) { + flag++; + } + } + } + if (zcount>=1&&flag==0&&dcount>=1){ + return true; + } + return false; + } + + static boolean ThirteenYao(List list){ + List tempList = new ArrayList(); + tempList.add(101); + tempList.add(109); + tempList.add(201); + tempList.add(209); + tempList.add(301); + tempList.add(309); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + + int jiangnum = 0; + int flag = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + jiangnum = Collections.frequency(list,card); + if (jiangnum!=1){ + return false; + } + + } + + if (jiangnum == 1) + { + return true; + } + return false; + } + + + public static void main(String[] args) { + List dealCards = new ArrayList<>(); +// dealCards.add(Config.DONGFENG); +// dealCards.add(Config.DONGFENG); +// dealCards.add(Config.DONGFENG); +// dealCards.add(Config.NANFENG); +// dealCards.add(Config.NANFENG); +// dealCards.add(Config.NANFENG); +// dealCards.add(Config.XIFENG); +// dealCards.add(Config.XIFENG); +// dealCards.add(Config.XIFENG); +// dealCards.add(Config.BEIFENG); + + /*dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.FACAI); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.FACAI); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(101); + dealCards.add(109); + /*dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(201); + dealCards.add(201); + dealCards.add(209); + dealCards.add(209); + dealCards.add(301); + dealCards.add(309); + dealCards.add(309);*/ + //dealCards.add(307); + //dealCards.add(307); + + dealCards.add(101); + dealCards.add(104); + dealCards.add(107); + dealCards.add(202); + dealCards.add(205); + dealCards.add(208); + dealCards.add(309); + + //dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.FACAI); + dealCards.add(Config.BAIBAN); + + int a = isTangZiHu(dealCards);//1:十老头,2:塘子十三ㄠ,3:塘子小七对 + System.out.println(a); + /* + ITObject test = new TObject(); + test.putInt("shoudailongjiafan",1);test.putBoolean("shibaluohan",false);test.putBoolean("qidui",false);test.putInt("pid",53);test.putBoolean("tiandihu",false); + test.putBoolean("pengpenghu",false);test.putBoolean("dashanyuan",false);test.putBoolean("haohua2_qidui",false);test.putBoolean("hunyise",false);test.putInt("isNonnegative",1); + test.putBoolean("quan_feng",false);test.putBoolean("gangshangpao_2bei",false);test.putBoolean("shishanyao",false);test.putInt("wanfa",0);test.putBoolean("hz_hu",false);test.putBoolean("qing_yao_jiu",false); + test.putBoolean("lian_zhuang",false);test.putBoolean("men_qing",false);test.putBoolean("ziyise",false);test.putBoolean("dianpao",false);test.putInt("qiduijiafan",1);test.putBoolean("dashanyuan",true);test.putBoolean("xiaosixi",false); + test.putBoolean("dasixi",false);test.putBoolean("quan_qiu_ren",false);test.putBoolean("quan_feng",false); + + ArrayList cardInhand = new ArrayList(); + //cardInhand.add(101); + /*cardInhand.add(102); + cardInhand.add(103); + cardInhand.add(104); + + cardInhand.add(105); + cardInhand.add(106); + cardInhand.add(107); + + cardInhand.add(107); + cardInhand.add(108); + cardInhand.add(109);*/ + //cardInhand.add(305); + //cardInhand.add(305); + //cardInhand.add(301); + //cardInhand.add(301); + //cardInhand.add(103); + //cardInhand.add(102); + /*cardInhand.add(101); + cardInhand.add(104); + cardInhand.add(107); + cardInhand.add(201); + cardInhand.add(204); + cardInhand.add(207); + cardInhand.add(302); + cardInhand.add(305); + //cardInhand.add(308); + //cardInhand.add(Config.DONGFENG); + cardInhand.add(Config.NANFENG); + cardInhand.add(Config.XIFENG); + cardInhand.add(Config.BEIFENG); + cardInhand.add(Config.HONGZHONG); + cardInhand.add(Config.FACAI); + cardInhand.add(Config.BAIBAN); + + + //System.out.println(cardInhand); + + int[] intListCard = WinSplitCard.SwitchToCardData(cardInhand); + System.out.println(intListCard); + List tagAnalyseItemList = new ArrayList(); + + Map map =new HashMap<>(); + List testlist = new ArrayList<>(); + */ + /*peng + int gangcard = Config.NANFENG; + int pengcard = Config.BAIBAN; + int [] kongGroup = new int [4]; + kongGroup[0] = gangcard; + kongGroup[1] = gangcard; + kongGroup[2] = gangcard; + kongGroup[3] = gangcard; + + int[] pengG1 = new int[4]; + pengG1[0] = pengcard; + pengG1[1] = pengcard; + pengG1[2] = pengcard; + pengG1[3] = pengcard; + + int[] pengG2 = new int[4]; + pengG2[0] = Config.FACAI; + pengG2[1] = Config.FACAI; + pengG2[2] = Config.FACAI; + pengG2[3] = Config.FACAI; + + int[] pengG3 = new int[4]; + pengG3[0] = Config.HONGZHONG; + pengG3[1] = Config.HONGZHONG; + pengG3[2] = Config.HONGZHONG; + pengG3[3] = Config.HONGZHONG; + + + OpCard test1 = new OpCard(RuleWeight.TYPE_SELF_KONG, pengcard, 1, kongGroup); + OpCard test2 = new OpCard(RuleWeight.TYPE_SELF_KONG, pengcard, 1, pengG1); + OpCard test3 = new OpCard(RuleWeight.TYPE_SELF_KONG, pengcard, 1, pengG2); + OpCard test4 = new OpCard(RuleWeight.TYPE_SELF_KONG, pengcard, 1, pengG3); + /*OpCard test2 = new OpCard(RuleWeight.TYPE_CHOW, 102); + test2.opCard = new TArray(); + test2.opCard.addInt(101); + test2.opCard.addInt(103); + + testlist.add(test1); + testlist.add(test2); + testlist.add(test3); + testlist.add(test4);*/ + + /* + boolean hu = WinSplitCard.AnalyseChiHuCard(map, test, intListCard, 0, testlist, tagAnalyseItemList); + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + System.out.println(cardType.type); + System.out.println(cardType.desc); + System.out.println(cardType.is_dahu); + System.out.println(cardType.score); + } + System.out.println(hu);*/ + + + } +} diff --git a/game_mj_gejiu/src/main/java/extend/mj/uitl/WinSplitCard.java b/game_mj_gejiu/src/main/java/extend/mj/uitl/WinSplitCard.java new file mode 100644 index 0000000..c89dcfc --- /dev/null +++ b/game_mj_gejiu/src/main/java/extend/mj/uitl/WinSplitCard.java @@ -0,0 +1,2161 @@ +package extend.mj.uitl; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; + +import java.util.*; + +public class WinSplitCard { + //获取数值 + public static int GetCardValue(int cbCardData) { return cbCardData % 100; } + //获取花色 + public static int GetCardColor(int cbCardData) { return cbCardData / 100; } + + //扑克转换 + public static int SwitchToCardData(int cbCardIndex) + { + int cbCardColor= cbCardIndex/10; + int cbCardValue= cbCardIndex%10; + if (cbCardIndex < 27) + { //9 -> 200 + 1 //10 -> 202 //11 -> 203 // 17 -> 209 // 18 -> 301 19->302 20 -> 303 26->309 + if (cbCardValue + (cbCardColor+1) >= 10) + { + return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 + 1; + } + else { + return (cbCardColor+1) * 100 + cbCardValue + (cbCardColor+1); + } + } + else { //27 -> 400 //28 -> 403 // 29 -> 406 // 30 -> 409 //31 -> 412 // 32 -> 415 // 33 -> 418 + if (cbCardValue + (cbCardColor+1) >= 10) + { + return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 * 3; + } + else { + return (cbCardColor+1) * 100 + (cbCardValue + cbCardColor) * 3; + } + } + } + + //扑克转换 + public static int SwitchToCardIndex(int cbCardData) + { + //扑克属性 + int cbCardColor=GetCardColor(cbCardData); + int cbCardValue=GetCardValue(cbCardData); + if (cbCardColor <= 3) + { + return (cbCardColor-1)*10+cbCardValue-cbCardColor; + } + else { + return (cbCardColor-1)*10+cbCardValue/3-cbCardColor+1; + } + } + + //扑克转换 + public static int[] SwitchToCardData(List cardInhand) + { + int[] cardIndex = new int[34]; + for(int i = 0; i < cardIndex.length; i++) + { + cardIndex[i] = 0; + } + + for(int i = 0; i < cardInhand.size(); i++) + { + int pos = SwitchToCardIndex(cardInhand.get(i)); + cardIndex[pos]++; + } + + return cardIndex; + } + + //扑克转换 + public static List SwitchToCardIndex(int[] cardIndex) + { + List cardIndexList = new ArrayList(); + for(int i = 0; i < cardIndex.length; i++) + { + for(int j = 0; j < cardIndex[i]; j++) + { + int card = SwitchToCardData(i); + cardIndexList.add(card); + } + } + return cardIndexList; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score, boolean isDaHu, String desc) { + if (map == null) + return null; + if (isDaHu) + { + map.remove(WinCardType.DIANPAO); + map.remove(WinCardType.PINGHU); + } + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score, isDaHu, desc); + map.put(type, wct); + return wct; + } + } + + public static boolean IsZiYiSe(int[] hand_cards, int max_gui, List opCards) + { + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + if (op_card.card < 400) + { + return false; + } + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + if (card < 400) + { + return false; + } + } + } + + return true; + } + + public static boolean IsLuoDiLong(int[] hand_cards, int max_gui, List opCards){ + List addcards =new ArrayList<>(); + for (int j=0;j100){ + wz++; + } + if (card<300&&card>200){ + tz++; + } + if (card<400&&card>300){ + lz++; + } + }else if (num>0){ + if(card<200&&card>100){ + wz++; + } + if (card<300&&card>200){ + tz++; + } + if (card<400&&card>300){ + lz++; + } + } + } + } + if (wz==9||tz==9||lz==9){ + return true; + } + return false; + } + + public static boolean IsYiTiaoLong(int[] hand_cards, int max_gui, List opCards) + { + int wz=0,tz=0,lz= 0; + for (int i=0;i0){ + if(card<200&&card>100){ + wz++; + } + if (card<300&&card>200){ + tz++; + } + if (card<400&&card>300){ + lz++; + } + } + } + if (wz==9||tz==9||lz==9){ + return true; + } + return false; + } + + public static boolean IsYiTiaoLong(TagAnalyseItem item){ + //判断是否有 + System.out.println("item:"); + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + System.out.println(op_card.card); + } + return false; + } + + public static boolean IsZiYiSe(TagAnalyseItem item) + { + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + if (card < 400) + { + return false; + } + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card < 400) + { + return false; + } + } + } + + return true; + } + + public static boolean IsQingYiSe(int[] hand_cards, int max_gui, List opCards) + { + int perColor = -1; + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + return true; + } + + public static boolean IsQingYiSe(TagAnalyseItem item) + { + int perColor = -1; + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + return true; + } + + public static boolean IsHunYiSe(int[] hand_cards, int max_gui, List opCards) + { + int perColor = -1; + boolean hunyise = false; + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + } + + int need_gui = 0; + if (hunyise == false) + { + need_gui++; + hunyise = true; + } + + if (perColor == -1) + { + need_gui++; + perColor = 1; + } + + if (need_gui > max_gui) + { + return false; + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + public static boolean IsHunYiSe(TagAnalyseItem item) + { + int perColor = -1; + boolean hunyise = false; + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + public static boolean IsShiBaLuoHan(TagAnalyseItem item) + { + int count = 0; + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_KONG || op_card.type == RuleWeight.TYPE_SELF_KONG) + { + count++; + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + //混幺九 + public static boolean IsHuYaoJiu(TagAnalyseItem item) { + boolean yaoKeZe = false; + if (item.cbCardEye != 0) + { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0) + { + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } else { + yaoKeZe = true; + } + } + } + else { + yaoKeZe = true; + } + } + } + + if (yaoKeZe) + { + return true; + } + + return false; + } + + //清幺九 + public static boolean IsQingYaoJiu(TagAnalyseItem item) { + if (item.cbCardEye != 0) + { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0) + { + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + } + } + + return true; + } + + public static boolean IsQuanFeng(TagAnalyseItem item) { + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0 && card < 400) { + return false; + } + } + } + + return true; + } + + + public static int IsDaXiaoSanYuan(TagAnalyseItem item) + { + byte mKeCount = 0; + byte mDuiCount = 0; + + if (item.cbCardEye != 0) + { + if (item.cbCardEye == Config.HONGZHONG + || item.cbCardEye == Config.FACAI + || item.cbCardEye == Config.BAIBAN) + { + mDuiCount++; + } + } + else { + mDuiCount++; + } + + //组合判断 + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card == Config.HONGZHONG + || op_card.card == Config.FACAI + || op_card.card == Config.BAIBAN) + { + mKeCount++; + } + } + else { + mKeCount++; + } + } + + //大三元 + if (mKeCount ==3) + { + return 1; + } + + //小三元 + if ((mKeCount ==2) && (mDuiCount ==1)) + { + return 2; + } + + return 0; + } + + public static int IsDaXiaoSiXi(TagAnalyseItem item) + { + int keCount = 0; + int duiCount = 0; + if (item.cbCardEye != 0) + { + if (item.cbCardEye == Config.DONGFENG + || item.cbCardEye == Config.NANFENG + || item.cbCardEye == Config.XIFENG + || item.cbCardEye == Config.BEIFENG) + { + duiCount++; + } + } + else { + duiCount++; + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + keCount++; + } + } + } + + + //大四喜 + if (keCount >= 4) + { + return 1; + } + //小四喜 + else if (keCount >= 3 && duiCount >= 1) + { + return 2; + } + + return 0; + } + + public static boolean QuanQiuRen(List opCards) + { + if (opCards.size() != 4) + { + return false; + } + + return false; + } + + //七小对 + public static int IsQiXiaoDui(int[] hand_cards, int max_gui, List opCards) + { + //组合判断 + if (opCards.size() != 0) return -1; + + //麻将判断 + int mCountTmp = 0; + int mDaDuiNum = 0; + + int need_gui = 0; + int curDuiNum = 0; + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num == 1) + { + need_gui++; + mCountTmp++; + curDuiNum++; + if (need_gui > max_gui) + { + return -1; + } + } + else if (num == 3) + { + need_gui++; + mCountTmp += 2; + mDaDuiNum++; + if (need_gui > max_gui) + { + return -1; + } + } + else if (num == 2) { + curDuiNum++; + mCountTmp++; + } + else if (num == 4) { + mCountTmp += 2; + mDaDuiNum++; + } + } + + if (need_gui > max_gui) + { + return -1; + } + + if ((max_gui - need_gui) % 2 != 0) + { + return -1; + } + + int guiDuiNum = (max_gui - need_gui) / 2; + if (curDuiNum <= guiDuiNum) + { + mCountTmp += curDuiNum; + mDaDuiNum += curDuiNum; + mDaDuiNum += (guiDuiNum-curDuiNum) / 2; + mCountTmp += (guiDuiNum-curDuiNum); + } + else { + mCountTmp += guiDuiNum; + mDaDuiNum += guiDuiNum; + } + + + if (mCountTmp == 7) + { + return mDaDuiNum; + } + + return -1; + } + + public static boolean ThirteenOne(int[] hand_cards, int max_gui, List opCards) + { + if (opCards.size() > 0) + { + return false; + } + + List tempList = new ArrayList(); + tempList.add(0); //101 + tempList.add(8); //109 + tempList.add(9); //201 + tempList.add(17); //209 + tempList.add(18); //301 + tempList.add(26); //309 + tempList.add(27); //东风 + tempList.add(28); + tempList.add(29); + tempList.add(30); + tempList.add(31); + tempList.add(32); + tempList.add(33); + + int jiangnum = 0; + int need_gui = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card_num = hand_cards[tempList.get(i)]; + if (card_num != 1) + { + if (card_num == 0) + { + need_gui++; + if (need_gui > max_gui) + { + return false; + } + } + else if (card_num == 2) + { + jiangnum++; + if (jiangnum >= 2) + { + return false; + } + } + else { + return false; + } + } + } + + if (jiangnum == 0) + { + need_gui++; + jiangnum++; + if (need_gui > max_gui) + { + return false; + } + } + + if (jiangnum == 1) + { + return true; + } + + return false; + } + + + public static boolean AnalyseChiHuCard(Map curMap, ITObject config, int[] hand_cards, int gui_num, List opCards, List tagAnalyseItemList) { + get_hu_info(hand_cards, gui_num, opCards, tagAnalyseItemList); + System.out.println("AnalyseChiHuCard_bak"); + //变量定义 + List wChiHuKind = new ArrayList(); + List> tempLaiziMapList = new ArrayList>(); + + //特殊胡牌 + int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards); + if (DaDuiNum >= 0) + { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + if (DaDuiNum==3){ + wChiHuKind.add(WinCardType.SANLONGJIABEI); + putWinCardType(map, WinCardType.SANLONGJIABEI, 1, WinCardType.SANLONGJIABEI_SCORE, false, "三龙夹背"); + }else if(DaDuiNum==2){ + wChiHuKind.add(WinCardType.SHUANGLONGJIABEI); + putWinCardType(map, WinCardType.SHUANGLONGJIABEI, 1, WinCardType.SHUANGLONGJIABEI_SCORE, false, "双龙夹背"); + }else if(DaDuiNum==1){ + wChiHuKind.add(WinCardType.LONGJIABEI); + putWinCardType(map, WinCardType.LONGJIABEI, 1, WinCardType.LONGJIABEI_SCORE, false, "龙夹背"); + }else { + wChiHuKind.add(WinCardType.QIXIAODUI); + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, false, "七小对"); + } + boolean qing_se = false; + + if (IsQingYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + + qing_se = true; + } + + + + if (IsZiYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + + + if (!qing_se) + { + + if (IsHunYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + + } + } + + boolean qxybg = IsQiXingYiBanGao(hand_cards); + //七星一般高 + if (qxybg){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + wChiHuKind.add(WinCardType.QIXINGYIBANGAO); + putWinCardType(map, WinCardType.QIXINGYIBANGAO, 1, WinCardType.QIXINGYIBANGAO_SCORE, false, "七星一般高"); + } + //七星 + boolean qx = IsQiXing(hand_cards); + if (qx&&!qxybg){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + wChiHuKind.add(WinCardType.QIXING); + putWinCardType(map, WinCardType.QIXING, 1, WinCardType.QIXING_SCORE, false, "七星"); + } + + //一般高 + boolean ybg = IsYiBanGao(hand_cards); + if (ybg&&!qxybg){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + wChiHuKind.add(WinCardType.YIBANGAO); + putWinCardType(map, WinCardType.YIBANGAO, 1, WinCardType.YIBANGAO_SCORE, false, "一般高"); + } + + //烂牌 + boolean lanpai = IsLanPai(hand_cards); + if (lanpai&&!qxybg&&!qx&&!ybg){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + wChiHuKind.add(WinCardType.LANPAI); + putWinCardType(map, WinCardType.LANPAI, 1, WinCardType.LANPAI_SCORE, false, "烂牌"); + } + + + + //胡牌分析 + System.out.println("tag:"); + System.out.println(tagAnalyseItemList); + for (int i = 0; i < tagAnalyseItemList.size(); i++) { + HashMap map = new HashMap(); + + tempLaiziMapList.add(map); + + //变量定义 + int lianCardNum = 0; + int pengCardNum = 0; + int lianOrPengNum = 0; + TagAnalyseItem pAnalyseItem = tagAnalyseItemList.get(i); + + //牌型分析 + for (int j = 0; j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) { + if (cbWeaveKind.card == 0) + { + lianOrPengNum++; + } + else if (cbWeaveKind.card != 0 && cbWeaveKind.card2 == 0 && cbWeaveKind.card3 == 0) + { + lianOrPengNum++; + } + else { + pengCardNum++; + } + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + lianCardNum++; + } + } + System.out.println(pengCardNum); + //特殊--碰碰胡 + if (pengCardNum + lianOrPengNum == 4 || pAnalyseItem.isPengPengHu) { + wChiHuKind.add(WinCardType.DADUIZI); + putWinCardType(map, WinCardType.DADUIZI, 1, WinCardType.DADUIZI_SCORE, false, "碰碰胡"); + } + + + boolean qing_se = false; + if (IsQingYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, false, "清一色"); + qing_se = true; + } + + + if (IsZiYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, false, "字一色"); + qing_se = true; + } + + if(!qing_se) + { + if (IsHunYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + + System.out.println("laizi:"+tempLaiziMapList); + if (tempLaiziMapList.size() > 0) + { + + //判断是否是一条龙 + //是否是一条龙 + boolean yitiaolong = false; + if (IsYiTiaoLong(hand_cards,0,opCards)){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + WinCard.putWinCardType(map, WinCardType.YI_TIAO_LONG, 1,WinCardType.YI_TIAO_LONG_SCORE, false, "一条龙"); + } + + boolean luodilong = IsLuoDiLong(hand_cards,0,opCards); + if (luodilong){ + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + WinCard.putWinCardType(map, WinCardType.LOU_DI_LONG, 1,WinCardType.LUO_DI_LONG_SCORE, false, "落地龙"); + } + + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + + + int maxType = 0; + int maxScore = 0; + List typeList = new ArrayList(); + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + int type = cardType.type; + if (cardType.IsDaHu()) + { + typeList.add(type); + } + } + + if (maxType > 0) + { + for(int i = 0; i < typeList.size(); i++) + { + int type = typeList.get(i); + if (type != maxType) + { + tempLaiziMap.remove(type); + } + } + } + + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + curMap.putAll(tempLaiziMap); + return true; + } + return false; + } + + public static boolean get_hu_info(int[] hand_cards, int gui_num, List opCards, List tagAnalyseItemList) { + int[] cards = new int[34]; + System.arraycopy(hand_cards, 0, cards, 0, 34); + + int[] eye_tbl = new int[34]; + int eye_num = 0; + int empty = -1; + for (int i = 0; i < 34; ++i) { + // 优化手段,三不靠的牌,必做将 + int min = (i / 9) * 9; + int max = min + 8; + if (max == 35) max = 33; + if (cards[i] == 1 && + (i - 2 < min || cards[i - 2] == 0) && + (i - 1 < min || cards[i - 1] == 0) && + (i + 1 > max || cards[i + 1] == 0) && + (i + 2 > max || cards[i + 2] == 0)) { + if (gui_num < 0) { + return false; + } + eye_num = 1; + eye_tbl[0] = i; + empty = -1; + break; + } + if (empty == -1 && cards[i] == 0) empty = i; + if (cards[i] > 0 && cards[i] + gui_num >= 2) { + eye_tbl[eye_num++] = i; + } + } + if (empty > 0) { + eye_tbl[eye_num++] = empty; + } + + boolean hu = false; + int[] cache = {0, 0, 0, 0}; + TagAnalyseItem[] cache_item = {null, null, null, null}; + for (int i = 0; i < eye_num; i++) { + int eye = eye_tbl[i]; + if (eye == empty) { + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = 0; + tagItem.cbCardEye2 = 0; + hu = foreach_eye(cards, gui_num - 2, gui_num, 1000, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 2); + } + tagAnalyseItemList.add(tagItem); + } + } else { + int n = cards[eye]; + if (n == 1) { + cards[eye] = 0; + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = SwitchToCardData(eye); + tagItem.cbCardEye2 = 0; + hu = foreach_eye(cards, gui_num - 1, gui_num, eye / 9, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 1); + } + tagAnalyseItemList.add(tagItem); + } + } else { + cards[eye] -= 2; + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = SwitchToCardData(eye); + tagItem.cbCardEye2 = SwitchToCardData(eye); + hu = foreach_eye(cards, gui_num, gui_num, eye / 9, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num); + } + tagAnalyseItemList.add(tagItem); + } + } + cards[eye] = n; + } + } + + return tagAnalyseItemList.size() > 0; + } + public static boolean IsLanPai(int[] cards){ + List list = WinSplitCard.SwitchToCardIndex(cards); + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100); + if (wangzicard.size()==3){ + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){ + + }else{ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100); + if (tongzicard.size()==3){ + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){ + // return false; + }else{ + return false; + } + + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100); + if (tiaozicard.size()==3){ + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){ + + }else{ + return false; + } + } + } + + + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + System.out.println("cm:"+ uniqueList.size()); + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + if (ziList.size()<5){ + return false; + } + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + public static boolean IsYiBanGao(int[] cards){ + List list = WinSplitCard.SwitchToCardIndex(cards); + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100); + if (wangzicard.size()==3){ + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){ + + }else{ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100); + if (tongzicard.size()==3){ + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){ + // return false; + }else{ + return false; + } + + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100); + if (tiaozicard.size()==3){ + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){ + + }else{ + return false; + } + } + } + + + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + if(uniqueList.size()>1){ + return false; + } + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + + if (ziList.size()<5){ + return false; + } + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + public static boolean IsQiXing(int[] cards){ + List list = WinSplitCard.SwitchToCardIndex(cards); + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + System.out.println(wangzicard); + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100); + if (wangzicard.size()==3){ + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){ + + }else{ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100); + if (tongzicard.size()==3){ + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){ + // return false; + }else{ + return false; + } + + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100); + if (tiaozicard.size()==3){ + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){ + + }else{ + return false; + } + } + } + + + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + if (ziList.size()<7){ + return false; + } + System.out.println(ziList.size()); + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + public static boolean IsQiXingYiBanGao(int[] cards){ + List list = WinSplitCard.SwitchToCardIndex(cards); + Map tempCardList = new HashMap<>(); + for(Integer cd:list){ + if (tempCardList.containsKey(cd)){ + tempCardList.put(cd,tempCardList.get(cd)+1); + }else{ + tempCardList.put(cd,1); + } + } + int tongzi = 0; + int wangzi = 0; + int tiaozi = 0; + ArrayList wangzicard = new ArrayList<>(); + ArrayList tongzicard = new ArrayList<>(); + ArrayList tiaozicard = new ArrayList<>(); + ArrayList checkmen = new ArrayList<>(); + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num>1){ + return false; + } + if (card<200&&card>100){ + wangzi++; + wangzicard.add(card); + } + if (card<300&&card>200){ + tongzi++; + tongzicard.add(card); + } + if(card<400&&card>300){ + tiaozi++; + tiaozicard.add(card); + } + } + if(wangzi>3||tongzi>3||tiaozi>3){ + return false; + } + System.out.println(wangzicard); + if (wangzicard.size()>0){ + checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100); + if (wangzicard.size()==3){ + if(wangzicard.get(0)%100>3){ + return false; + } + if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){ + return false; + } + }else if(wangzicard.size()==2){ + if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){ + + }else{ + return false; + } + } + } + if (tongzicard.size()>0){ + checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100); + if (tongzicard.size()==3){ + if(tongzicard.get(0)%100>3){ + return false; + } + if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){ + return false; + } + }else if(tongzicard.size()==2){ + if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){ + // return false; + }else{ + return false; + } + + } + } + if(tiaozicard.size()>0){ + checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100); + if (tiaozicard.size()==3){ + if(tiaozicard.get(0)%100>3){ + return false; + } + if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){ + return false; + } + }else if(tiaozicard.size()==2){ + if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){ + + }else{ + return false; + } + } + } + + + List uniqueList = new ArrayList<>(new HashSet<>(checkmen)); + if (uniqueList.size()!=1){ + return false; + } + + List tempList = new ArrayList(); + Collections.sort(list); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + List ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size()); + int jiangnum = 0; + if (ziList.size()<7){ + return false; + } + System.out.println(ziList.size()); + for(int i = 0; i < ziList.size(); i++) + { + int card = ziList.get(i); + jiangnum = Collections.frequency(tempList,card); + if (jiangnum!=1){ + return false; + } + } + + return true; + } + + public static boolean isPengPengHu(int[] cards, int gui_num) + { + int need_gui = 0; + for(int i = 0; i < cards.length; i++) + { + int num = cards[i]; + if (num > 0) + { + if (num == 1) + { + need_gui += 2; + } + else if (num == 2) + { + need_gui++; + } + else if (num == 3) + { + + } + else if (num == 4) + { + return false; + } + } + } + + if (need_gui > gui_num) + { + return false; + } + + if ((gui_num - need_gui) % 3 == 0) + { + return true; + } + + return false; + } + + public static boolean foreach_eye(int[] cards, int gui_num, int max_gui, int eye_color, int[] cache, TagAnalyseItem item, TagAnalyseItem[] cacheItemList) { + int left_gui = gui_num; + for (int i = 0; i < 3; i++) { + int cache_index = -1; + if (eye_color != i) cache_index = i; + TagAnalyseItem cache_item = new TagAnalyseItem(); + int need_gui = check_normal(cards, i * 9, i * 9 + 8, max_gui, cache_index, cache, i, item, cacheItemList, cache_item); + if (cache_index > 0) { + cache[i] = need_gui + 1; + cacheItemList[i] = cache_item; + } + left_gui -= need_gui; + if (left_gui < 0) { + return false; + } + } + + int cache_index = -1; + if (eye_color != 3) cache_index = 3; + TagAnalyseItem cache_item = new TagAnalyseItem(); + int need_gui = check_zi(cards, max_gui, cache_index, cache, 3, item, cacheItemList, cache_item); + if (cache_index > 0) { + cache[3] = need_gui + 1; + cacheItemList[3] = cache_item; + } + for(int i = 1; i <= 4; i++) + { + if (left_gui - 3*i == need_gui) + { + for(int j = 0; j < i; j++) { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, 0, 0, 0); + item.cbOpCard.add(op_card); + } + } + } + + return left_gui >= need_gui; + } + + public static int check_normal(int[] cards, int from, int to, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) { + if (cache_index >= 0) { + int n = cache[cache_index]; + if (n > 0) { + TagAnalyseItem old_item = cacheItemList[cache_index]; + if (old_item != null) + { + for(int i = 0; i < old_item.cbOpCard.size(); i++) + { + OpCard op_card = old_item.cbOpCard.get(i); + item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3)); + + + OpCard cache_card = old_item.cbOpCard.get(i); + cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3)); + } + } + return n - 1; + } + } + + int n = 0; + for (int i = from; i <= to; i++) { + n = n * 10 + cards[i]; + } + + if (n == 0) return 0; + + boolean n3 = false; + for (int i = 0; i <= max_gui; i++) { + if ((n + i) % 3 == 0) { + n3 = true; + break; + } + } + + if (!n3) { + return max_gui + 1; + } + + return next_split(n, 0, max_gui, eye_color, item, cacheItemList, cache_item, 0); + } + + public static int next_split(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c = 0; + while (true) { + if (n == 0) return need_gui; + + while (n > 0) { + c = n % 10; + n = n / 10; + cur_index++; + if (c != 0) break; + } + if (c == 1 || c == 4) { + if (c == 4) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + cache_item.cbOpCard.add(cache_card); + } + return one(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } else if (c == 2) { + return two(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + else { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + cache_item.cbOpCard.add(cache_card); + } + } + } + + public static int one(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c1 = n % 10; + int c2 = (n % 100) / 10; + + OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + if (c1 == 0) + { + op_card.card2 = 0; + cache_card.card2 = 0; + ++need_gui; + } + else { + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + n -= 1; + } + + if (c2 == 0) { + op_card.card3 = 0; + cache_card.card3 = 0; + ++need_gui; + } + else { + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + n -= 10; + } + + if (op_card.card2 == 0 && op_card.card3 == 0) + { + op_card.type = RuleWeight.TYPE_PONG; + cache_card.type = RuleWeight.TYPE_PONG; + } + + item.cbOpCard.add(op_card); + cache_item.cbOpCard.add(cache_card); + + if (n == 0) return need_gui; + + if (need_gui > max_gui) return need_gui; + + return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + + public static int two(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c1 = n % 10; + int c2 = (n % 100) / 10; + int c3 = (n % 1000) / 100; + int c4 = (n % 10000) / 1000; + + boolean choose_ke = true; + if (c1 != 0) { + if (c1 == 1) { + // 刻子 + if (c2 != 0 && c2 != 1) { + if (c2 == 2) { + if (c3 == 2) { + if (c4 == 2) choose_ke = false; + } else if (c3 == 3) { + if (c4 != 2) choose_ke = false; + } else { + choose_ke = false; + } + } else if (c2 == 3) { + if (c3 != 3) { + choose_ke = false; + } + } else if (c2 == 4) { + if (c3 == 2) { + if (c4 == 2 || c4 == 3 || c4 == 4) choose_ke = false; + } + if (c3 == 3) { + choose_ke = false; + } + } + } + } else if (c1 == 2) { + choose_ke = false; + } else if (c1 == 3) { + if (c2 == 2) { + if (c3 == 1 || c3 == 4) { + choose_ke = false; + } else if (c3 == 2) { + if (c4 != 2) choose_ke = false; + } + } + if (c2 == 3) { + choose_ke = false; + } else if (c2 == 4) { + if (c3 == 2) { + choose_ke = false; + } + } + } else if (c1 == 4) { + if (c2 == 2 && c3 != 2) { + choose_ke = false; + } else if (c2 == 3) { + if (c3 == 0 || c3 == 1 || c3 == 2) { + choose_ke = false; + } + } else if (c2 == 4) { + if (c3 == 2) choose_ke = false; + } + } + } // c1 == 0 全拆刻子 + + + if (choose_ke) { + need_gui += 1; + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0); + cache_item.cbOpCard.add(cache_card); + } else { + OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard op_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard cache_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + + if (c1 < 2) { + need_gui += (2 - c1); + n -= c1; + if (c1 == 0) + { + op_card.card2 = 0; + op_card2.card2 = 0; + + cache_card.card2 = 0; + cache_card2.card2 = 0; + } + else if (c1 == 1) + { + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + op_card2.card2 = 0; + + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card2.card2 = 0; + } + } else { + n -= 2; + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + op_card2.card2 = (eye_color+1)*100+(9-cur_index+1-1); + + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card2.card2 = (eye_color+1)*100+(9-cur_index+1-1); + } + + if (c2 < 2) { + need_gui += (2 - c2); + n -= c2 * 10; + if (c2 == 0) + { + op_card.card3 = 0; + op_card2.card3 = 0; + + cache_card.card3 = 0; + cache_card2.card3 = 0; + } + else if (c2 == 1) + { + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + op_card2.card3 = 0; + + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card2.card3 = 0; + } + } else { + n -= 20; + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + op_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2); + + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2); + } + + item.cbOpCard.add(op_card); + item.cbOpCard.add(op_card2); + + cache_item.cbOpCard.add(cache_card); + cache_item.cbOpCard.add(cache_card2); + } + + if (n == 0) return need_gui; + + if (need_gui > max_gui) return need_gui; + + return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + + public static int check_zi(int[] cards, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) { + if (cache_index >= 0) { + int n = cache[cache_index]; + if (n > 0) { + TagAnalyseItem old_item = cacheItemList[cache_index]; + if (old_item != null) + { + for(int i = 0; i < old_item.cbOpCard.size(); i++) + { + OpCard op_card = old_item.cbOpCard.get(i); + item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3)); + + OpCard cache_card = old_item.cbOpCard.get(i); + cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3)); + } + } + return n - 1; + } + } + + int need_gui = 0; + for (int i = 27; i < 34; i++) { + int c = cards[i]; + if (c == 0) continue; + if (c == 1 || c == 4) { + if (c == 1) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + cache_item.cbOpCard.add(cache_card); + } + else if (c == 4) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card); + OpCard op_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card2); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card); + OpCard cache_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card2); + } + need_gui = need_gui + 2; + } else if (c == 2) { + need_gui = need_gui + 1; + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0); + cache_item.cbOpCard.add(cache_card); + } + else { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card); + } + if (need_gui > max_gui) return need_gui; + } + + return need_gui; + } +} diff --git a/game_mj_gejiu/src/test/java/game_mj_yijiaolaiyou/Main.java b/game_mj_gejiu/src/test/java/game_mj_yijiaolaiyou/Main.java new file mode 100644 index 0000000..525ce5e --- /dev/null +++ b/game_mj_gejiu/src/test/java/game_mj_yijiaolaiyou/Main.java @@ -0,0 +1,9 @@ +package game_mj_yijiaolaiyou; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_hongzhong/.idea/compiler.xml b/game_mj_hongzhong/.idea/compiler.xml new file mode 100644 index 0000000..2a395f2 --- /dev/null +++ b/game_mj_hongzhong/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/.idea/encodings.xml b/game_mj_hongzhong/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_mj_hongzhong/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/.idea/jarRepositories.xml b/game_mj_hongzhong/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_mj_hongzhong/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/.idea/misc.xml b/game_mj_hongzhong/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_mj_hongzhong/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/.idea/vcs.xml b/game_mj_hongzhong/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/game_mj_hongzhong/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/config/game-config.xml b/game_mj_hongzhong/config/game-config.xml new file mode 100644 index 0000000..e36b2e6 --- /dev/null +++ b/game_mj_hongzhong/config/game-config.xml @@ -0,0 +1,11 @@ + + + + + 192.168.3.9 + 192.168.3.9 + 6421 + 8860 + 22 + true + \ No newline at end of file diff --git a/game_mj_hongzhong/config/log4j.properties b/game_mj_hongzhong/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_hongzhong/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_hongzhong/config/taurus-core.xml b/game_mj_hongzhong/config/taurus-core.xml new file mode 100644 index 0000000..1f91b10 --- /dev/null +++ b/game_mj_hongzhong/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_hongzhong/config/taurus-permanent.xml b/game_mj_hongzhong/config/taurus-permanent.xml new file mode 100644 index 0000000..40e4818 --- /dev/null +++ b/game_mj_hongzhong/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_hongzhong/pom.xml b/game_mj_hongzhong/pom.xml new file mode 100644 index 0000000..10fb611 --- /dev/null +++ b/game_mj_hongzhong/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_hongzhong + 1.0.0 + jar + + game_mj_hongzhong + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_hongzhong + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_hongzhong/src/main/java/extend/mj/CardNiao.java b/game_mj_hongzhong/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..a21039b --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/CardNiao.java @@ -0,0 +1,19 @@ +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("score", score); + return obj; + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/Config.java b/game_mj_hongzhong/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..fb13fd7 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/Config.java @@ -0,0 +1,122 @@ +package extend.mj; + +public class Config { + + public static final int HONGZHONG = 412; + public static final int XIPAI_SCORE = 10; + + public static final String ROOM_CONFIG_DIANPAO = "dianpao"; + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian"; + public static final String ROOM_CONFIG_FENGDING = "fengding"; + public static final String ROOM_CONFIG_FENGDING_SCORE = "fengding_score"; + 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_QIDUI = "qidui"; + public static final String ROOM_CONFIG_NIAO = "niao"; + public static final String ROOM_CONFIG_NIAO_OPT = "niao_opt"; + public static final String ROOM_CONFIG_NIAO_OPT_SCORE = "niao_opt_score"; + public static final String ROOM_CONFIG_HONGZHONG = "laizi"; + public static final String ROOM_CONFIG_WUGUI_JIABEI = "wuguijiabei"; + public static final String ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI = "wuguizhuopaojiabei"; + + public static final String ROOM_CONFIG_DIANPAOHU = "dianpaohu"; + public static final String ROOM_CONFIG_QIANGKONG = "qiangkong"; + public static final String ROOM_CONFIG_QIANGKONG_NIAO = "qiangkong_niao"; + public static final String ROOM_CONFIG_HONGZHONG8 = "laizi8"; + public static final String ROOM_CONFIG_NONEALL = "none_is_all"; + public static final String ROOM_CONFIG_NIAO_SCORE = "niao_score"; + public static final String ROOM_CONFIG_QG_TYPE = "qianggang_type"; + public static final String ROOM_CONFIG_JIANGMA = "jiangma"; + public static final String ROOM_CONFIG_HZ_HU = "hz_hu"; + 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_DI_FEN = "di_fen"; //低分 + public static final String ROOM_CONFIG_LAIZI4_HU = "laizi4_hu"; //四鬼胡牌 + + public static final String SETTLE_DIAN_PAO = "dian_pao"; + public static final String SETTLE_JIE_PAO = "jie_pao"; + public static final String SETTLE_ZIMO = "zimo"; + public static final String SETTLE_AN_KONG = "an_kong"; + public static final String SETTLE_MING_KONG = "ming_kong"; + + public static final int NIAO_TYPE_159 =1; + public static final int NIAO_TYPE_ALL =2; + public static final int NIAO_TYPE_WOWO =3; + + /** + * + */ + 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_PIAONIAO_TIP = "833"; + /** + * + */ + public static final String GAME_EVT_PIAONIAO = "834"; + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXActionEvent.java b/game_mj_hongzhong/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..db9bbf0 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXActionEvent.java @@ -0,0 +1,18 @@ +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_PIAO_NIAO = "piao_niao"; +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXGameController.java b/game_mj_hongzhong/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..605a838 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXGameController.java @@ -0,0 +1,278 @@ +package extend.mj; + +import java.util.Collections; +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; + +/** + * + * + * + * EXGameController.java + */ +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.weight+" 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; + TObject 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+"]"); + } + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){ + 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); + } + EXRoom room = player.getRoom(); + + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type)); + } + room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast); + ((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + //Global.logger.info("playerid:"+player.playerid+" isw: "+player.is_white); + + player.cardInhand = owner.card.deal(player.is_white); + Collections.sort(player.cardInhand); + if(Global.loggerDebug) { + Global.logger.info(player + " cardlist:" + player.cardInhand); + } + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + param.putInt("round", player.room.round); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + + Global.logger.info("dealCard() ===> round = "+owner.round); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + public void winEvent(EXPlayer owner,int from_seat,int win_card) { + 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("win_card", win_card); + param.putInt("from_seat", from_seat); + if(Global.loggerDebug) { + Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]"); + } + 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 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); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putFloat("xipai_score", Float.parseFloat(owner.xi_pai_score + "")/100 ); +// mp.putInt("xipai_score", owner.xi_pai_score); + 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 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("hu_score", player.score.round_log.get(EXScore.WIN)); + param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO)); + param.putInt("gang_score", player.score.round_log.get(EXScore.KONG)); + param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO)); + player.hp_info(param); + 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); + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + 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); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.playBackData.addResult(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXMainServer.java b/game_mj_hongzhong/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..1e98ee6 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXMainServer.java @@ -0,0 +1,98 @@ +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.PROtherKongState; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.player.rulestate.PRSelfKongState; +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.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.player.state.EXPlayerWaitState; +import extend.mj.room.state.EXRoomDealState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.room.state.EXRoomStartGameState; + +/** + * + * + * EXMainServer.java + */ +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(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + 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()); + + + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXPlayBack.java b/game_mj_hongzhong/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..7169ad6 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXPlayBack.java @@ -0,0 +1,78 @@ +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){ + 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); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public void addResultData(ITObject resultData){ + // ITObject mp = TObject.newInstance(); + // mp.putInt("type", 0); + // mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "Result"); + cmdObj.putTObject("data", resultData); + cmdList.addTObject(cmdObj); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXPlayer.java b/game_mj_hongzhong/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..3023de5 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXPlayer.java @@ -0,0 +1,142 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +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; + +/** + * + * + * + * 2017��8��30�� + * EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + + // ������ + public List outcardList; + + public ITArray opCard; + + public List pongGroup; + public List kongGroup; + public List selfKongGroup; + public List opCardList; + + public int drawCard = 0; + public int winCard = 0; + + public TipManager tipMgr; + + public SettleLog settleLog; + + /** + * ©�� + */ + public boolean louhu = false; + + /** + * ǿ�Ƽ����� + */ + public boolean forceCheckWin = false; + /** + * 0 С�� 1 ���ܺ� + */ + public int winType = 0; + public List notPongKongList = new ArrayList<>(); + + public int niaoCount; + public int piaoNiao; + public boolean fengding; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + + pongGroup = new ArrayList<>(); + kongGroup = new ArrayList<>(); + selfKongGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + + opCard = new TArray(); + + tipMgr = new TipManager(this); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_DIAN_PAO, 0); + settleLog.put(Config.SETTLE_JIE_PAO, 0); + settleLog.put(Config.SETTLE_ZIMO, 0); + settleLog.put(Config.SETTLE_AN_KONG, 0); + settleLog.put(Config.SETTLE_MING_KONG, 0); + fengding = false; + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(self); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", cardInhand.size()); + playerData.putInt("score", score.total_score); + playerData.putInt("piao_niao", this.piaoNiao); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card", opcard.card); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + + return playerData; + } + + public void clear() { + super.clear(); + this.cardInhand.clear(); + this.notPongKongList.clear(); + this.winer = 0; + this.louhu = false; + this.outcardList.clear(); + this.drawCard = 0; + this.kongGroup.clear(); + this.pongGroup.clear(); + this.selfKongGroup.clear(); + this.opCardList.clear(); + this.score.resetRound(); + this.niaoCount = 0; + this.piaoNiao = 0; + this.fengding = false; + } + + + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXRoom.java b/game_mj_hongzhong/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..353e63a --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,700 @@ +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.player.state.EXPlayerDisCardTipState; +import extend.mj.tip.Action; +import extend.mj.tip.TipManager; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winCount = 0; + public boolean liuju = false; + + public ArrayList niao; + + public int niao_score; + public int piaoNiaoCount; + public int adminSeat = 0; + + public int di_fen = 2; + + public int fengdingScore = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.niao = new ArrayList(); + this.fengdingScore = 0; + + 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_OPT)) + { + this.config.putInt(Config.ROOM_CONFIG_PIAO_NIAO_OPT, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_JIABEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_DIANPAOHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAOHU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT_SCORE)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE, 1); + } + + if (Global.gameId == 1) { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG, true); + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false); + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO, true); + this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG8, false); + this.config.putInt(Config.ROOM_CONFIG_JIANGMA, 0); + if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false); + } + this.niao_score = this.config.containsKey(Config.ROOM_CONFIG_NIAO_SCORE)?this.config.getInt(Config.ROOM_CONFIG_NIAO_SCORE):1; + } else { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false); + this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG, true); + this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false); + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + this.config.putInt(Config.ROOM_CONFIG_QG_TYPE, 0); + if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false); + } + this.niao_score = 2; + if(this.config.getInt(Config.ROOM_CONFIG_NIAO) > 0) { + int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE); + if(opt==2)this.niao_score = 1; + } + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false); + } + + 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_DI_FEN)) + { + this.config.putInt(Config.ROOM_CONFIG_DI_FEN, 0); + this.di_fen = 2; + } + else { + int di_index = this.config.getInt(Config.ROOM_CONFIG_DI_FEN); + if (di_index == 0) + { + this.di_fen = 2; + } + else if (di_index == 1) + { + this.di_fen = 3; + } + else if (di_index == 2) + { + this.di_fen = 4; + } + else if (di_index == 3) + { + this.di_fen = 5; + } + } + + // this.entrustTime = this.config.getInt("tuoguan_active_time") * 60000; + // this.openEntrust = this.entrustTime > 0; + // this.entrusResultType = this.config.getInt("tuoguan_result_type"); + this.isEntrust=true; + this.adminSeat = 0; + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry 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); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN); + if(type == EXScore.WIN) { + if (zhuangxian) { + if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) { + score += 1; + } + } + + EXScore exscore = (EXScore) destPlayer.score; + EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer); + if (hu_score == null) { + hu_score = new EXScore.HUScore(); + hu_score.player = fromPlayer; + exscore.hu_score.add(hu_score); + } + + hu_score.score += score; + } + else if (type == EXScore.NIAO) + { + EXScore exscore = (EXScore) destPlayer.score; + EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer); + if (hu_score == null) { + hu_score = new EXScore.HUScore(); + hu_score.player = fromPlayer; + exscore.hu_score.add(hu_score); + } + + hu_score.niao_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 addAllScore(EXPlayer destPlayer, int socre, int type) { + for (Entry 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) { + this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO); + } + + public void addAllNiaoScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.niaoCount ++; + 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 entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addPiaoNiaoScore(destPlayer,fromPlayer); + } + } + + private int getNiaoNum(int card) { + int niao_num = 0; + int niao = this.config.getInt(Config.ROOM_CONFIG_NIAO); + switch (niao) { + case Config.NIAO_TYPE_159: + int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + niao_num = opt * 2; + break; + case Config.NIAO_TYPE_ALL: + niao_num = 1; + break; + case Config.NIAO_TYPE_WOWO: + int tem = card % 100; + niao_num = (card == Config.HONGZHONG) ? 10 : tem; + break; + } + return niao_num; + } + + public void niao_tongPao(int card) { + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + __zhuaNiao(dianPaoPlayer, getNiaoNum(card)); + List winPlayerList = new ArrayList(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.winer == 1) { + ((EXPlayer)player).niaoCount = 0; + winPlayerList.add((EXPlayer) player); + } + } + for (CardNiao cn : niao) { + boolean not_niao = true; + if (dianPaoPlayer.playerid == cn.playerId) { + for (EXPlayer winer : winPlayerList) { + int score = cn.score; + if(Global.gameId != 1&&winer.winType == 1) + score = score * (maxPlayers - 1); + winer.niaoCount ++; + this.addNiaoScore(winer, dianPaoPlayer, score); + } + not_niao = false; + } else { + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + boolean jiabei = false; + boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI); + if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { + if (Util.cardNum(Config.HONGZHONG, winer.cardInhand) <= 0) { + jiabei = true; + } + } + + int score = 0; + if (jiabei) + { + score = cn.score * 2; + } + else { + score = cn.score; + } + if (Global.gameId != 1&&winer.winType == 1) + score = score * (maxPlayers - 1); + this.addNiaoScore(winer, dianPaoPlayer, score); + not_niao = false; + winer.niaoCount ++; + break; + } + } + } + if (not_niao) + cn.score = 0; + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + for (EXPlayer winer : winPlayerList) { + if(winer.niaoCount == 6 ||winer.niaoCount == 0) { + this.addNiaoScore(winer, dianPaoPlayer, niao_score*6); + } + } + } + + EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat); + } + + public void niao_dianPao(EXPlayer owner, int card) { + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + EXPlayer winer = owner; + int num = getNiaoNum(card); + boolean jiabei = false; + boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI); + if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { + if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) { + jiabei = true; + int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA); + if(jm_num>0) { + num +=jm_num; + } + } + } + + __zhuaNiao(winer, num); + winer.niaoCount = 0; + for (CardNiao cn : niao) { + if (cn.playerId == winer.playerid || dianPaoPlayer.playerid == cn.playerId) { + int score = 0; + if (jiabei) + { + score = cn.score * 2; + } + else { + score = cn.score; + } + if(Global.gameId != 1&&owner.winType == 1) + score = score * (maxPlayers - 1); + winer.niaoCount ++; + this.addNiaoScore(winer, dianPaoPlayer, score); + } else { + cn.score = 0; + } + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + if(winer.niaoCount == 6 ||winer.niaoCount == 0) { + this.addNiaoScore(winer, dianPaoPlayer, niao_score*6); + } + } + EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat); + } + + public void niao_selfWin(EXPlayer owner, int card) { + if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) { + return; + } + int num = getNiaoNum(card); + boolean hongzhong = Util.checkCard(Config.HONGZHONG, owner.cardInhand); + int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA); + if(card!=Config.HONGZHONG&&!hongzhong&&jm_num>0) { + num +=jm_num; + } + __zhuaNiao(owner, num); + for (Entry entry : owner.room.playerMapById.entrySet()) { + ((EXPlayer)entry.getValue()).niaoCount = 0; + } + boolean jiabei = false; + boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); + if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { + if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0 && owner.drawCard != Config.HONGZHONG) { + jiabei = true; + } + } + for (CardNiao cn : niao) { + boolean not_niao = true; + if (cn.playerId == owner.playerid) { + if (jiabei) + { + this.addAllNiaoScore(owner, cn.score * 2); + } + else { + this.addAllNiaoScore(owner, cn.score); + } + not_niao = false; + } else { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + if (jiabei) + { + this.addNiaoScore(owner, player, cn.score * 2); + } + else { + this.addNiaoScore(owner, player, cn.score); + } + not_niao = false; + break; + } + } + } + if (not_niao) + cn.score = 0; + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.niaoCount == 6 ||player.niaoCount == 0) { + if (jiabei) + { + this.addNiaoScore(owner, player, niao_score*6*2); + } + else { + this.addNiaoScore(owner, player, niao_score*6); + } + } + } + } + EXMainServer.gameCtr.sendNiaoEvt(owner, owner.seat); + } + + private final void __zhuaNiao(EXPlayer owner, int niao_num) { + this.niao.clear(); + + boolean niao_all = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL; + for (int index = 0; index < niao_num; index++) { + if (card.cardList.size() == 0) { + break; + } + + int card = this.card.pop(); + CardNiao cn = new CardNiao(); + cn.card = card; + this.niao.add(cn); + int tem = card % 100; + if (niao_all) { + cn.playerId = owner.playerid; + if (card == Config.HONGZHONG || (Global.gameId == 1 &&tem == 1)) { + cn.score = 10; + } else { + cn.score = tem; + } + } else { + if (card == Config.HONGZHONG || tem == 1 || tem == 5 || tem == 9) { + cn.playerId = owner.playerid; + cn.score = niao_score; + } + } + } + + } + + public void winCallback(EXPlayer owner, int card) { + boolean qiangkong_niao = config.getBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO); + + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + if (owner.winType == 1 && qiangkong_niao) + niao_tongPao(card); + else + niao_tongPao(card); + } else { + if (owner.winType == 1 && qiangkong_niao) { + niao_dianPao(owner, card); + } + else + niao_dianPao(owner, card); + } + + this.endGame(); + } + } + + @Override + public void endGame() { + boolean fengding = this.config.getBoolean(Config.ROOM_CONFIG_FENGDING); + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) { + List list = ((EXScore) player.score).hu_score; + for (EXScore.HUScore hu_score : list) { + int hu_num = hu_score.score; + int niao_num = hu_score.niao_score; + 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; + } + } + } + ((EXPlayBack)this.playBackData).addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.endGame(); + } + +// public void settleRound() { +// saveMilitaryRound(playBackData.getData()); +// boolean total = this.round >= this.maxRound; +// if(this.entrusResultType ==EXRoom.ENTRUST_CURREN_RESULT) { +// for (Entry entry : this.playerMapById.entrySet()) { +// if(entry.getValue().isEntrust()) { +// total = true; +// break; +// } +// } +// } +// if (!total) +// EXMainServer.gameCtr.roomResult(this); +// else { +// this.saveMilitaryTotal(false); +// } +// this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); +// this.winCount = 0; +// +// +// if (total) { +// this.stateMachine.changeState(Global.getState(RoomDestoryGameState.class)); +// return; +// } +// } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + @Override + protected void roomResult() { + ((EXPlayBack)this.playBackData).addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.winCount = this.piaoNiaoCount = 0; + this.niao.clear(); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/EXScore.java b/game_mj_hongzhong/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..1e7631c --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,45 @@ +package extend.mj; + +import com.game.data.Score; + +import java.util.ArrayList; +import java.util.List; + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int KONG = 2; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + + public List hu_score; + + public EXScore(EXPlayer owner){ + super(owner); + this.hu_score = new ArrayList<>(); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(KONG, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + if(this.hu_score!=null) + this.hu_score.clear(); + } + + public HUScore getHuScore(EXPlayer from){ + for(HUScore hu_score : hu_score){ + if(hu_score.player.playerid == from.playerid){ + return hu_score; + } + } + return null; + } + + + public static final class HUScore{ + public int score; + public EXPlayer player; + public int niao_score; + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/OpCard.java b/game_mj_hongzhong/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..32f8334 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,19 @@ +package extend.mj; + +public class OpCard { + public int type; + public int card; + public int seat; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + this.seat = 0; + } + + public OpCard(int type, int card, int seat) { + this.type = type; + this.card = card; + this.seat = seat; + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_hongzhong/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..f935748 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,103 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.RuleOtherKong; +import extend.mj.player.rule.RuleOtherWin; +import extend.mj.player.rule.RulePong; +import extend.mj.player.rule.RulePongKong; +import extend.mj.player.rule.RuleSelfKong; +import extend.mj.player.rule.RuleSelfWin; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.tip.IRuleBase; + +/** + * ����������� + * + * + * + * 2017��9��19�� PlayerRuleManager.java + */ +public class PlayerRuleManager { + + /** + * ����ץ�� + */ + public static final int DRAW_RULE = 1; + /** + * ���˳��� + */ + public static final int OTHER_DISCARD_RULE = 2; + /** + * ���ܺ����� + */ + public static final int KONG_HU_RULE = 3; + /** + * �������Ժ���ƹ��� + */ + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerKongWinState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerDrawTipState) Global.getState(EXPlayerDrawTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + cpDiscardRuleList.add(new RulePongKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/RoomCard.java b/game_mj_hongzhong/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..8c1688f --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,207 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.game.Global; + +import java.util.Random; +import extend.mj.uitl.WinCard; + + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + subCardList = new ArrayList<>(); + this.room = table; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + + private void initCard() { + + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + this.cardList.add(300 + index); + } + } + + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + boolean laizi8 = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG8); + if(laizi) { + int laiziNum = laizi8 ? 8 :4; + WinCard.zhongWinNum = laiziNum; + for(int i =0;i cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } + +// public int pop() { +// +// if (this.cardList.size() == 0) { +// this.room.bankerSeat = this.room.activeSeat; +//// this.room.roundSettle(); +// } +// +// int card = this.cardList.remove(0); +// +// return card; +// +// } + + public int pop() { + Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; +// this.room.roundSettle(); + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + // ���� + public List deal(boolean isw) { + List dealCards = new ArrayList(); + + + if (isw){ + + boolean laizi8 = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG8); + Random randomno = new Random(); + //boolean value = randomno.nextBoolean(); + if (laizi8){ + for (int ia = 0; ia<3;ia++){ + int indexhh = this.cardList.indexOf(Config.HONGZHONG); + //Global.logger.info("hongzhongid:"+indexhh+"card"+this.cardList); + dealCards.add(Config.HONGZHONG); + this.cardList.remove(indexhh); + Collections.shuffle(this.cardList); + } + + for (int index = 0; index < 10; index++) { + dealCards.add(this.pop()); + } + }else{ + int flag = 1; + //if (value){ + // flag = 2; + //} + for (int ia = 0; ia log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..fcf6da1 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,50 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + + int eventCard = room.activeCard; + if (eventCard == Config.HONGZHONG || player.isEntrust()) { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..ede798d --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,64 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(!player.forceCheckWin&&player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + /*if (!player.forceCheckWin&&!config.getBoolean(Config.ROOM_CONFIG_DIANPAO)&&!hz_hu) { + return false; + }*/ + if (!player.forceCheckWin&&!config.getBoolean(Config.ROOM_CONFIG_DIANPAOHU)){ + return false; + } + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + + int activieCard = room.activeCard; + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + WinCard win = new WinCard(player.cardInhand, room.activeCard, Config.HONGZHONG, laizi,qidui); + if(hz_hu&&win.zhong_count >0) { + return false; + } + if (win.checkQidui() || win.tryWin(room)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + player.tipMgr.addTip(tip); + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..48cf238 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == Config.HONGZHONG || player.isEntrust()) { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + if (Util.checkCard(tip.card, player.cardInhand, 3)) { + player.notPongKongList.add(tip.card); + } + player.stateMachine.changeState(Global.getState(PRPongState.class)); + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..6a36a2e --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,59 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + boolean result = false; + if (player.isEntrust()) { + return false; + } + for (int card : player.cardInhand) { + if(!player.notPongKongList.contains(card)) { + result = conditionCard(player, card) || result; + } + } + return result; + + } + + public boolean conditionCard(EXPlayer player, int card) { + + for (int[] cardGroup : player.pongGroup) { + if (card == cardGroup[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_PONG_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + return false; + + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..ff51846 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,56 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if (player.isEntrust()) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + if(card == Config.HONGZHONG)continue; + int num = entry.getValue(); + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..93b26b5 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,49 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + boolean laizi = config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + WinCard win = new WinCard(player.cardInhand, Config.HONGZHONG, laizi,qidui); + if (win.checkQidui() || win.tryWin(player.getRoom())) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..ad4facd --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,89 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PROtherKongState.java + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size()-1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + room.addScore(owner,activePlayer, 3,EXScore.KONG); + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(owner.getRoom().activeCard); + + + int [] kongGroup = new int [4]; + int card = room.activeCard; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + + owner.kongGroup.add(kongGroup); + owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, fromseat) ); + Util.removeCard(owner.cardInhand, card, 4); + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + owner.settleLog.add(Config.SETTLE_MING_KONG); +// owner.stateMachine.changeState( Global.getState(EXPlayerDrawState.class) ); + +// owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); +// if(room.tipMap.size() == 0){ + toNextState(owner); +// }else{ +// owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); +// } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..c893fa2 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,98 @@ +package extend.mj.player.rulestate; + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.*; + +import java.util.Map; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + int score = room.di_fen; + int qg_type = room.config.getInt(Config.ROOM_CONFIG_QG_TYPE); + if(qg_type == 0&&owner.winType == 1) { + score = room.di_fen * ( room.maxPlayers - 1); + } + room.addScore(owner,activePlayer, score,EXScore.WIN); + room.addPiaoNiaoScore(owner, activePlayer); + boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI); + boolean dianpaohu = room.config.getBoolean(Config.ROOM_CONFIG_DIANPAOHU); + if (dianpaohu){ + room.addScore(owner,activePlayer, score,EXScore.WIN); + room.addPiaoNiaoScore(owner, activePlayer); + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer gangPlayer = (EXPlayer) entry.getValue(); + for(int i = 0; i < gangPlayer.opCardList.size(); i++) + { + OpCard op_card = gangPlayer.opCardList.get(i); + if (op_card.type == RuleWeight.TYPE_SELF_KONG) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat == 0) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat > 0) + { + EXPlayer activePlayer2 = (EXPlayer)room.playerMapBySeat.get(op_card.seat); + room.addScore(gangPlayer,activePlayer2, 3,EXScore.KONG); + } + } + } + } + if (wuguijiabei && room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { + if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) { + room.addScore(owner,activePlayer, score,EXScore.WIN); + room.addPiaoNiaoScore(owner, activePlayer); + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer gangPlayer = (EXPlayer) entry.getValue(); + for(int i = 0; i < gangPlayer.opCardList.size(); i++) + { + OpCard op_card = gangPlayer.opCardList.get(i); + if (op_card.type == RuleWeight.TYPE_SELF_KONG) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat == 0) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat > 0) + { + EXPlayer activePlayer2 = (EXPlayer)room.playerMapBySeat.get(op_card.seat); + room.addScore(gangPlayer,activePlayer2, 3,EXScore.KONG); + } + } + } + } + } + activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO); + activePlayer.winer = 2; + + owner.settleLog.add(Config.SETTLE_JIE_PAO); + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + room.bankerSeat = owner.seat; + room.winCount += 1; + owner.winer = 1; + owner.winCard = room.activeCard; + + room.winCallback( owner ,owner.winCard); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongKongState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongKongState.java new file mode 100644 index 0000000..070f652 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongKongState.java @@ -0,0 +1,77 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.uitl.CardUtil; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRPongKongState.java + */ +public class PRPongKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + CardUtil.removeGroup(owner.pongGroup, card); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_PONG, card)); + + int[] kong = new int[4]; + kong[0] = card; + kong[1] = card; + kong[2] = card; + kong[3] = card; + owner.kongGroup.add(kong); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard); + + room.activeCard = card; + boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG); + if(qiangkong) { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + toNextState(owner); + } + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.settleLog.add(Config.SETTLE_MING_KONG); + owner.getRoom().addAllScore(owner, 3, EXScore.KONG); + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..5d82b46 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,67 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PRPongState.java + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..f4d8a9f --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,53 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRSelfKongState.java + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + owner.selfKongGroup.add(kongGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + + room.addAllScore(owner, 3, EXScore.KONG); + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + owner.settleLog.add(Config.SETTLE_AN_KONG); + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..d7e0ccf --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,119 @@ +package extend.mj.player.rulestate; + + +import java.util.Map.Entry; + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.*; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + Util.removeCard(owner.cardInhand, owner.winCard, 1); + room.addAllScore(owner, room.di_fen,EXScore.WIN); + room.addAllPiaoNiaoScore(owner); + boolean jiabei = true; + boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); + if (wuguijiabei && room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) + { + if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0 && owner.drawCard != Config.HONGZHONG) + { + room.addAllScore(owner, room.di_fen,EXScore.WIN); + room.addAllPiaoNiaoScore(owner); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer gangPlayer = (EXPlayer) entry.getValue(); + for(int i = 0; i < gangPlayer.opCardList.size(); i++) + { + OpCard op_card = gangPlayer.opCardList.get(i); + if (op_card.type == RuleWeight.TYPE_SELF_KONG) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat == 0) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat > 0) + { + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(op_card.seat); + room.addScore(gangPlayer,activePlayer, 3,EXScore.KONG); + } + } + } + } + } + + boolean dianpaohu = room.config.getBoolean(Config.ROOM_CONFIG_DIANPAOHU); + if (dianpaohu){ + room.addAllScore(owner, room.di_fen,EXScore.WIN); + room.addAllPiaoNiaoScore(owner); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer gangPlayer = (EXPlayer) entry.getValue(); + for(int i = 0; i < gangPlayer.opCardList.size(); i++) + { + OpCard op_card = gangPlayer.opCardList.get(i); + if (op_card.type == RuleWeight.TYPE_SELF_KONG) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat == 0) + { + room.addAllScore(gangPlayer, 3, EXScore.KONG); + } + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat > 0) + { + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(op_card.seat); + room.addScore(gangPlayer,activePlayer, 3,EXScore.KONG); + } + } + } + } + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + room.niao_selfWin(owner,owner.winCard ); + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.endGame(); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..2e3d968 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ��ҳ�����ʾ״̬ + * + * + * 2017��8��30�� + * EXPlayerDisCardTipState.java + */ +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..c360325 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,146 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +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.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.room.state.EXRoomSetpState; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * �ȴ���ҳ���״̬ + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.louhu = false; + EXMainServer.gameCtr.outCard(owner, discard); + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_TIMER_AUTO: + owner.louhu = false; + discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + if(discard == Config.HONGZHONG) { + for (Integer card : owner.cardInhand) { + if(card !=Config.HONGZHONG) { + discard = card; + break; + } + } + } + EXMainServer.gameCtr.outCard(owner, discard); + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..1f0bbc4 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,226 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.card.cardList.size() == 0) { + room.liuju = true; + room.endGame(); + return; + + } + + ITObject config = room.config; + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + + WinCard win = new WinCard(owner.cardInhand, drawCard, Config.HONGZHONG, laizi,qidui); + if(!(hz_hu && win.zhong_count >0)) { + if (win.checkQidui() || win.tryWin(room)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(!IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + if(owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white_value:"+owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black_value:"+owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else { + owner.drawCard = room.card.pop(); + } + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + + private boolean IsGoodCard(EXPlayer player, int drawCard, boolean qidui, boolean hz_hu, boolean laizi) { + if (drawCard == Config.HONGZHONG) + { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + for (int[] cardGroup : player.pongGroup) { + if (drawCard == cardGroup[0]) { + return true; + } + } + + WinCard win = new WinCard(player.cardInhand, drawCard, Config.HONGZHONG, laizi,qidui); + if(!(hz_hu && win.zhong_count >0)) { + if (win.checkQidui() || win.tryWin(player.getRoom())) { + return true; + } + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } + + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..f2b5baf --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,43 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ���ץ����ʾ״̬ + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ; + if(Global.gameId == 1 && win && id == 0)return; + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..441c172 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,42 @@ +package extend.mj.player.state; + +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * ���������ʾ�ȴ� + * + * + * 2017��8��30�� + * EXPlayerKongWinState.java + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..1263fff --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * Ʊ����ʾ״̬ + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoNiaoTipEvent(owner); + owner.startActionTimer(); + }else{ + _action(owner, 0, 0); + } + } + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piaoNiao = id; + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + } + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..fad0cea --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,49 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * �����ʾ������� + * + * + * 2017��8��30�� + * EXPlayerTipState.java + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tipEvent(owner); + } + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if(cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..dff6a34 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,24 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * ������ҵȴ��������ǹ�ܺ� + * + * + * 2017��8��30�� + * EXPlayerWaitKongWinState.java + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..858aee0 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,39 @@ +package extend.mj.player.state; + + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * ��ҵȴ�״̬ + * + * + * 2017��8��30�� + * EXPlayerWaitState.java + */ +public class EXPlayerWaitState extends StateBase { + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.forceCheckWin = true; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + owner.forceCheckWin = false; + break; + default: + break; + } + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..974856b --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,148 @@ +package extend.mj.room.state; + +import java.util.Map.Entry; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import com.taurus.permanent.TPServer; +import extend.mj.*; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; + +/** + * ���䷢��״̬ + * + * + * 2017��8��30�� + * EXRoomDealState.java + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + //随机定庄 + Random random = new Random(); + owner.bankerSeat = random.nextInt(2) + 1; + } +// owner.isplaying = true; +// owner.round += 1; + + int piao_niao = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO); + if(piao_niao > 0) { + if(piao_niao == 1) { + owner.piaoNiaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + else if (piao_niao == 2) + { + owner.piaoNiaoCount = 0; + int opt = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO_OPT); + int piao_fen = 1; + if (opt == 0) + { + piao_fen = 1; + } + else if (opt == 1) + { + piao_fen = 2; + } + else if (opt == 2) + { + piao_fen = 3; + } + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.piaoNiao = piao_fen; + player.tipMgr.clean(); + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + player.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(player); + } + this.toNextState(owner); + } + else { + this.toNextState(owner); + } + } else { + this.toNextState(owner); + } + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) { + if(owner.piaoNiaoCount==0) { + this.toNextState(owner); + } + } + + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..47fbd44 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,42 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ����ת����λ + * + * + * 2017��8��30�� + * EXRoomSetpState.java + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + this.toNextState(owner); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..1272100 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,33 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * ���俪ʼ״̬ + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/tip/Action.java b/game_mj_hongzhong/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..454d9ca --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + + */ +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_hongzhong/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..79f1ab8 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * ����������� + * + * + * 2017��8��30�� + * RuleBase.java + */ +public interface IRuleBase { + + /** + * ������� + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * ִ�иù��� + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/tip/Tip.java b/game_mj_hongzhong/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..434343a --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,40 @@ +package extend.mj.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +/** + * tip������ + * + * + * + * 2017��8��30�� Tip.java + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int winType; + public int type; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/tip/TipManager.java b/game_mj_hongzhong/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..b8361ec --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,125 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.EXPlayer; +import extend.mj.RuleWeight; + +/** + * + * + * + * 2017��9��18�� TipManager.java + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + private void checkLouhu() { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + + public void choicAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_hongzhong/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..6d95053 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,32 @@ +package extend.mj.uitl; + +import java.util.List; + +import extend.mj.OpCard; + +public class CardUtil { + + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card == opcards.get(i).card) { + opcards.remove(i); + return; + } + + } + + } + +} diff --git a/game_mj_hongzhong/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_hongzhong/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..f51e9c6 --- /dev/null +++ b/game_mj_hongzhong/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,363 @@ +package extend.mj.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import com.game.Util; +import extend.mj.Config; +import extend.mj.EXRoom; + +public class WinCard { + + public int pair_count; + public Stack> stack; + public List cardList; + public int zhong_count; + public int zhongid = 0; + public boolean qidui; + public static int zhongWinNum = 4; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + if (card == zhongid) { + this.zhong_count += 1; + } else { + this.cardList.add(card); + } + } + Collections.sort(this.cardList); + } + + private boolean tryShunzi(int card) { + if (card < 400 && card % 100 > 7) { + return false; + } + if (Util.checkCard(card + 1, this.cardList) && Util.checkCard(card + 2, this.cardList)) { + Util.removeCard(this.cardList, card, 1); + Util.removeCard(this.cardList, card + 1, 1); + Util.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryKezi(int card) { + + if (Util.checkCardAndRomve(card, this.cardList, 3)) { +// CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + + if (Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + return true; + } + return false; + + } + + private boolean tryKezi1Zhong(int card) { + + if (this.zhong_count >= 1 && Util.checkCardAndRomve(card, this.cardList,2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.zhong_count -= 1; + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryKezi2Zhong(int card) { + + if (this.zhong_count >= 2 && Util.checkCardAndRomve(card, this.cardList,1)) { +// CardUtil.removeCard(this.cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(this.zhongid); + this.zhong_count -= 2; + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryShunzi1Zhong(int card) { + if (card % 100 > 8) { + return false; + } + + if (this.zhong_count < 1) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 1, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(this.zhongid); + this.push(cardGroup); + return true; + } + + if (Util.checkCard(card + 2, this.cardList) && ((card + 1) % 100 != 0)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 2, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + + return false; + + } + + private boolean tryPair1Zhong(int card) { + + if (this.pair_count > 0) { + return false; + } + if (this.zhong_count < 1) { + return false; + } + Util.removeCard(cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.zhong_count -= 1; + this.pair_count = 1; + return true; + + } + + private boolean tryPair2Zhong() { + + if (this.pair_count > 0) { + return false; + } + if (this.zhong_count < 2) { + return false; + } + List cardGroup = new ArrayList(); + cardGroup.add(this.zhongid); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.pair_count = 1; + this.zhong_count -= 2; + return true; + } + + public boolean tryWin(EXRoom room) { + if (room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU)) + { + if (this.zhong_count == zhongWinNum) { + return true; + } + } + + if (this.cardList.size() == 0 && this.pair_count == 1) { + return true; + } + if (this.cardList.size() == 0 && this.pair_count == 0) { + return tryPair2Zhong(); + } + + if (this.cardList.size() == 0) { + return false; + } + int activeCard = this.cardList.get(0); + + if (tryPair(activeCard)) { + if (tryWin(room)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + + } + + if (tryKezi(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryShunzi(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + + if (tryKezi1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryKezi2Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryShunzi1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryPair1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + return false; + } + + public WinCard(List cardInhand, int addCard, int zhongid, boolean isZhong, boolean qidui) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.qidui = qidui; + this.cardList.add(addCard); + if (isZhong) { + this.zhongid = zhongid; + this.zhong_count = Util.cardNum(zhongid, this.cardList); + Util.removeCard(this.cardList, zhongid, this.zhong_count); + } + Collections.sort(this.cardList); + } + + public WinCard(List cardInhand, int zhongid, boolean isZhong, boolean qidui) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.qidui = qidui; + this.cardList.addAll(cardInhand); + if (isZhong) { + this.zhongid = zhongid; + this.zhong_count = Util.cardNum(zhongid, this.cardList); + Util.removeCard(this.cardList, zhongid, this.zhong_count); + } + Collections.sort(this.cardList); + + } + + public boolean checkQidui() { + if (!this.qidui) + return false; + if ((this.cardList.size() + zhong_count) != 14) + return false; + List cardlist = new ArrayList<>(); + cardlist.addAll(this.cardList); + hongzhong_count = this.zhong_count; + return isQdPari(cardlist); + } + + private int hongzhong_count = 0; + private int qidui_pari_count = 0; + boolean isQdPari(List cardlist) { + if(qidui_pari_count == 7)return true; + if (cardlist.size() == 0)return true; + int card = cardlist.get(0); + if (Util.cardNum(card, cardlist) >= 2) { + Util.removeCard(cardlist, card, 2); + qidui_pari_count++; + if (isQdPari(cardlist)) { + return true; + } + } + + if (this.hongzhong_count > 0) { + Util.removeCard(cardlist, card, 1); + this.hongzhong_count--; + qidui_pari_count++; + if (isQdPari(cardlist)) { + return true; + } + } + return false; + + } + + public static void main(String[] args) { + + + long time = System.currentTimeMillis(); +// for(int i=0;i<1000000;++i) { + ArrayList cardInhand = new ArrayList(); + cardInhand.add(101); + cardInhand.add(102); + cardInhand.add(103); + cardInhand.add(104); + cardInhand.add(105); + cardInhand.add(106); + + cardInhand.add(204); + cardInhand.add(205); + cardInhand.add(206); + cardInhand.add(201); + cardInhand.add(202); + cardInhand.add(203); + + cardInhand.add(301); + cardInhand.add(301); + cardInhand.add(301); + cardInhand.add(108); + WinCard win = new WinCard(cardInhand,45,45,true,false); +// } + System.out.println( System.currentTimeMillis() - time); + } + +} diff --git a/game_mj_hongzhong/src/test/java/game_mj_hongzhong/Main.java b/game_mj_hongzhong/src/test/java/game_mj_hongzhong/Main.java new file mode 100644 index 0000000..cd2c372 --- /dev/null +++ b/game_mj_hongzhong/src/test/java/game_mj_hongzhong/Main.java @@ -0,0 +1,9 @@ +package game_mj_hongzhong; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_nanxian/config/game-config.xml b/game_mj_nanxian/config/game-config.xml new file mode 100644 index 0000000..c2bd6fe --- /dev/null +++ b/game_mj_nanxian/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.1.6 + 192.168.1.6 + 8991 + 8991 + 11 + true + \ No newline at end of file diff --git a/game_mj_nanxian/config/log4j.properties b/game_mj_nanxian/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_nanxian/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_nanxian/config/taurus-core.xml b/game_mj_nanxian/config/taurus-core.xml new file mode 100644 index 0000000..6e51965 --- /dev/null +++ b/game_mj_nanxian/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_nanxian/config/taurus-permanent.xml b/game_mj_nanxian/config/taurus-permanent.xml new file mode 100644 index 0000000..d125fc4 --- /dev/null +++ b/game_mj_nanxian/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_nanxian/pom.xml b/game_mj_nanxian/pom.xml new file mode 100644 index 0000000..bfd8ea4 --- /dev/null +++ b/game_mj_nanxian/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_nanxian + 1.0.0 + jar + + game_mj_nanxian + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_nanxian + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_nanxian/src/main/java/extend/mj/CardNiao.java b/game_mj_nanxian/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..133e619 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/CardNiao.java @@ -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; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/Config.java b/game_mj_nanxian/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..4f1b706 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/Config.java @@ -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_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 String ROOM_CONFIG_KAN_CHI = "kan_chi"; // + public static final String ROOM_CONFIG_HAIDI_JIAFEN = "haidi_jiafen"; //海底加两分 + public static final String ROOM_CONFIG_GANGBAO_JIAFEN = "gangbao_jiafen"; //杠爆加两分 + + + 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"; +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXActionEvent.java b/game_mj_nanxian/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..7a47b0c --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXActionEvent.java @@ -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"; + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXGameController.java b/game_mj_nanxian/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..cc58ce4 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXGameController.java @@ -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 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(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 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 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 entry : tip.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i map) + { + int count = 0; + for (Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + if (isDaHu(wct.type)) + { + for(int i = 0;i entry : tip.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i 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 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 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); + + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXMainServer.java b/game_mj_nanxian/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..1d9105c --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXMainServer.java @@ -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 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(); + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXPlayBack.java b/game_mj_nanxian/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..8e4ea16 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXPlayBack.java @@ -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); + } + + + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXPlayer.java b/game_mj_nanxian/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..59449bf --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXPlayer.java @@ -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 cardInhand; + + + public List outcardList; + + public ITArray opCard; + + public List 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 winMap; + + public OpenKong openKong; + public Set llsCardRecord; + public int piaoNiao = 0; + + public int win_count; + public boolean fengding; + public List 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(); + + 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; + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXRoom.java b/game_mj_nanxian/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..eeae482 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,779 @@ +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 tipMap; + public List actionList; + public List 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 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 redis_room_map) { + super(roomid, redis_room_map); + + if (!this.config.containsKey(Config.ROOM_CONFIG_HAIDI_JIAFEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAIDI_JIAFEN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NO_JIANG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_NO_JIANG, true); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGBAO_JIAFEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGBAO_JIAFEN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZIMO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZIMO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZT_LIULIUSHUN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZT_LIULIUSHUN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZT_DASIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZT_DASIXI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QS_JIEJIEGAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QS_JIEJIEGAO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QS_SANTONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QS_SANTONG, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QS_YIZHIHUA)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QS_YIZHIHUA, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QUEYIMEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUEYIMEN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_TYPE)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO_TYPE, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_KAN_CHI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_KAN_CHI, false); + } + + 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(); + this.actionList = new ArrayList(); + this.actionWinList = new ArrayList(); + this.niao = new ArrayList(); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry 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 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 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 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 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 winPlayerList = new ArrayList(); + for (Entry 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 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 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 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 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 list, int card) { + CardNiao cn = new CardNiao(); + cn.card = card; + list.add(cn); + int tem = card % 100; + for (Entry 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 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 tlist = new ArrayList(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 entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) { + List 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(); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/EXScore.java b/game_mj_nanxian/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..48b58fc --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,52 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.game.data.Score; + + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int QS = 2; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + + public List hu_score; + + public EXScore(EXPlayer owner){ + super(owner); + this.hu_score = new ArrayList<>(); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(QS, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + if(this.hu_score!=null) + this.hu_score.clear(); + } + + public HUScore getHuScore(EXPlayer from){ + for(HUScore hu_score : hu_score){ + if(hu_score.player.playerid == from.playerid){ + return hu_score; + } + } + return null; + } + + + public static final class HUScore{ + public int score; + public EXPlayer player; + public int niao_double_num; + public int niao_score; + public Map qs_score_map = new HashMap(); + } + + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/OpCard.java b/game_mj_nanxian/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..3767cde --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,15 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; + +public class OpCard { + public int type; + public int card; + + public ITArray opCard; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/OpenKong.java b/game_mj_nanxian/src/main/java/extend/mj/OpenKong.java new file mode 100644 index 0000000..ec3a748 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/OpenKong.java @@ -0,0 +1,53 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +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.uitl.CardUtil; + +public class OpenKong { + + public int diceNum1; + public int diceNum2; + + /** + * + */ + public int fromSeat; + + + public int kongSeat; + public List drawList; + + public boolean haidi; + + public int tipActionSeat = -1; + + public OpenKong() { + drawList = new ArrayList(); + + diceNum1 = CardUtil.randomDiceNum(); + diceNum2 = CardUtil.randomDiceNum(); + } + + public ITObject getTObject() { + ITObject data = TObject.newInstance(); + data.putInt("diceNum1", diceNum1); + data.putInt("diceNum2", diceNum2); + + data.putInt("from_seat", fromSeat); + data.putInt("kong_seat", kongSeat); + + ITArray cardList = TArray.newInstance(); + for (int card : drawList) { + cardList.addInt(card); + } + data.putTArray("cardList", cardList); + return data; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_nanxian/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..817e56d --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,143 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.RuleChow; +import extend.mj.player.rule.RuleHaidi; +import extend.mj.player.rule.RuleOtherKong; +import extend.mj.player.rule.RuleOtherOpenKong; +import extend.mj.player.rule.RuleOtherWin; +import extend.mj.player.rule.RulePong; +import extend.mj.player.rule.RulePongKong; +import extend.mj.player.rule.RulePongOpenKong; +import extend.mj.player.rule.RuleQSWin; +import extend.mj.player.rule.RuleSelfKong; +import extend.mj.player.rule.RuleSelfOpenKong; +import extend.mj.player.rule.RuleSelfWin; +import extend.mj.player.rule.RuleZTWin; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerHaidiTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerQSWinTipState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.player.state.EXPlayerZTWinTipState; +import extend.mj.tip.IRuleBase; + +/** + * + */ +public class PlayerRuleManager { + + + public static final int DRAW_RULE = 1; + + public static final int OTHER_DISCARD_RULE = 2; + + public static final int KONG_HU_RULE = 3; + + public static final int QS_HU_RULE = 4; + + public static final int OPENKONG_RULE = 5; + + public static final int HAIDI_RULE = 6; + + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public static final int ZT_HU_RULE = 8; + + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.QS_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerQSWinTipState.class)); + tipMap.put(PlayerRuleManager.OPENKONG_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.HAIDI_RULE, (EXPlayerTipState) Global.getState(EXPlayerHaidiTipState.class)); + tipMap.put(PlayerRuleManager.ZT_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerZTWinTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RuleSelfOpenKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RulePongOpenKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleChow()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RuleOtherOpenKong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List qshuList = new ArrayList(); + qshuList.add(new RuleQSWin()); + ruleMap.put(PlayerRuleManager.QS_HU_RULE, qshuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + cpDiscardRuleList.add(new RuleSelfOpenKong()); + cpDiscardRuleList.add(new RulePongKong()); + cpDiscardRuleList.add(new RulePongOpenKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + List openkongList = new ArrayList(); + openkongList.add(new RuleChow()); + openkongList.add(new RulePong()); + openkongList.add(new RuleOtherKong()); + openkongList.add(new RuleOtherOpenKong()); + openkongList.add(new RulePongOpenKong()); + openkongList.add(new RuleOtherWin()); + openkongList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.OPENKONG_RULE, openkongList); + + List haidiList = new ArrayList(); + haidiList.add(new RuleHaidi()); + ruleMap.put(PlayerRuleManager.HAIDI_RULE, haidiList); + + List zthuList = new ArrayList(); + zthuList.add(new RuleZTWin()); + ruleMap.put(PlayerRuleManager.ZT_HU_RULE, zthuList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + player.getRoom().actionWinList.clear(); + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/QSLog.java b/game_mj_nanxian/src/main/java/extend/mj/QSLog.java new file mode 100644 index 0000000..a93f5f0 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/QSLog.java @@ -0,0 +1,30 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class QSLog { + public int score; + public int niao_score; + public List niaoList = new ArrayList(2); + + public ITArray winMap; + + public ITObject toMP() { + ITObject p = TObject.newInstance(); + p.putInt("score", score); + p.putInt("niao_score", niao_score); + ITArray niao = new TArray(); + for (int index = 0; index < niaoList.size(); index++) { + niao.addTObject(niaoList.get(index).toMP()); + } + p.putTArray("niao", niao); + p.putTArray("win_list", winMap); + return p; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/RoomCard.java b/game_mj_nanxian/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..ce33240 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,336 @@ +package extend.mj; + +import java.util.*; + +import com.game.Global; +import com.game.Util; + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + //this.initCard2(); + } + + private void initCard2() { + List list = Arrays.asList(109, 109, 109, 207, 207, 207, 105, 106, 107, 202, 202, 203, 204); + List list2 = Arrays.asList(209, 209, 209, 206, 206, 203, 203, 208, 208, 208, 202, 202, 202); + List list3 = Arrays.asList(208, 201, 202, 103, 107, 107, 205, 208, 209, 207, 109, 203, 208, 104, 210, 106, 104, 107, 202, 105, 206, 206, 109, 202, 209, 210, 104, 206, 107, 101, 108, 210, 203, 101, 102, 106, 209); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + + private void initCard() { + boolean queyimen = this.room.config.getBoolean(Config.ROOM_CONFIG_QUEYIMEN); + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(200 + index); + this.cardList.add(300 + index); + if(!queyimen) { + this.cardList.add(100 + index); + } + } + } + +// this.cardList.add(207); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); +// this.cardList.add(103); + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public int pop() { + //Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } +// this.room.roundSettle(); + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; +// this.room.roundSettle(); + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + private boolean IsGoodCard(List dealCards, int drawCard) { + if (Util.cardNum(drawCard, dealCards) >= 2) + { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, dealCards) >= 1 && Util.cardNum(drawCard+2, dealCards) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, dealCards) >= 1 && Util.cardNum(drawCard-2, dealCards) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, dealCards) >= 1 && Util.cardNum(drawCard+1, dealCards) >= 1) + { + return true; + } + } + } + + return false; + } + + // 发牌 + public List deal(EXPlayer owner, int num) { + List dealCards = new ArrayList<>(); + shuffle(); + + for (int index = 0; index < num ; index++) { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(dealCards.size() > 0 && !IsGoodCard(dealCards, drawCard)) { + if (room.card.cardList.size() != 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + dealCards.add(drawCard); + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else { + if (owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:" + owner.playerid + " white player:" + owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } else if (owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + Global.logger.info("dealcards playerid:" + owner.playerid + " black player:" + owner.black_white_rate); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } else { + if (room.while_list && !owner.is_white && rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (dealCards.size() > 0 && IsGoodCard(dealCards, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + dealCards.add(drawCard); + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + dealCards.add(room.card.pop()); + } + } + } + } + + return dealCards; + } + + public List deal(int num) { + List dealCards = new ArrayList(); + + for (int index = 0; index < num; index++) { + dealCards.add(this.pop()); + } + +// if(num == 14) { +// dealCards.add(104); +// } +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// +// +// dealCards.add(104); + return dealCards; + + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/RuleWeight.java b/game_mj_nanxian/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..01f9beb --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,55 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 1; + public final static int PONG = 2; + + public final static int KONG = 4; + + public final static int SELF_KONG = 8; + + public final static int WIN = 16; + + public final static int SELF_WIN = 32; + + public final static int GROUP_CHOW = 1; + public final static int GROUO_PONG = 2; + public final static int GROUO_KONG = 3; + public final static int GROUO_OPENKONG = 4; + public final static int GROUO_WIN = 5; + public final static int GROUO_QSWIN = 6; + public final static int GROUO_HAIDI = 7; + public final static int GROUO_ZTWIN = 8; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_PONG_KONG = 5; + public final static int TYPE_WIN = 6; + public final static int TYPE_QSWIN = 7; + public final static int TYPE_ZTWIN = 8; + + + public final static int TYPE_LIULIUSHUN = 21; + + public final static int TYPE_DASIXI = 22; + + public final static int TYPE_QUEYISE = 23; + + public final static int TYPE_BANBANHU = 24; + + public final static int TYPE_JIEJIEGAO = 25; + + public final static int TYPE_SANTONG = 26; + + public final static int TYPE_YIZHIHUA = 27; + + public final static int TYPE_ZT_LIULIUSHUN = 28; + + public final static int TYPE_ZT_DASIXI = 29; + + public final static int TYPE_QTYN = 30; + +} + diff --git a/game_mj_nanxian/src/main/java/extend/mj/SettleLog.java b/game_mj_nanxian/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/WinCardType.java b/game_mj_nanxian/src/main/java/extend/mj/WinCardType.java new file mode 100644 index 0000000..6179bc0 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/WinCardType.java @@ -0,0 +1,94 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class WinCardType { + + public static final int QIXIAODUI = 1; //七小对多少分? + + public static final int JIANGJIANGHU = 2; //将将胡多少分? + + public static final int QINGYISE = 3; //清一色多少分? + + public static final int PENGPENGHU = 4; //碰碰胡多少分? + + public static final int GANGSHANGHUA = 5; //杠上花多少分? + + public static final int GANGSHANGPAO = 6; //杠上炮多少分? + + public static final int QUANQIUREN = 7; //全求人多少分? + + public static final int HAIDI = 8; //海底多少分? + + public static final int HAIDIPAO = 9; //海底炮多少分? + + public static final int QIANG_GANG_HU =10; //抢杠胡? + + public static final int XIAOHU = 11; + + public final static int TYPE_TIANHU = 12; + + public final static int TYPE_TIANTINGHU = 13; + + public final static int TYPE_MENQING = 14; + + public final static int TYPE_LIULIUSHUN = 21; + + public final static int TYPE_DASIXI = 22; + + public final static int TYPE_QUEYISE = 23; + + public final static int TYPE_BANBANHU = 24; + + public final static int TYPE_JIEJIEGAO = 25; + + public final static int TYPE_SANTONG = 26; + + + public final static int TYPE_YIZHIHUA = 27; + + public final static int WIN_TYPE_SCORE = 7; + public final static int WIN_PING_TYPE_SCORE = 3; + public final static int PENG_PENG_HU_SCORE = 5; + public final static int JIANG_JIANG_HU_SCORE = 8; + public final static int JIANG_JIANG_HU_PENG_PENG_HU_SCORE = 2; //10 + public final static int QI_XIAO_DUI_HU_SCORE = 8; + public final static int QING_YI_SE_HU_SCORE = 8; + public final static int QING_YI_SE_HU_PENG_PENG_HU_SCORE = 5; + public final static int QUAN_QIU_REN_HU_SCORE = 10; + + public int type; + + public int value; + + public int score; + + public ITArray opcard; + + public WinCardType(int type, int value,int score) { + this.type = type; + this.value = value; + this.score = score; + } + + public ITObject toTObject() { + return toTObject(false); + } + + public ITObject toTObject(boolean is_opcard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", type); + obj.putInt("value", value); + if(is_opcard&&opcard!=null) { + obj.putTArray("opcard", opcard); + } + return obj; + } + + public String toString() { + return "type:" + type + " value:" + value; + + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleChow.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleChow.java new file mode 100644 index 0000000..2ecfeb1 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleChow.java @@ -0,0 +1,97 @@ +package extend.mj.player.rule; + +import java.util.List; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRChowState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����״̬ + * + * + * 2017��11��2�� + * PRChowRule.java + */ +public class RuleChow implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if (player.room.config.getBoolean(Config.ROOM_CONFIG_KAN_CHI) == false) return false; + + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (player.lastSeat != room.activeSeat) { + return false; + } + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + if(room.activeKong.kongSeat == player.seat)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + boolean result = false; + List cardInhand = player.cardInhand; + if (Util.checkCard(eventCard - 1, cardInhand) && Util.checkCard(eventCard - 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard - 1); + opcard.addInt(eventCard - 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard - 1, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard - 1); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + + if (Util.checkCard(eventCard + 1, cardInhand) && Util.checkCard(eventCard + 2, cardInhand)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard + 1); + opcard.addInt(eventCard + 2); + Tip tip = new Tip(eventCard,opcard, RuleWeight.CHOW,this, RuleWeight.TYPE_CHOW); + tip.group_type = RuleWeight.GROUP_CHOW; + player.tipMgr.addTip(tip); + result = result || true; + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRChowState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleHaidi.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleHaidi.java new file mode 100644 index 0000000..036ab06 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleHaidi.java @@ -0,0 +1,37 @@ +package extend.mj.player.rule; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���׼�� + * + * + * 2017��11��8�� + * RuleHaidi.java + */ +public class RuleHaidi implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + if (room.card.getCount() == 1) { + player.tipMgr.clean(); + room.tipMap.clear(); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..5fd5971 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,67 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ +// if(room.activeKong.kongSeat == player.seat)return false; + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + if (Util.checkCard(eventCard, player.cardInhand,3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java new file mode 100644 index 0000000..f0e6c08 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherOpenKong.java @@ -0,0 +1,76 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * �����ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + + if (Util.checkCardAndRomve(eventCard, player.cardInhand,3)) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + try { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,eventCard,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + return true; + } + }finally { + Util.addCard(player.cardInhand, eventCard, 3); + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PROtherOpenKongState.class)); + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..ce81fec --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,108 @@ +package extend.mj.player.rule; + +import java.util.HashMap; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.player.rulestate.PRPongOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���Ƽ�� + * + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + boolean zimo = room.config.getBoolean(Config.ROOM_CONFIG_ZIMO); + if(!zimo&&player.louhu)return false; + if(room.activeSeat == player.seat)return false; + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + boolean qiang_kong = activePlayer.stateMachine.curState instanceof PRPongOpenKongState; + OpenKong ok = room.activeKong; + boolean result = false; + ITArray opcard = TArray.newInstance(); + HashMap map = new HashMap(); + if (ok != null) { + for (int card : ok.drawList) { + if (Paixing.checkWin(map, player.opCardList, player.cardInhand, card,!no_jiang, room.difen_score)) { + Paixing.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.WIN_TYPE_SCORE); + map.remove(WinCardType.XIAOHU); + result = true; + opcard.addInt(card); + } + } + } else { + boolean jiang = no_jiang; + //if(no_jiang&&(qiang_kong ||room.activeHaidi)) { + // jiang = false; + //} + result = Paixing.checkWin(map, player.opCardList, player.cardInhand, room.activeCard,jiang, room.difen_score); + opcard.addInt(room.activeCard); + } + if (result) { + if (room.activeHaidi) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.HAIDIPAO, new WinCardType(WinCardType.HAIDIPAO, 1,WinCardType.WIN_TYPE_SCORE)); + } + + boolean menqing = room.config.getBoolean("menqing"); + if(menqing) { + boolean m_r = true; + for (OpCard oc : player.opCardList) { + if(oc.type !=RuleWeight.TYPE_SELF_KONG) { + m_r = false; + break; + } + } + if(m_r) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_MENQING, new WinCardType(WinCardType.TYPE_MENQING, 1,WinCardType.WIN_TYPE_SCORE)); + } + } + + if(qiang_kong) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.QIANG_GANG_HU, new WinCardType(WinCardType.QIANG_GANG_HU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + if(player.tianting) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANTINGHU, new WinCardType(WinCardType.TYPE_TIANTINGHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + if(zimo&&map.containsKey(WinCardType.XIAOHU))return false; + + Tip tip = new Tip(opcard.getInt(0),opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.group_type = RuleWeight.GROUO_WIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + } + + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeCard = tip.card; + player.winMap = tip.winMap; + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..1bbdd22 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,70 @@ +package extend.mj.player.rule; + +import java.util.ArrayList; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.haidi)return false; + if(room.activeKong.kongSeat == player.seat)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card) || result; + } + }else{ + int eventCard = room.activeCard; + result = check(player,eventCard); + } + + return result; + } + + private boolean check(EXPlayer player,int eventCard){ + if (Util.cardNum(eventCard, player.cardInhand) >= 2) { + ArrayList opCard = new ArrayList<>(); + opCard.add(eventCard); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard,opcard, RuleWeight.PONG,this, RuleWeight.TYPE_PONG); + tip.group_type = RuleWeight.GROUO_PONG; + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.getRoom().activeKong = null; + player.getRoom().activeCard = tip.card; + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..25cf94f --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,60 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + + boolean result = false; + for (int card : player.cardInhand) { + result = check(player, card) || result; + } + + return result; + } + + private boolean check(EXPlayer player, int card) { + for (OpCard opc : player.opCardList) { + if (opc.type == RuleWeight.TYPE_PONG && card == opc.card) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_PONG_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + return true; + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongOpenKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongOpenKong.java new file mode 100644 index 0000000..d7d2cf9 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RulePongOpenKong.java @@ -0,0 +1,89 @@ +package extend.mj.player.rule; + +import java.util.ArrayList; +import java.util.List; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ܿ��ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if (room.activeHaidi) { + return false; + } + if(player.tianting)return false; + + boolean result = false; + if(room.activeKong!=null){ + if(room.activeKong.kongSeat != player.seat)return false; + if(room.activeKong.haidi)return false; + for (int card : room.activeKong.drawList) { + result = check(player,card,false) || result; + } + }else{ + List cardList = new ArrayList<>(); + cardList.addAll(player.cardInhand); + if(player.autoOutCard) { + int card = player.drawCard; + result = check(player, card,true); + }else { + for (int card : cardList) { + result = check(player, card,true) || result; + } + } + + } + return result; + } + + private boolean check(EXPlayer player, int card,boolean remove) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + for (OpCard opc : player.opCardList) { + if (opc.type == RuleWeight.TYPE_PONG && card == opc.card) { + if(remove)Util.removeCard(player.cardInhand, card, 1); + try { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_PONG_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + return true; + } + }finally { + if(remove)Util.addCard(player.cardInhand, card, 1); + } + } + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRPongOpenKongState.class)); + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleQSWin.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleQSWin.java new file mode 100644 index 0000000..59cf314 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleQSWin.java @@ -0,0 +1,45 @@ +package extend.mj.player.rule; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ֺ���� + * + */ +public class RuleQSWin implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + List cardList = player.cardInhand; + Map map = new HashMap<>(); + Paixing.qs_check(map, cardList,player.room.config, player.getRoom().difen_score); + boolean result = map.size()>0; + + if (result) { + Tip tip = new Tip(0,new TArray(), 0,this, RuleWeight.TYPE_QSWIN); + tip.group_type = RuleWeight.GROUO_QSWIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + player.getRoom().qsWinCount ++; + } + return result; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..3d63005 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,56 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.autoOutCard)return false; + + if (player.getRoom().activeHaidi) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_KONG; + player.tipMgr.addTip(tip); + result = true; + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java new file mode 100644 index 0000000..67f9f6f --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfOpenKong.java @@ -0,0 +1,77 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfOpenKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ܿ��ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfOpenKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + if (player.getRoom().activeHaidi) { + return false; + } + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean result = false; + if(player.autoOutCard) { + int card = player.drawCard; + if(Util.checkCardAndRomve(card, player.cardInhand,4)) { + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + result = true; + } + Util.addCard(player.cardInhand, card, 4); + } + }else { + Map cardMap = Util.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 4) { + Util.removeCard(player.cardInhand, card, 4); + if(Paixing.tingKongCheck(player.opCardList,player.cardInhand,card,!no_jiang)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG); + tip.group_type = RuleWeight.GROUO_OPENKONG; + player.tipMgr.addTip(tip); + result = true; + } + Util.addCard(player.cardInhand, card, 4); + } + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.drawCard = 0; + player.stateMachine.changeState(Global.getState(PRSelfOpenKongState.class)); + + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..253be8e --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,108 @@ +package extend.mj.player.rule; + +import java.util.HashMap; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + if(room.activeSeat != player.seat)return false; + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + OpenKong ok = room.activeKong; + boolean result = false; + ITArray opcard = TArray.newInstance(); + HashMap map = new HashMap(); + if (ok != null) { + for (int card : ok.drawList) { + if (Paixing.checkWin(map, player.opCardList, player.cardInhand, card,!no_jiang, room.difen_score)) { + Paixing.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.WIN_TYPE_SCORE); + map.remove(WinCardType.XIAOHU); + result = true; + opcard.addInt(card); + } + } + } else { + player.cardInhand.remove((Integer) player.drawCard); + boolean jiang = no_jiang; + //if(no_jiang&&room.activeHaidi) { + // jiang = false; + //} + result = Paixing.checkWin(map, player.opCardList, player.cardInhand, player.drawCard,jiang, room.difen_score); + player.cardInhand.add(player.drawCard); + opcard.addInt(player.drawCard); + } + if (result) { + if (room.activeHaidi) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.HAIDI, new WinCardType(WinCardType.HAIDI, 1,WinCardType.WIN_TYPE_SCORE)); + } + if(player.tianting) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANTINGHU, new WinCardType(WinCardType.TYPE_TIANTINGHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + + boolean tianhu = room.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if(tianhu&&room.bankerSeat == player.seat && player.outCardCount ==0) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_TIANHU, new WinCardType(WinCardType.TYPE_TIANHU, 1,WinCardType.WIN_TYPE_SCORE)); + } + boolean menqing = room.config.getBoolean("menqing"); + if(menqing) { + boolean m_r = true; + for (OpCard oc : player.opCardList) { + if(oc.type !=RuleWeight.TYPE_SELF_KONG) { + m_r = false; + break; + } + } + if(m_r) { + map.remove(WinCardType.XIAOHU); + map.put(WinCardType.TYPE_MENQING, new WinCardType(WinCardType.TYPE_MENQING, 1,WinCardType.WIN_TYPE_SCORE)); + } + } + + + Tip tip = new Tip(opcard.getInt(0),opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.group_type = RuleWeight.GROUO_WIN; + tip.winMap = map; + tip.self = true; + player.tipMgr.addTip(tip); + } + + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winCard = tip.card; + player.drawCard = tip.card; + player.winMap = tip.winMap; + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleZTWin.java b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleZTWin.java new file mode 100644 index 0000000..ee80373 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rule/RuleZTWin.java @@ -0,0 +1,45 @@ +package extend.mj.player.rule; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.Paixing; + +/** + * ���ֺ���� + * + */ +public class RuleZTWin implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + if(player.tianting)return false; + List cardList = player.cardInhand; + Map map = new HashMap<>(); + Paixing.zt_check(map, cardList,player.room.config,player.drawCard,player.llsCardRecord, player.getRoom().difen_score); + boolean result = map.size()>0; + + if (result) { + Tip tip = new Tip(0,new TArray(), 0,this, RuleWeight.TYPE_ZTWIN); + tip.group_type = RuleWeight.GROUO_ZTWIN; + tip.winMap = map; + player.tipMgr.addTip(tip); + } + return result; + } + + @Override + public void action(EXPlayer player, Tip tip) { + + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRChowState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRChowState.java new file mode 100644 index 0000000..3fcfd69 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRChowState.java @@ -0,0 +1,64 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRChowState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + ITArray opcard = owner.opCard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + int card= room.activeCard; + Util.removeCard(owner.cardInhand, chowcard1, 1); + Util.removeCard(owner.cardInhand, chowcard2, 1); + room.activeCard = 0; + + + OpCard opc = new OpCard(RuleWeight.TYPE_CHOW, card); + opc.opCard = new TArray(); + opc.opCard.addInt(chowcard1); + opc.opCard.addInt(chowcard2); + owner.opCardList.add(opc); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_CHOW, fromseat,opc.opCard,false); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..e108491 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,58 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(room.activeCard); + int card = room.activeCard; + OpCard opc = new OpCard(RuleWeight.TYPE_KONG, card); + owner.opCardList.add(opc); + Util.removeCard(owner.cardInhand, card, 4); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard,false); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java new file mode 100644 index 0000000..20fbc50 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherOpenKongState.java @@ -0,0 +1,64 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; + +/** + * + */ +public class PROtherOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + if(activePlayer!=owner) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + int fromseat = activePlayer.seat; + OpenKong ok = new OpenKong(); + ok.fromSeat = fromseat; + ok.kongSeat = owner.seat; + owner.openKong = ok; + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + + int card = room.activeCard; + OpCard opc = new OpCard(RuleWeight.TYPE_KONG, card); + owner.opCardList.add(opc); + + Util.removeCard(owner.cardInhand, card, 3); + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard,true); + room.activeCard = 0; + room.lastDiscardSeat = 0; + toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().activeKong = owner.openKong; + owner.openKong=null; + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..b8cd9dd --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,47 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.*; + +/** + * + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.win_count ++; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + for (Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + OpCard opc = CardUtil.findOpcard(owner.opCardList, card,RuleWeight.TYPE_PONG); + opc.type = RuleWeight.TYPE_KONG; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard,false); + + room.activeCard = card; + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + room.activeCard = 0; + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java new file mode 100644 index 0000000..10b3ca8 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongOpenKongState.java @@ -0,0 +1,81 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.tip.TipManager; +import extend.mj.uitl.CardUtil; + +/** + * + */ +public class PRPongOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + ITArray opcard = TArray.newInstance(); + if(room.activeKong==null){ + Util.removeCard(owner.cardInhand, card, 1); + opcard.addInt(card); + }else { + if(owner.outcardList.get(owner.outcardList.size() - 1)!=room.activeCard){ + owner.outcardList.remove(owner.outcardList.size() - 2); + }else{ + owner.outcardList.remove(owner.outcardList.size() - 1); + } + } + + OpCard opc = CardUtil.findOpcard(owner.opCardList, card,RuleWeight.TYPE_PONG); + opc.type = RuleWeight.TYPE_KONG; + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard,true); + if(room.activeKong==null) { + room.activeCard = card; + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + room.activeCard = 0; + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().activeCard = 0; + OpenKong ok = new OpenKong(); + ok.fromSeat = owner.seat; + ok.kongSeat = owner.seat; + owner.getRoom().activeKong = ok; + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..60bf1bf --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,61 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2); + }else{ + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + } + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int card = room.activeCard; + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard,false); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..b9c3339 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,39 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard,false); + + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java new file mode 100644 index 0000000..dcb3c70 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfOpenKongState.java @@ -0,0 +1,48 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.OpenKong; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerOpenKongState; + +/** + * + */ +public class PRSelfOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + OpenKong ok = new OpenKong(); + ok.fromSeat = owner.seat; + ok.kongSeat = owner.seat; + room.activeKong = ok; + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard,true); + + owner.stateMachine.changeState(Global.getState(EXPlayerOpenKongState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..67f83bd --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,50 @@ +package extend.mj.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.*; + +/** + * + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + owner.win_count ++; + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.win_count = 0; + } + for (Entry entry : owner.winMap.entrySet()) { + WinCardType wct = entry.getValue(); + for(int i = 0;i entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner, 0, 0); + } + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..b8492bb --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,158 @@ +package extend.mj.player.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.*; + +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.tip.TipManager; +import extend.mj.uitl.Paixing; + +/** + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + if (owner.autoOutCard) { + owner.startActionTimer(1000); + } else { + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + // owner.startActionTimer(); + } + + private void _action(EXPlayer owner, int discard, int gid) { + if (owner.autoOutCard && discard != owner.drawCard) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.louhu = false; + owner.drawCard = 0; + EXMainServer.gameCtr.outCard(owner, discard); + boolean ting = owner.room.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if (owner.seat == owner.room.bankerSeat && owner.outCardCount == 0 && ting && Paixing.tingCheck(owner.opCardList, owner.cardInhand)) { + owner.stateMachine.changeState(Global.getState(EXPlayerTianTingTipState.class)); + } else { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + EXRoom room = owner.getRoom(); + if (room.tipMap.size() != 0) { + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if (tipmgr.isWin) + win_count++; + } + room.tongpao = 0; + if (win_count > 1) + room.tongpao = win_count; + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + owner.outCardCount++; + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + _action(owner, discard, gid); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard = owner.drawCard; + if (owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + _action(owner, discard, gid); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..e9bdd53 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,255 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; + +import extend.mj.*; +import extend.mj.uitl.Paixing; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!owner.skipDraw&&room.card.cardList.size() == 0) { + room.liuju = true; + room.endGame(); + return; + } + draw(owner); + } + + void draw(EXPlayer owner) { + EXRoom room = owner.getRoom(); + boolean zt_win = false; + if(!owner.skipDraw) { + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean no_jiang = room.config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean jiang = true; + if(no_jiang&&room.activeHaidi) { + jiang = false; + } + + HashMap map = new HashMap(); + boolean result = Paixing.checkWin(map, owner.opCardList, owner.cardInhand, drawCard, jiang, room.difen_score); + if (result) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(!IsGoodCard(owner, drawCard)) { + if (room.card.cardList.size() != 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else { + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + //owner.drawCard = room.card.pop(); + zt_win = EXMainServer.playerRuleMgr.condition(PlayerRuleManager.ZT_HU_RULE, owner,false); + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + } + if(room.activeHaidi) { + room.haidiCard = owner.drawCard; + } + owner.skipDraw = false; + if(!zt_win) { + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + boolean no_jiang = player.getRoom().config.getBoolean(Config.ROOM_CONFIG_NO_JIANG); + boolean jiang = true; + if(no_jiang&&player.getRoom().activeHaidi) { + jiang = false; + } + + HashMap map = new HashMap(); + boolean result = Paixing.checkWin(map, player.opCardList, player.cardInhand, drawCard, jiang, player.getRoom().difen_score); + if (result) { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..faaacf8 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,38 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java new file mode 100644 index 0000000..8e4b897 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerHaidiTipState.java @@ -0,0 +1,52 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; + +/** + * + */ +public class EXPlayerHaidiTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.haidiTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + owner.tipMgr.clean(); + if (id == 0) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.haidiCount ++; + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + room.niao.clear(); + owner.autoOutCard = true; + room.activeHaidi = true; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..b48e82a --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,48 @@ +package extend.mj.player.state; + +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + +// protected void winOpt(Tip tip) { +// tip.winMap.remove(WinCardType.XIAOHU); +// tip.winMap.put(WinCardType.QIANG_GANG_HU, new WinCardType(WinCardType.QIANG_GANG_HU, 1,6)); +// } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); +// if(id!=0) { +// Tip tip = owner.tipMgr.tipMap.get(id); +// if(tip.weight == RuleWeight.WIN) { +// winOpt(tip); +// } +// } + + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java new file mode 100644 index 0000000..b0c9978 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerOpenKongState.java @@ -0,0 +1,106 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.mj.*; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.tip.TipManager; + +/** + * + */ +public class EXPlayerOpenKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + owner.louhu = false; + owner.autoOutCard = true; + + EXRoom room = owner.getRoom(); + OpenKong ok = room.activeKong; + if (ok != null) { + ok.drawList.add(room.card.pop()); + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + if (room.config.getInt(Config.ROOM_CONFIG_KAI_GONG) > 0) + { + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + if (room.card.getCount() > 0) + ok.drawList.add(room.card.pop()); + } + if(room.card.getCount() == 0){ + ok.haidi = true; + } + } + + for(Integer card : ok.drawList) { + owner.outcardList.add(card); + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).openKongEvent(owner, leftCount, ok); + + timer(owner.getRoom(), owner, this); + } + + public static void timer(EXRoom room, EXPlayer owner, EXPlayerOpenKongState state) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (room == null) { + Global.logger.error("room is null"); + return; + } + + if (room.isDestroy) + return; + + room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OPENKONG, null); + int win_count = 0; + for (Entry entry : room.tipMap.entrySet()) { + TipManager tipmgr = entry.getValue(); + if(tipmgr.isWin)win_count++; + } + room.tongpao = 0; + if( win_count>1)room.tongpao = win_count; + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OPENKONG_RULE, owner,false); + if (room.tipMap.size() == 0) { + room.activeKong = null; + state.toNextState(owner); + } + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXPlayer owner) { + if(owner.getRoom().activeKong == null) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + }else { + + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + + } + + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d9c6b79 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,47 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.piaoNiaoTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + owner.piaoNiao = id; + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoNiaoCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + EXMainServer.gameCtr.piaoNiaoEvent(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java new file mode 100644 index 0000000..a9d62d3 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerQSWinTipState.java @@ -0,0 +1,49 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXGameController; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.tip.Tip; + +/** + * + */ +public class EXPlayerQSWinTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.qsTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + if (id != 0) { + Tip tip = owner.tipMgr.tipMap.get(id); + ((EXGameController)Global.gameCtr).qsWinEvent(owner,tip); + } + owner.tipMgr.clean(); + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().qsWinCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_QSWIN, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java new file mode 100644 index 0000000..25ed8b9 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTianTingTipState.java @@ -0,0 +1,68 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.room.state.EXRoomSetpState; + +/** + * + */ +public class EXPlayerTianTingTipState extends EXPlayerTipState { + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.tingTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + owner.tipMgr.clean(); + if(id!=0) { + owner.tianting = true; + owner.autoOutCard = true; + EXMainServer.gameCtr.tingEvent(owner); + } + if(owner.seat == owner.room.bankerSeat) { + EXRoom room = owner.getRoom(); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DISCARD, room.activeCard); + if (room.tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + }else { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().tianTingCount --; + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_TIANTING, gid, null); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + } + + @Override + public void toNextState(EXPlayer owner) { + if(owner.seat == owner.room.bankerSeat) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + }else { + super.toNextState(owner); + } + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..a8da242 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (!owner.isEntrust()) { + _tipEvent(owner); + owner.startActionTimer(); + } else { + owner.startActionTimer(500); + } + } + + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } + + protected void _action(EXPlayer owner, int id, int gid) { + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..716e90c --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,20 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..ff4f2ea --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,47 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * + */ +public class EXPlayerWaitState extends StateBase { + +// @SuppressWarnings("unchecked") +// @Override +// public void toNextState(EXPlayer owner) { +// if(owner.getRoom().activeKong!=null){ +// if(owner.getRoom().activeKong.kongSeat == owner.seat){ +// owner.stateMachine.lastState.toNextState(owner); +// } +// } +// } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + boolean old_louhu = owner.louhu; + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.louhu = false; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + break; + case EXActionEvent.EVENT_OPENKONG: + owner.louhu = false; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OPENKONG_RULE , owner); + break; + default: + break; + } + owner.louhu =old_louhu; + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java new file mode 100644 index 0000000..be03472 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/player/state/EXPlayerZTWinTipState.java @@ -0,0 +1,51 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXGameController; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.tip.Tip; + +/** + * 中途胡 + */ +public class EXPlayerZTWinTipState extends EXPlayerTipState { + + + @Override + protected void _tipEvent(EXPlayer owner) { + EXMainServer.gameCtr.qsTipEvent(owner); + } + @Override + protected void _action(EXPlayer owner,int id,int gid) { + if (id != 0) { + Tip tip = owner.tipMgr.tipMap.get(id); + + ((EXGameController) Global.gameCtr).qsWinEvent(owner, tip); + } + owner.tipMgr.clean(); + owner.skipDraw = true; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + } else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner, 0, gid); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..2896ebd --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,197 @@ +package extend.mj.room.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayBack; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.PlayerRuleManager; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; +import extend.mj.player.state.EXPlayerTianTingTipState; +import extend.mj.uitl.Paixing; + +/** + * + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + ArrayList randPlayer = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + Integer seat = entry.getKey(); + randPlayer.add(seat); + } + + Collections.shuffle(randPlayer); + if (randPlayer.size() > 0) + { + owner.bankerSeat = randPlayer.get(0); + } + } +// owner.round += 1; +// owner.isplaying = true; + + int piao_niao = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO); + boolean piao_niao_auto = owner.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO_AUTO); + if(piao_niao > 0) { + if(piao_niao == 1 || piao_niao == 2 && piao_niao_auto) { + owner.piaoNiaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + else if (piao_niao == 2) + { + owner.piaoNiaoCount = 0; + int opt = owner.config.getInt(Config.ROOM_CONFIG_PIAO_NIAO_OPT); + int piao_fen = 1; + if (opt == 0) + { + piao_fen = 1; + } + else if (opt == 1) + { + piao_fen = 2; + } + else if (opt == 2) + { + piao_fen = 3; + } + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.piaoNiao = piao_fen; + player.tipMgr.clean(); + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + player.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(player); + } + checkXiPai(owner); + } else { + checkXiPai(owner); + } + }else { + checkXiPai(owner); + } + } + + public static void timer(EXRoom owner, EXRoomDealState state) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + state.checkQSWin(owner); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + private void checkXiPai(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner, this); + } + else { + checkQSWin(owner); + } + } + + private void checkQSWin(EXRoom owner) { + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.QS_HU_RULE, (EXPlayer)player); + } + + if(owner.qsWinCount ==0) { + checkTianting(owner); + } + } + + private void checkTianting(EXRoom owner) { + boolean ting = owner.config.getBoolean(Config.ROOM_CONFIG_NATIVE_HU); + if(ting) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat != owner.bankerSeat) { + if(Paixing.tingCheck(player.opCardList, player.cardInhand)) { + owner.tianTingCount ++; + player.stateMachine.changeState(Global.getState(EXPlayerTianTingTipState.class)); + } + } + } + if (owner.tianTingCount == 0) { + toNextState(owner); + } + }else { + toNextState(owner); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) { + if(owner.piaoNiaoCount==0) { + checkXiPai(owner); + } + }else if(cmd.equals(EXActionEvent.EVENT_QSWIN)) { + if(owner.qsWinCount ==0) { + checkTianting(owner); + } + }else if(cmd.equals(EXActionEvent.EVENT_TIANTING)) { + if(owner.tianTingCount ==0) { + toNextState(owner); + } + } + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..8054053 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,45 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.PlayerRuleManager; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + if(owner.haidiCount == owner.maxPlayers) { + owner.liuju = true; + owner.endGame(); + return; + } + + Player player; + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HAIDI_RULE, (EXPlayer)player,false)){ + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..5637fca --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,34 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.activeKong = null; + owner.startGame(); + + this.toNextState(owner); + + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/tip/Action.java b/game_mj_nanxian/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..7f657ac --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,30 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + * Action.java + */ +public class Action { + + public Tip tip; + public EXPlayer player; + public boolean isRun; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + if(this.isRun)return; + this.isRun = true; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_nanxian/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..fac8497 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,23 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * + * + * RuleBase.java + */ +public interface IRuleBase { + + /** + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/tip/Tip.java b/game_mj_nanxian/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..f7b92cb --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,44 @@ +package extend.mj.tip; + +import java.util.Map; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.mj.WinCardType; + +/** + * + * + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public int group_type; + + public Map winMap; + public boolean self; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", group_type); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/tip/TipManager.java b/game_mj_nanxian/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..993f3c6 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,175 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; + +/** + * + * + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + public boolean isWin = false; + private Tip winTip = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + if(tip.weight == RuleWeight.WIN) { + this.isWin = true; + this.winTip = tip; + } + this.tipMap.put(id, tip); + } + + + + private void checkLouhu() { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + + public void choicAction(int id) { + EXRoom room = this.owner.getRoom(); + if(room.tongpao > 1 && this.isWin) { + Tip tip = this.winTip; + Tip choic_tip = this.tipMap.get(id); + if(choic_tip!=null) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Action action = new Action(choic_tip, owner); + if(tip == choic_tip) { + for (Entry entry : room.tipMap.entrySet()) { + TipManager tem = entry.getValue(); + if (action.tip.weight < tem.getWeightest()) { + room.actionWinList.add(action); + room.actionList.add(action); + return; + } + } + action.run(); + room.actionList.clear(); + room.tongpao = 0; + }else { + room.actionWinList.add(new Action(tip, owner)); + room.addAction(action); + } + return; + }else { + room.actionWinList.add(new Action(tip, owner)); + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.checkAction(); + } + }else { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + } + + public void winAction() { + EXRoom room = this.owner.getRoom(); + if(room.tongpao > 1 && this.isWin) { + Tip tip = this.winTip; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.addAction(new Action(tip, owner)); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); +// mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.winTip = null; + this.isWin = false; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_nanxian/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..7c60282 --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,52 @@ +package extend.mj.uitl; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.OpCard; +import extend.mj.WinCardType; + +public class CardUtil { + + static public OpCard findOpcard(List opcards, int card,int type) { + for (OpCard oc : opcards) { + if(oc.type == type) { + if (card == oc.card) { + return oc; + } + } + } + return null; + } + + + final static Random random = new Random(); + static { + random.setSeed(System.currentTimeMillis()); + } + static public int randomDiceNum() { + int result = random.nextInt(5); + return result + 1; + } + + static public ITArray toMPData_WinMap(Map map) { + return toMPData_WinMap(map,false); + } + + static public ITArray toMPData_WinMap(Map map,boolean is_opcard) { + if (map != null && map.size() > 0) { + ITArray array = TArray.newInstance(); + for (Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + array.addTObject(wct.toTObject(is_opcard)); + } + return array; + } + return null; + } +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/uitl/Paixing.java b/game_mj_nanxian/src/main/java/extend/mj/uitl/Paixing.java new file mode 100644 index 0000000..39b3beb --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/uitl/Paixing.java @@ -0,0 +1,438 @@ +package extend.mj.uitl; + +import java.util.*; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.WinCardType; + + + +public class Paixing { + + private final static boolean qs_yijihua_check(Map cardMap,int se,int index) { + Integer num = cardMap.get(se+index); + if(num!=null&&num==1) { + for(int i=1;i<=9;++i) { + if(i !=index) { + if(cardMap.containsKey(se+i)){ + return false; + } + } + } + return true; + } + return false; + } + + public final static void zt_check(Map map,List cardInhand,ITObject config,int card,Set llsCardRecord, int difen) { + if(config.getBoolean(Config.ROOM_CONFIG_ZT_DASIXI)) { + if(Util.cardNum(card,cardInhand) >= 3) { + ITArray opcard4 = new TArray(); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_DASIXI, 1,1); + Util.addCard(opcard4, card, 4); + wct.opcard = opcard4; + + } + } + if(config.getBoolean(Config.ROOM_CONFIG_ZT_LIULIUSHUN)) { + if(!llsCardRecord.contains(card)) { + if(Util.cardNum(card,cardInhand) >= 2) { + Map cardMap =Util.getCardNumMap(cardInhand); + for (Entry entry : cardMap.entrySet()) { + int t_card = entry.getKey(); + int num = entry.getValue(); + if(num>=3&&t_card!=card&&!llsCardRecord.contains(t_card)) { + ITArray opcard3 = new TArray(); + Util.addCard(opcard3, card, 3); + Util.addCard(opcard3, t_card, 3); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_LIULIUSHUN, 1,1); + wct.opcard = opcard3; + break; + } + } + } + + } + } + } + + public final static void qs_check(Map map,List cardInhand,ITObject config, int difen){ + Map cardMap =Util.getCardNumMap(cardInhand); + int card3count=0; + int card4count=0; + boolean banban = true; + ITArray opcard4 = new TArray(); + ITArray opcard3 = new TArray(); + + Set se = new HashSet(); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) { + banban = false; + } + se.add(card/100); + int num = entry.getValue(); + if(num>=4) { + Util.addCard(opcard4, card, 4); + Util.addCard(opcard3, card, 3); + card4count++; + card3count++; + }else if(num>=3) { + Util.addCard(opcard3, card, 3); + card3count++; + } + } + if(card4count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_DASIXI, card4count,1); + wct.opcard = opcard4; + } + if(card3count>=2) { + if(card3count>2 &&card3count %2 !=0){ + opcard3.del(opcard3.size()-1); + opcard3.del(opcard3.size()-1); + opcard3.del(opcard3.size()-1); + } + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_LIULIUSHUN, card3count/2,1); + wct.opcard = opcard3; + } + if(banban) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_BANBANHU, 1,1); + wct.opcard = Util.toTArray(cardInhand); + } + if(!config.getBoolean(Config.ROOM_CONFIG_QUEYIMEN)&&se.size()<3) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_QUEYISE, 1,1); + wct.opcard = Util.toTArray(cardInhand); + + } + if(config.getBoolean(Config.ROOM_CONFIG_QS_YIZHIHUA)) { + int yizhihua_count = 0; + for(int k=100;k<=300;k+=100) { + if(qs_yijihua_check(cardMap,k,5)) { + yizhihua_count ++; + } + } + if(yizhihua_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_YIZHIHUA, yizhihua_count,1); + wct.opcard = Util.toTArray(cardInhand); + }else { + boolean card_5 = false; + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + if(!card_5 && card % 100 == 5&&entry.getValue() == 1) { + card_5 = true; + }else { + if (card % 100 == 2 || card % 100 == 5 || card % 100 == 8) { + card_5 = false; + break; + } + } + } + if(card_5) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_YIZHIHUA, 1,1); + wct.opcard = Util.toTArray(cardInhand); + } + } + } + + boolean santong_2= false; + if(config.getBoolean(Config.ROOM_CONFIG_QS_SANTONG)) { + int santong_count = 0; + ITArray st_opcard = new TArray(); + for(int i=1;i<=9;++i) { + if(Util.cardNum(cardMap, 100+i, 2)&&Util.cardNum(cardMap, 200+i, 2)&&Util.cardNum(cardMap, 300+i, 2)) { + santong_count++; + Util.addCard(st_opcard, 100+i, 2); + Util.addCard(st_opcard, 200+i, 2); + Util.addCard(st_opcard, 300+i, 2); + if (i == 2)santong_2=true; + } + } + if(santong_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_SANTONG, santong_count,1); + wct.opcard = st_opcard; + } + } + + if(!santong_2&&config.getBoolean(Config.ROOM_CONFIG_QS_JTYN)) { + if(Util.cardNum(cardMap, 202, 2)&&Util.cardNum(cardMap, 302, 2)) { + ITArray st_opcard = new TArray(); + Util.addCard(st_opcard, 202, 2); + Util.addCard(st_opcard, 302, 2); + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_QTYN, 1,1); + wct.opcard = st_opcard; + } + } + + if(config.getBoolean(Config.ROOM_CONFIG_QS_JIEJIEGAO)) { + int jjg_count = 0; + ITArray jjg_opcard = new TArray(); + for(int k=100;k<=300;k+=100) { + for(int i=1;i<=7;++i) { + if(Util.cardNum(cardMap, k+i, 2)&&Util.cardNum(cardMap, k+i+1, 2)&&Util.cardNum(cardMap, k+i+2, 2)) { + jjg_count++; + Util.addCard(jjg_opcard, k+i, 2); + Util.addCard(jjg_opcard, k+i+1, 2); + Util.addCard(jjg_opcard, k+i+2, 2); + i+=2; + } + } + } + if(jjg_count>0) { + WinCardType wct = putWinCardType(map, RuleWeight.TYPE_JIEJIEGAO, jjg_count,1); + wct.opcard = jjg_opcard; + } + } + } + + public static void main(String[] args) { +// List cardInhand = new java.util.ArrayList<>(); +// List opCards = new java.util.ArrayList<>(); +// opCards.add(new OpCard(RuleWeight.TYPE_PONG, 109)); +// opCards.add(new OpCard(RuleWeight.TYPE_PONG, 209)); +// cardInhand.add(106); +// cardInhand.add(106); +// cardInhand.add(107); +// cardInhand.add(108); +//// cardInhand.add(109); +// +// +// System.out.println(tingKongCheck(opCards,cardInhand, 109)); + } + + private final static boolean quanqiuren(List opCards,List cardInhand, int drawCard) { + if (cardInhand.size() > 1) { + return false; + } + if(drawCard == 0)return true; + if (cardInhand.get(0) != drawCard) + return false; + return true; + } + + private final static boolean qingyise(List opCards, List cardInhand, int drawCard) { + int se = cardInhand.get(0) / 100; + if (drawCard!=0&&drawCard / 100 != se) + return false; + for (OpCard card : opCards) { + if (se != card.card / 100) { + return false; + } + } + for (int card : cardInhand) { + if (se != card / 100) { + return false; + } + } + return true; + } + + private final static boolean pongpong(List opCards, List cardInhand, int drawCard,boolean quanqiuren) { + for (OpCard card : opCards) { + if (card.type == RuleWeight.TYPE_CHOW) { + return false; + } + } + if (quanqiuren)return true; + + int card1count=0,card2count=0; + Map cardMap =Util.getCardNumMap(cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 4) return false; + switch(num) { + case 1: + if(card1count>=1)return false; + if(drawCard!=0&&card != drawCard)return false; + card1count++; + break; + case 2: + if(card2count >=2)return false; + card2count ++; + break; + } + } + if(card1count>0&&card2count>0)return false; + if(card1count>0&&drawCard!=0&&!cardMap.containsKey(drawCard))return false; + if(card2count == 2&&drawCard!=0) { + if(!cardMap.containsKey(drawCard))return false; + if(cardMap.get(drawCard)!=2)return false; + } + return true; + } + + private final static boolean jiangjiang(List opCards, List cardInhand, int drawCard) { + if(drawCard!=0){ + if (drawCard % 100 != 2 && drawCard % 100 != 5 && drawCard % 100 != 8) { + return false; + } + } + for (OpCard card : opCards) { + if (card.type == RuleWeight.TYPE_CHOW) { + return false; + } + if (card.card % 100 != 2 && card.card % 100 != 5 && card.card % 100 != 8) { + return false; + } + } + for (int card : cardInhand) { + if (card % 100 != 2 && card % 100 != 5 && card % 100 != 8) { + return false; + } + + } + return true; + } + + private final static int qixiaodui(List opCards, List cardInhand, int drawCard) { + if (cardInhand.size() != 13) { + return -1; + } + List cardlist = cardInhand; + int pair = 0; + int card4count=0; + Map cardMap =Util.getCardNumMap(cardlist); + for (Entry entry : cardMap.entrySet()) { + int num = entry.getValue(); + int card = entry.getKey(); + if (num == 4) { + pair +=2; + card4count ++; + }else if(num >=2) { + if(num==3&&drawCard!=0&&drawCard != card) { + return -1; + } + pair +=1; + }else if(num ==1) { + if(drawCard!=0&&drawCard != card) { + return -1; + } + } + } + if(pair<6) return -1; + if(drawCard ==0)return card4count+1; + if(!cardMap.containsKey(drawCard)) return -1; + if(cardMap.get(drawCard) == 3) { + card4count++; + } + return card4count+1; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score) { + if (map == null) + return null; + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score); + map.put(type, wct); + return wct; + } + } + + public static boolean checkWin(Map map, List opCards, List cardInhand,int drawCard, int difen) { + return checkWin(map,opCards,cardInhand,drawCard,true, difen); + } + + public static boolean checkWin(Map map, List opCards, List cardInhand,int drawCard,boolean jiang, int difen) { + int qixiaodui = qixiaodui(opCards,cardInhand, drawCard); + if (qixiaodui != -1) { + putWinCardType(map, WinCardType.QIXIAODUI, qixiaodui,WinCardType.QI_XIAO_DUI_HU_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QING_YI_SE_HU_SCORE); + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.JIANG_JIANG_HU_SCORE); + } + return true; + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.JIANG_JIANG_HU_SCORE); + boolean _qqr =quanqiuren(opCards,cardInhand, drawCard); + if (_qqr) { + putWinCardType(map, WinCardType.QUANQIUREN, 1,WinCardType.WIN_TYPE_SCORE); + } + if (pongpong(opCards,cardInhand, drawCard,_qqr)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.JIANG_JIANG_HU_PENG_PENG_HU_SCORE); + } + return true; + } + if (quanqiuren(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QUANQIUREN, 1,WinCardType.QUAN_QIU_REN_HU_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QING_YI_SE_HU_SCORE); + } + if (jiangjiang(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.JIANGJIANGHU, 1,WinCardType.JIANG_JIANG_HU_SCORE); + } + if (pongpong(opCards,cardInhand, drawCard,true)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.PENG_PENG_HU_SCORE); + } + return true; + } + if (pongpong(opCards,cardInhand, drawCard,false)) { + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.PENG_PENG_HU_SCORE); + if (qingyise(opCards,cardInhand, drawCard)) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QING_YI_SE_HU_PENG_PENG_HU_SCORE); + } + return true; + } + if (qingyise(opCards,cardInhand, drawCard)) { + WinCard win = new WinCard(cardInhand, drawCard); + win.jiang = false; + if (win.tryWin()) { + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QING_YI_SE_HU_SCORE); + return true; + } + } else { + WinCard win = new WinCard(cardInhand, drawCard); + win.jiang = jiang; + if (win.tryWin()) { + putWinCardType(map, WinCardType.XIAOHU, 1, difen); + return true; + } + } + return false; + } + + static public boolean tingCheck(List opCards,List cardInhand) { + if(qixiaodui(opCards,cardInhand, 0)!=-1)return true; + if (quanqiuren(opCards,cardInhand, 0))return true; + if (jiangjiang(opCards,cardInhand, 0))return true; + if (pongpong(opCards,cardInhand, 0,false))return true; + + if (qingyise(opCards,cardInhand, 0)) { + WinCard win = new WinCard(cardInhand, 0); + win.jiang = false; + return win.tryWin(); + } + WinCard win = new WinCard(cardInhand, 0); + return win.tryWin(); + } + + + static public boolean tingKongCheck(List opCards,List cardInhand,int kongCard,boolean jiang) { + if (quanqiuren(opCards,cardInhand, 0))return true; + if (jiangjiang(opCards,cardInhand, kongCard))return true; + if (pongpong(opCards,cardInhand, 0,false))return true; + if (qingyise(opCards,cardInhand, kongCard)) { + WinCard win = new WinCard(cardInhand, 0); + win.jiang = false; + return win.tryWin(); + } + WinCard win = new WinCard(cardInhand, 0); + win.jiang = jiang; + return win.tryWin(); + } + +} diff --git a/game_mj_nanxian/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_nanxian/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..558fc8d --- /dev/null +++ b/game_mj_nanxian/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,275 @@ +package extend.mj.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import com.game.Util; + +import extend.mj.WinCardType; + +public class WinCard { + public int pair_count; + public Stack> stack; + public List cardList; + public boolean jiang = true; + public int zhong_count; + public int zhongid = 0; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + if (card == zhongid) { + this.zhong_count += 1; + } else { + this.cardList.add(card); + } + } + Collections.sort(this.cardList); + } + + private boolean tryShunzi(int card) { + if (card % 100 > 7) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList) && Util.checkCard(card + 2, this.cardList)) { + Util.removeCard(this.cardList, card, 1); + Util.removeCard(this.cardList, card + 1, 1); + Util.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryKezi(int card) { + if (Util.checkCardAndRomve(card, this.cardList, 3)) { +// CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (jiang) { + if (!(card % 100 == 2 || card % 100 == 5 || card % 100 == 8)) { + return false; + } + } + if (Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + return true; + } + return false; + } + + private boolean tryKezi1Zhong(int card) { + if (this.zhong_count >= 1 && Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.zhong_count -= 1; + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryShunzi1Zhong(int card) { + if (card % 100 > 8) { + return false; + } + + if (this.zhong_count < 1) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 1, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(this.zhongid); + this.push(cardGroup); + return true; + } + + if (Util.checkCard(card + 2, this.cardList) && ((card + 1) % 100 != 0)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 2, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryPair1Zhong(int card) { + if (this.pair_count > 0) { + return false; + } + if (jiang) { + if (!(card % 100 == 2 || card % 100 == 5 || card % 100 == 8)) { + return false; + } + } + if (this.zhong_count < 1) { + return false; + } + + Util.removeCard(cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.zhong_count -= 1; + this.pair_count = 1; + return true; + } + + public boolean tryWin() { + if (this.cardList.size() == 0 && this.pair_count == 1) { + return true; + } + + if (this.cardList.size() == 0) { + return false; + } + int activeCard = this.cardList.get(0); + + if (tryPair(activeCard)) { + if (tryWin()) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + + if (tryKezi(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + + } + if (tryShunzi(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + } + + if (tryKezi1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + + } + if (tryShunzi1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.rollBack(); + } + if (tryPair1Zhong(activeCard)) { + if (tryWin()) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard == 0) { + this.zhongid = 0; + this.zhong_count = 1; + } else { + this.cardList.add(addCard); + } + + Collections.sort(this.cardList); + } + + public static void main(String[] args) { + + long time = System.currentTimeMillis(); +// for (int i = 0; i < 1000000; ++i) { + ArrayList cardInhand = new ArrayList(); + cardInhand.add(102); + cardInhand.add(102); + cardInhand.add(204); + cardInhand.add(204); + cardInhand.add(206); + cardInhand.add(206); + + cardInhand.add(305); + cardInhand.add(305); + cardInhand.add(305); + cardInhand.add(306); + cardInhand.add(306); + cardInhand.add(307); + + cardInhand.add(307); +// cardInhand.add(301); +// cardInhand.add(301); +// cardInhand.add(108); + +// cardInhand.contains(204); +// Util.checkCard(204, cardInhand); +// CardUtil.checkCardAndRomve(204, cardInhand, 2); + +// if(Util.checkCard(204, cardInhand)) { +// CardUtil.removeCard(cardInhand, 204, 2); +// } +// WinCard win = new WinCard(cardInhand, 0); +// win.tryWin(); +// Paixing.tingKongCheck(new ArrayList<>(), cardInhand, 301); +// } + Map map = new HashMap(); + //Paixing.checkWin(map, new ArrayList<>(), cardInhand, 305, room.difen_score); + + System.out.println(System.currentTimeMillis() - time); + + } + +} diff --git a/game_mj_nanxian/src/test/java/game_mj_nanxian/Main.java b/game_mj_nanxian/src/test/java/game_mj_nanxian/Main.java new file mode 100644 index 0000000..a3e5f06 --- /dev/null +++ b/game_mj_nanxian/src/test/java/game_mj_nanxian/Main.java @@ -0,0 +1,9 @@ +package game_mj_nanxian; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_yijiaolaiyou/config/game-config.xml b/game_mj_yijiaolaiyou/config/game-config.xml new file mode 100644 index 0000000..4c44b1f --- /dev/null +++ b/game_mj_yijiaolaiyou/config/game-config.xml @@ -0,0 +1,11 @@ + + + + + 192.168.14.1 + 192.168.14.1 + 8711 + 8711 + 12 + true + \ No newline at end of file diff --git a/game_mj_yijiaolaiyou/config/log4j.properties b/game_mj_yijiaolaiyou/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_yijiaolaiyou/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_yijiaolaiyou/config/taurus-core.xml b/game_mj_yijiaolaiyou/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_mj_yijiaolaiyou/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_yijiaolaiyou/config/taurus-permanent.xml b/game_mj_yijiaolaiyou/config/taurus-permanent.xml new file mode 100644 index 0000000..1f42593 --- /dev/null +++ b/game_mj_yijiaolaiyou/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_yijiaolaiyou/pom.xml b/game_mj_yijiaolaiyou/pom.xml new file mode 100644 index 0000000..a729ddf --- /dev/null +++ b/game_mj_yijiaolaiyou/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_yijiaolaiyou + 1.0.0 + jar + + game_mj_yijiaolaiyou + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_yijiaolaiyou + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/CardNiao.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..12b4af9 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/CardNiao.java @@ -0,0 +1,22 @@ +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 seat = 0; + public int score = 0; + + + public ITObject toMP(){ + ITObject obj = TObject.newInstance(); + obj.putInt("card", card); + obj.putInt("score", score); + obj.putInt("playerId", playerId); + obj.putInt("seat", seat); + return obj; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/Config.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..3cb2b78 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/Config.java @@ -0,0 +1,193 @@ +package extend.mj; + +public class Config { + //400 东风 403南风 406西风 409北风 412红中 415发财 418白板 + public static final int DONGFENG = 400; + public static final int NANFENG = 403; + public static final int XIFENG = 406; + public static final int BEIFENG = 409; + public static final int HONGZHONG = 412; + public static final int FACAI = 415; + public static final int BAIBAN = 418; + + public static final String ROOM_CONFIG_DIANPAO = "dianpao"; //接炮胡 + public static final String ROOM_CONFIG_HUNYISE = "hunyise"; //混一色 + public static final String ROOM_CONFIG_QINGYISE = "qingyise"; //清一色 + public static final String ROOM_CONFIG_PENGPENGHU = "pengpenghu"; //碰碰胡 + public static final String ROOM_CONFIG_QIDUI = "qidui"; //七小对 + public static final String ROOM_CONFIG_HAOHUA_QIDUI = "haohua_qidui"; //豪华七小对 + public static final String ROOM_CONFIG_HAOHUA2_QIDUI = "haohua2_qidui"; //双豪华七小对 + public static final String ROOM_CONFIG_HAOHUA3_QIDUI = "haohua3_qidui"; //三豪华七小对 + public static final String ROOM_CONFIG_GANGSHANGKAIHUA_2bei = "gangshangkaihua"; //杠上开花2倍 + public static final String ROOM_CONFIG_GANGSHANGPAO_2bei = "gangshangpao_2bei"; //杠上炮2倍 + public static final String ROOM_CONFIG_SHISHANGYAO = "shishanyao"; //十三幺 + public static final String ROOM_CONFIG_TIANDIHU = "tiandihu"; //天地胡 + public static final String ROOM_CONFIG_SHIBALUOHAN = "shibaluohan"; //十八罗汉 + public static final String ROOM_CONFIG_XIAOSHANYUAN = "xiaoshanyuan"; //小三元 + public static final String ROOM_CONFIG_XIAOSIXI = "xiaosixi"; //小四喜 + public static final String ROOM_CONFIG_DASHANYUAN = "dashanyuan"; //大三元 + public static final String ROOM_CONFIG_DASIXI = "dasixi"; //大四喜 + public static final String ROOM_CONFIG_LOUHU = "louhu"; //漏胡 + public static final String ROOM_CONFIG_GUO_PENG = "guopeng"; //过碰不碰 + public static final String ROOM_CONFIG_GUO_GONG = "guogang"; //过杠不杠 + public static final String ROOM_CONFIG_YAO_JIU = "yao_jiu"; //混幺九 + public static final String ROOM_CONFIG_QING_YAO_JIU = "qing_yao_jiu"; //清幺九 + public static final String ROOM_CONFIG_LAIZI4_HU = "laizi4_hu"; //四鬼胡牌 + public static final String ROOM_CONFIG_LAIZI4_HU_2BEI = "laizi4_hu_2bei"; //四鬼胡牌两倍 + public static final String ROOM_CONFIG_QUAN_FENG = "quan_feng"; //全风 + public static final String ROOM_CONFIG_12ZHANG_LUODI_QUANBAO = "twelve_zhang_luodi_quanbao";//12张落地全包 + public static final String ROOM_CONFIG_QUAN_FENG_SCORE = "quan_qiu_ren"; //全求人 + public static final String ROOM_CONFIG_han19 = "han19"; //含19即可 + public static final String ROOM_CONFIG_ZIYISE = "ziyise"; //字一色 + public static final String ROOM_CONFIG_HAI_DI_NAO_YUE = "haidinaoyue"; //海底捞月 + + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian"; + public static final String ROOM_CONFIG_PIAO_NIAO = "piao_niao"; + public static final String ROOM_CONFIG_QIDUI_JIA_FAN = "qidui_jiafan"; //七对2倍 + public static final String ROOM_CONFIG_QIDUI_4BEI = "qidui_4bei"; //七对4倍 + public static final String ROOM_CONFIG_NIAO = "niao"; //0无马 1有马 2爆炸马 3抓马 + public static final String ROOM_CONFIG_NIAO_OPT = "niao_opt"; //爆炸马 0 加分 1 加倍 + public static final String ROOM_CONFIG_MAI_NIAO = "mai_niao"; //0无马 1有马 + public static final String ROOM_CONFIG_MAI_NIAO_OPT = "mai_niao_opt"; //1买一码 2买二马 3罚一码 4罚二马 + public static final String ROOM_CONFIG_WU_FENG = "wu_feng"; + public static final String ROOM_CONFIG_LAIZI = "laizi"; ////0 无鬼 1白板做鬼 2翻鬼(随机一个牌做鬼) 3翻双鬼 4红中做鬼 + + public static final String ROOM_CONFIG_QIANGKONG = "qiangkong"; //可抢杠胡 + public static final String ROOM_CONFIG_QIANGKONG_2BEI = "qiangkong_2bei"; //可抢杠胡2倍 + public static final String ROOM_CONFIG_QIANGKONG_MING = "qiangkong_ming"; //明杠可抢 + public static final String ROOM_CONFIG_QIANGKONG_NIAO = "qiangkong_niao"; + public static final String ROOM_CONFIG_NONEALL = "none_is_all"; + public static final String ROOM_CONFIG_NIAO_SCORE = "niao_score"; + public static final String ROOM_CONFIG_QG_TYPE = "qianggang_type"; //抢杠全包 + public static final String ROOM_CONFIG_GANGBAO_TYPE = "gangbao_type"; //杠爆全包 + public static final String ROOM_CONFIG_JIANGMA = "jiangma"; + public static final String ROOM_CONFIG_HZ_HU = "hz_hu"; + public static final String ROOM_CONFIG_GENGZHUAN = "geng_zhuan"; + public static final String ROOM_CONFIG_JIEJIEGAO = "jiejiegao"; + public static final String ROOM_CONFIG_JIEJIEGAO_FIRST_NO = "jiejiegao_first"; + public static final String ROOM_CONFIG_LIAN_ZHUANG = "lian_zhuang"; + public static final String ROOM_CONFIG_WUGUI_JIABEI = "wuguijiabei"; + public static final String ROOM_CONFIG_NO_WAN = "no_wan"; + public static final String ROOM_CONFIG_MA_GEN_DI_FEN = "ma_gen_di_fen";//马跟底分 + public static final String ROOM_CONFIG_MA_GEN_GONG = "ma_gen_gong";//马跟杠 + public static final String ROOM_CONFIG_LIU_GOU_MA = "liu_gou_ma";//留够马牌 + public static final String ROOM_CONFIG_HUANGZHUANGHUANGGANG = "huangzhuang_huanggang";//荒庄荒杠 + public static final String ROOM_CONFIG_LIUJU_2BEI = "liuju_2bei";//流局翻倍 + public static final String ROOM_CONFIG_DAHU_CHENG = "da_hu_cheng";//大胡相乘 + public static final String ROOM_CONFIG_JIHU_NOTCHIHU = "jihunotchihu"; //鸡胡不能吃胡 + public static final String ROOM_CONFIG_XIAOHU_BEI = "xiaohu_bei"; //小胡的倍数另算 + public static final String ROOM_CONFIG_SPECAIL_ZIMO = "special_zimo"; //潮州特殊自摸 + public static final String ROOM_CONFIG_MUST_HU = "must_hu"; //必胡,必须胡牌,不能过 + public static final String ROOM_CONFIG_10_BEI_BUJIFEN = "10bei_bu_jifen"; //十倍不计分 + public static final String ROOM_CONFIG_10_BEI_FENGDING = "10bei_fengding"; //封顶十倍 + public static final String ROOM_CONFIG_ZI_DONG_HU = "zi_dong_hu"; //自动胡 + public static final String ROOM_CONFIG_USE_BASE_HU_SCORE = "use_base_hu_score"; //使用默认基础胡分 + public static final String ROOM_CONFIG_MENG_QING = "men qing"; //门清 + public static final String ROOM_CONFIG_JIHU_SHI_PINGHU = "ji hu shi ping hu"; //没有鸡胡,统一叫平胡 + + public static final String YI_JIAO_LAI_YOU = "lai_you_type"; //0:一脚癞油 1:半癞 2:无癞到底 int + public static final String LIANG_MEN_PAI = "liang_men_pai"; // 两门牌 boolean + public static final String DIAO_YU = "diao_yu"; //钓鱼 boolean + public static final String lian_gun_dai_pai = "lian_gun_dai_pai"; //连滚带爬 boolean + public static final String si_lai_you_xi = "si_lai_you_xi"; //四癞有喜 boolean + public static final String si_lai_you_xi_score = "si_lai_you_xi_score"; //四癞有喜分数 int + public static final String LAIYOU_DIFEN = "laiyou_difen"; //底分 int + public static final String LAIYOU_YILAIDAODI = "laiyou_yilaidaodi"; //一癞到底 int + + public static final String SETTLE_DIAN_PAO = "dian_pao"; + public static final String SETTLE_JIE_PAO = "jie_pao"; + public static final String SETTLE_ZIMO = "zimo"; + public static final String SETTLE_AN_KONG = "an_kong"; + public static final String SETTLE_MING_KONG = "ming_kong"; + + public static final int MING_GANG_SCORE = 3; + public static final int BU_GANG_SCORE = 1; + public static final int AN_GANG_SCORE = 2; + + + public static final int NIAO_TYPE_WU =0; + public static final int NIAO_TYPE_159 =1; + public static final int NIAO_TYPE_ALL =2; //爆炸马 + public static final int NIAO_TYPE_ZHUAMA =3; + + /** + * + */ + 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_MAI_NIAO = "20822"; + + /** + * + */ + public static final String GAME_EVT_PIAONIAO_TIP = "833"; + /** + * + */ + public static final String GAME_EVT_PIAONIAO = "834"; + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXActionEvent.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..db9bbf0 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXActionEvent.java @@ -0,0 +1,18 @@ +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_PIAO_NIAO = "piao_niao"; +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXGameController.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..0c460b2 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXGameController.java @@ -0,0 +1,400 @@ +package extend.mj; + +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; + +import java.util.Collections; +import java.util.Map.Entry; + +/** + * + * + * + * EXGameController.java + */ +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.weight+" 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; + TObject 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); + if (player.getRoom().isLaizi(discard)) + { + response.putBoolean("is_cheng", true); + player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + else { + response.putBoolean("is_cheng", false); + 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; + + + if(Global.loggerDebug) { + Global.logger.info(player + " outcard["+discard+"]"); + } + if (player.getRoom().isLaizi(discard)) + { + player.chengList.add(discard); + Util.removeCard(player.cardInhand, discard, 1); + } + else { + player.outcardList.add(discard); + Util.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + } + + + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){ + 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); + } + EXRoom room = player.getRoom(); + + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type)); + } + room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast); + ((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.cardInhand = owner.card.deal(); + player.laizi_num = Util.cardNum(owner.card.laiziCard, player.cardInhand) + Util.cardNum(owner.card.laiziCard2, player.cardInhand); + Collections.sort(player.cardInhand); + if(Global.loggerDebug) { + Global.logger.info(player + " cardlist:" + player.cardInhand); + } + if (owner.config.getInt(Config.ROOM_CONFIG_MAI_NIAO) == 1) + { + int maiNiaoOpt = owner.config.getInt(Config.ROOM_CONFIG_MAI_NIAO_OPT); + //买一马 + if (maiNiaoOpt == 1) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + //买二马 + else if (maiNiaoOpt == 2) + { + for(int i = 0; i < 2; i++) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + //罚一马 + else if (maiNiaoOpt == 3) + { + if (player.seat == owner.bankerSeat) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + //罚二马 + else if (maiNiaoOpt == 4) + { + if (player.seat == owner.bankerSeat) + { + for(int i = 0; i < 2; i++) + { + CardNiao niao = new CardNiao(); + niao.playerId = player.playerid; + niao.seat = player.seat; + niao.card = owner.card.pop(); + niao.score = 0; + player.mai_niao.add(niao); + } + } + } + } + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + param.putInt("laiziCard", owner.card.laiziCard); + param.putInt("laiziCard2", owner.card.laiziCard2); + param.putInt("laiziCardBefore", owner.card.laiziCardBefore); + param.putInt("laiziCard2Before", owner.card.laiziCard2Before); + 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(); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + public void winEvent(EXPlayer owner,int from_seat,int win_card) { + 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("win_card", win_card); + param.putInt("from_seat", from_seat); + ITArray array = CardUtil.toMPData_WinMap(owner.winMap); + if (array != null) { + param.putTArray("win_list", array); + } + if(Global.loggerDebug) { + Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]"); + } + 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); + } + + public void sendMaiNiaoEvt(EXPlayer owner, int seat) { + EXRoom room = owner.getRoom(); + ITObject param = new TObject(); + ITArray array = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (int index = 0; index < player.mai_niao.size(); index++) { + array.addTObject(player.mai_niao.get(index).toMP()); + } + } + + param.putTArray("mai_niao", array); + param.putInt("start_seat", seat); + + room.broadCastToClient(0, Config.GAME_EVT_MAI_NIAO, param); + ((EXPlayBack)room.playBackData).addMaiNiaoCommand(owner.seat, 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); + } + + private ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + 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 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("hu_score", player.score.round_log.get(EXScore.WIN)); + param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO)); + param.putInt("gang_score", player.score.round_log.get(EXScore.KONG)); + param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO)); + param.putInt("geng_zhuan", player.score.round_log.get(EXScore.GENG_ZHUAN)); + param.putInt("ma_geng_gong", player.score.round_log.get(EXScore.MA_GENG_GONG)); + param.putInt("zhong_jiang", player.score.round_log.get(EXScore.ZHONG_JIANG)); + if ((owner.config.getBoolean(Config.ROOM_CONFIG_JIEJIEGAO) || owner.config.getBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG)) && player.repeat_win > 0) + { + param.putInt("repeat_win", player.repeat_win); + } + else + { + param.putInt("repeat_win", 0); + } + + param.putInt("mai_niao_score", player.score.round_log.get(EXScore.MAI_NIAO)); + player.hp_info(param); + 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); + } + ITArray mai_niao = new TArray(); + for (int index = 0; index < player.mai_niao.size(); index++) { + mai_niao.addTObject(player.mai_niao.get(index).toMP()); + } + param.putTArray("mai_niao", mai_niao); + param.putInt("ming_gang_num", player.ming_gang_num); + param.putInt("an_gang_num", player.an_gang_num); + param.putInt("dian_gang_num", player.dian_gang_num); + param.putInt("cheng_num", player.cheng_num); + param.putInt("fang_jian_num", player.fang_jian_num); + param.putInt("zhong_jiang_num", player.zhong_jiang_num); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + 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); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.playBackData.addResult(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXMainServer.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..b3d124f --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXMainServer.java @@ -0,0 +1,89 @@ +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.*; +import extend.mj.player.state.*; +import extend.mj.room.state.EXRoomDealState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.room.state.EXRoomStartGameState; + +/** + * + * + * EXMainServer.java + */ +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(EXPlayerKongDrawState.class, new EXPlayerKongDrawState()); + Global.registerState(EXPlayerChengDrawState.class, new EXPlayerChengDrawState()); + + 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(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + Global.registerState(PROtherKongState.class, new PROtherKongState()); + Global.registerState(PROtherWinState.class, new PROtherWinState()); + Global.registerState(PRPongKongWinState.class, new PRPongKongWinState()); + 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(PROtherGongSelfWinState.class, new PROtherGongSelfWinState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayBack.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..89db544 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayBack.java @@ -0,0 +1,75 @@ +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()); + info.putInt("laiziCard", room.card.laiziCard); + info.putInt("laiziCard2", room.card.laiziCard2); + info.putInt("laiziCardBefore", room.card.laiziCardBefore); + info.putInt("laiziCard2Before", room.card.laiziCard2Before); + } + + 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){ + 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); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + + public void addMaiNiaoCommand(int seat,ITObject param){ + addCommand("Mai_Niao",seat,param); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayer.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..696da34 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXPlayer.java @@ -0,0 +1,215 @@ +package extend.mj; + +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; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + * + * + * 2017��8��30�� + * EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + + // ������ + public List outcardList; + + public ITArray opCard; + + public List pongGroup; + public List kongGroup; + public List selfKongGroup; + public List opCardList; + + public int drawCard = 0; + public int winCard = 0; + + public TipManager tipMgr; + + public SettleLog settleLog; + + /** + * ©�� + */ + public boolean louhu = false; + + /** + * ǿ�Ƽ����� + */ + public boolean forceCheckWin = false; + /** + * 0 С�� 1 ���ܺ� + */ + public int winType = 0; + + /** + * 0 无 1 胡 2 输 + */ + public int last_winer = 0; + + public List notPongKongList = new ArrayList<>(); + public List notPongList = new ArrayList<>(); + public List chengList = new ArrayList<>(); + public int niaoCount; + public int piaoNiao; + + public int repeat_win; + + public Map winMap; + + public int niao_score; + + public int hu_score; + + public int di_score; + + public ArrayList mai_niao; + + public int ming_gang_num = 0; + public int an_gang_num = 0; + public int dian_gang_num = 0; + public int cheng_num = 0; + public int fang_jian_num = 0; + public int zhong_jiang_num = 0; + public int laizi_num = 0; + public boolean is_cheng = false; + public boolean is_fang_jian_gang = false; + + public boolean tinghu10bei = false; + + public boolean gangshangpao = false; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + + pongGroup = new ArrayList<>(); + kongGroup = new ArrayList<>(); + selfKongGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + + opCard = new TArray(); + + tipMgr = new TipManager(this); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_DIAN_PAO, 0); + settleLog.put(Config.SETTLE_JIE_PAO, 0); + settleLog.put(Config.SETTLE_ZIMO, 0); + settleLog.put(Config.SETTLE_AN_KONG, 0); + settleLog.put(Config.SETTLE_MING_KONG, 0); + + repeat_win = -1; + niao_score = 2; + hu_score = 0; + di_score = 0; + + ming_gang_num = 0; + an_gang_num = 0; + dian_gang_num = 0; + + last_winer = 0; + + tinghu10bei = false; + gangshangpao = false; + + this.mai_niao = 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); + ITArray chengList = Util.toTArray(this.chengList); + playerData.putTArray("cheng_list", chengList); + playerData.putInt("card_count", cardInhand.size()); + playerData.putInt("score", score.total_score); + playerData.putInt("piao_niao", this.piaoNiao); + 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) + { + List tempOpCard = new ArrayList<>(); + for(int i = 0; i < opcard.opcard.length; i++) + { + if (opcard.opcard[i] > 0) + { + tempOpCard.add(opcard.opcard[i]); + } + } + opcardParam.putTArray("opcard", Util.toTArray(tempOpCard)); + } + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + + return playerData; + } + + public void clear() { + super.clear(); + this.cardInhand.clear(); + this.notPongKongList.clear(); + this.notPongList.clear(); + this.winer = 0; + this.louhu = false; + this.outcardList.clear(); + this.drawCard = 0; + this.kongGroup.clear(); + this.pongGroup.clear(); + this.selfKongGroup.clear(); + this.opCardList.clear(); + this.score.resetRound(); + this.niaoCount = 0; + this.piaoNiao = 0; + this.winMap = null; + this.niao_score = 2; + this.hu_score = 0; + this.di_score = 0; + this.mai_niao.clear(); + this.ming_gang_num = 0; + this.an_gang_num = 0; + this.dian_gang_num = 0; + this.tinghu10bei = false; + this.cheng_num = 0; + this.fang_jian_num = 0; + this.zhong_jiang_num = 0; + this.laizi_num = 0; + this.is_fang_jian_gang = false; + this.chengList.clear(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXRoom.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..8d6db7d --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,2565 @@ +package extend.mj; + +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.player.state.EXPlayerDisCardTipState; +import extend.mj.tip.Action; +import extend.mj.tip.TipManager; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winCount = 0; + public boolean liuju = false; + public boolean last_liuju = false; + + public ArrayList niao; + + public int piaoNiaoCount; + public int adminSeat = 0; + public int lastWinPlayerId = 0; + public boolean isGengZhuang = false; + public int first_zhuang_card = 0; + public int geng_zhuan_num = 0; + public int gent_zhuan_nextSeat = 0; + /* + * 上一次庄家座位号 + */ + public int lastBankerSeat = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.niao = new ArrayList(); + + if (!this.config.containsKey(Config.ROOM_CONFIG_DIANPAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HUNYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HUNYISE, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QINGYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QINGYISE, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_PENGPENGHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_PENGPENGHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHISHANGYAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHISHANGYAO, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_TIANDIHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_TIANDIHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SHIBALUOHAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASHANYUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASHANYUAN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_DASIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DASIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSIXI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOSIXI, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_LOUHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LOUHU, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_PENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GUO_PENG, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_GONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GUO_GONG, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false); + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO, true); + + //可抢杠胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG, false); + } + + //可抢杠胡2倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_2BEI, false); + } + + //明杠可抢 + if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_MING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_MING, false); + } + + //抢杠全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_QG_TYPE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QG_TYPE, false); + } + + //杠爆全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGBAO_TYPE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGBAO_TYPE, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU, false); + + if (!this.config.containsKey(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GENGZHUAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LIAN_ZHUANG)) { + this.config.putBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_JIABEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NO_WAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_NO_WAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_4BEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_GONG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_GONG, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WU_FENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WU_FENG, false); + } + + this.config.putBoolean(Config.ROOM_CONFIG_PIAO_NIAO, false); + + ////幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_YAO_JIU, false); + } + + //清幺九 + if (!this.config.containsKey(Config.ROOM_CONFIG_QING_YAO_JIU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QING_YAO_JIU, false); + } + + //有没有癞子 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI)) + { + this.config.putInt(Config.ROOM_CONFIG_LAIZI, 0); + } + + //四鬼胡牌 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false); + } + + //四鬼胡牌两倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU_2BEI, false); + } + + //全风 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG, false); + } + + ////12张落地全包 + if (!this.config.containsKey(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO, false); + } + + ////留够马牌 + if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false); + } + + //全求人 + if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE, false); + } + + // ROOM_CONFIG_han19 = "han19"; //含19即可 + if (!this.config.containsKey(Config.ROOM_CONFIG_han19)) + { + this.config.putBoolean(Config.ROOM_CONFIG_han19, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_ZIYISE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZIYISE, false); + } + + + //大胡相乘 + if (!this.config.containsKey(Config.ROOM_CONFIG_DAHU_CHENG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_DAHU_CHENG, false); + } + + //鸡胡不能吃胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_NOTCHIHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU, false); + } + + //小胡的倍数另算 + if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOHU_BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIAOHU_BEI, false); + } + + //流局两倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_LIUJU_2BEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIUJU_2BEI, false); + } + + //荒庄荒杠 + if (!this.config.containsKey(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG, false); + } + + //潮州特殊自摸 + if (!this.config.containsKey(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + this.config.putBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO, false); + } + + //必胡,必须胡牌,不能过 + if (!this.config.containsKey(Config.ROOM_CONFIG_MUST_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MUST_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false); + } + + //买马,提前预定马,猜谁胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO, 0); + } + + //买马值 + if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO_OPT)) + { + this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO_OPT, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_DI_FEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_DI_FEN, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT, 0); + } + + //10倍不计分 + if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_BUJIFEN)) + { + this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_BUJIFEN, false); + } + + //封顶十倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_FENGDING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_FENGDING, false); + } + + //自动胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_ZI_DONG_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_ZI_DONG_HU, false); + } + + //海底捞月 + //自动胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE, false); + } + + ////使用默认基础胡分 + if (!this.config.containsKey(Config.ROOM_CONFIG_USE_BASE_HU_SCORE)) + { + this.config.putBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE, false); + } + + //门清 + if (!this.config.containsKey(Config.ROOM_CONFIG_MENG_QING)) + { + this.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, false); + } + + //没有鸡胡,统一叫平胡 + if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU, false); + } + + //杠上炮2倍 + if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei, false); + } + + if (!this.config.containsKey(Config.YI_JIAO_LAI_YOU)) + { + this.config.putInt(Config.YI_JIAO_LAI_YOU, 0); + } + + if (this.config.getInt(Config.YI_JIAO_LAI_YOU) == 2) + { + this.config.putInt(Config.ROOM_CONFIG_LAIZI, 0); + } + + if (!this.config.containsKey(Config.LAIYOU_DIFEN)) { + this.config.putInt(Config.LAIYOU_DIFEN, 1); + } + else { + this.config.putInt(Config.LAIYOU_DIFEN, this.config.getInt(Config.LAIYOU_DIFEN)+1); + } + + if (!this.config.containsKey(Config.LAIYOU_YILAIDAODI)) + { + this.config.putBoolean(Config.LAIYOU_YILAIDAODI, false); + } + + if (!this.config.containsKey(Config.LIANG_MEN_PAI)) + { + this.config.putBoolean(Config.LIANG_MEN_PAI, false); + } + + if (!this.config.containsKey(Config.DIAO_YU)) + { + this.config.putBoolean(Config.DIAO_YU, false); + } + + if (!this.config.containsKey(Config.lian_gun_dai_pai)) + { + this.config.putBoolean(Config.lian_gun_dai_pai, false); + } + + if (!this.config.containsKey(Config.si_lai_you_xi)) + { + this.config.putBoolean(Config.si_lai_you_xi, false); + } + + if (!this.config.containsKey(Config.si_lai_you_xi_score)) + { + this.config.putInt(Config.si_lai_you_xi_score, 0); + } + + this.isEntrust=true; + this.adminSeat = 0; + this.lastWinPlayerId =0; + + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + + this.lastBankerSeat = 0; + this.last_liuju = false; + + //初始化房间的特殊参数 + WinCardType.InitRoomSpecialConfig(this); + } + + public boolean isLiuJu() + { + boolean liugouma = this.config.getBoolean(Config.ROOM_CONFIG_LIU_GOU_MA); + if (liugouma) + { + int num = getNiaoNum(0, true); + if (card.cardList.size() <= num) + { + return true; + } + } + else + { + if (card.cardList.size() == 0) + { + return true; + } + } + + return false; + } + + public void endGameByLiuJu() + { + if (config.getBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG)) + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + int score = player.score.round_log.get(EXScore.KONG); + player.score.round_score -= score; + player.score.total_score -= score; + player.score.round_log.put(EXScore.KONG, 0); + } + } + liuju = true; + clear_repeatwin(); + + endGame(); + } + + public void endGame() + { + last_liuju = liuju; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer != 1) + { + player.last_winer = 0; + player.repeat_win = -1; + } + else + { + player.last_winer = 1; + } + } + super.endGame(); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + + checkAction(); + } + + public boolean isLaizi(int card) { + return this.card.isLaizi(card); + } + + public boolean isFanPai(int card) { + return this.card.isFanPai(card); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + + } + + /** + * 获取房间信息 + * + * @return + */ + public ITObject getRoomInfo() { + ITObject data = super.getRoomInfo(); + if (data != null) + { + data.putInt("laiziCard", this.card.laiziCard); + data.putInt("laiziCard2", this.card.laiziCard2); + data.putInt("laiziCardBefore", this.card.laiziCardBefore); + data.putInt("laiziCard2Before", this.card.laiziCard2Before); + } + + return data; + } + + 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); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN); + if(type == EXScore.WIN) { + if (zhuangxian) { + if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) { + score += 1; + } + } + } + + if (type == EXScore.WIN || type == EXScore.NIAO) + { + if (fromPlayer.tinghu10bei) + { + 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 addMaGengGongScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.MA_GENG_GONG); + } + + public void addAllMaGengGongScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addMaGengGongScore(destPlayer, fromPlayer, score); + } + } + + public int GetGongScore(EXPlayer destPlayer) + { + return destPlayer.score.round_log.get(EXScore.KONG); + } + + public void addAllScore(EXPlayer destPlayer, int socre, int type) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + this.addScore(destPlayer, fromPlayer, socre, type); + } + } + + public void addMaiNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.MAI_NIAO); + } + + public void addAllMaiNiaoScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addMaiNiaoScore(destPlayer, fromPlayer, score); + } + } + + public void addNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) { + this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO); + } + + public void addAllNiaoScore(EXPlayer destPlayer, int score) { + for (Entry 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) { + boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if(!piao_niao)return; + this.addScore(destPlayer, fromPlayer,destPlayer.piaoNiao + fromPlayer.piaoNiao , EXScore.PIAO_NIAO); + } + + public void addAllPiaoNiaoScore(EXPlayer destPlayer) { + boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if(!piao_niao)return; + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addPiaoNiaoScore(destPlayer,fromPlayer); + } + } + + public void CountMaGengGongScore() { + boolean maGenGong = config.getBoolean(Config.ROOM_CONFIG_MA_GEN_GONG); + if (maGenGong) + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1 && player.niaoCount > 0) + { + for(int i = 0; i < player.opCardList.size(); i++) + { + OpCard op_card = player.opCardList.get(i); + //明杠 + if (op_card.type == RuleWeight.TYPE_KONG && op_card.card_seat > 0) + { + EXPlayer gangPlayer = (EXPlayer) this.playerMapBySeat.get(op_card.card_seat); + if (gangPlayer != null) + { + addMaGengGongScore(player, gangPlayer, Config.MING_GANG_SCORE * player.niaoCount); + } + } + //补杠 + else if (op_card.type == RuleWeight.TYPE_KONG && op_card.card_seat == 0) + { + addAllMaGengGongScore(player, Config.BU_GANG_SCORE * player.niaoCount); + } + //暗杠 + else if (op_card.type == RuleWeight.TYPE_SELF_KONG) + { + addAllMaGengGongScore(player, Config.AN_GANG_SCORE * player.niaoCount); + } + } + } + } + } + } + + private int getNiaoNum(int card, boolean zimo) { + int niao_num = 0; + int niao = this.config.getInt(Config.ROOM_CONFIG_NIAO); + switch (niao) { + case Config.NIAO_TYPE_WU: + niao_num = 0; + break; + case Config.NIAO_TYPE_159: + int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + niao_num = opt * 2; + break; + case Config.NIAO_TYPE_ALL: + niao_num = 1; + break; + case Config.NIAO_TYPE_ZHUAMA: + if (zimo) + { + niao_num = 2; + } + else + { + niao_num = 1; + } + break; + } + return niao_num; + } + + public void handle_repeatwin(EXPlayer owner) + { + if (owner.last_winer == 1) + { + owner.repeat_win += 1; + } + else + { + owner.repeat_win += 1; + } + } + + public void clear_repeatwin() + { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.repeat_win = -1; + player.last_winer = 0; + } + } + + public void niao_tongPao(int card) { + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + + __zhuaNiao(dianPaoPlayer, getNiaoNum(card, false), true); + + List winPlayerList = new ArrayList(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.winer == 1) { + ((EXPlayer)player).niaoCount = 0; + winPlayerList.add((EXPlayer) player); + } + } + + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + for (CardNiao cn : niao) { + if (dianPaoPlayer.playerid == cn.playerId) { + if (zhua_ma) + { + dianPaoPlayer.niaoCount ++; + cn.score = 0; + for (EXPlayer winer : winPlayerList) { + int score = winer.hu_score; + cn.score += score; + this.addNiaoScore(winer, dianPaoPlayer, score); + } + } + else + { + dianPaoPlayer.niaoCount ++; + //爆炸马 加倍的情况 + if (dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + int real_score = 0; + for (EXPlayer winer : winPlayerList) { + int score = cn.score * winer.hu_score; + real_score += score; + this.addNiaoScore(winer, dianPaoPlayer, score); + } + + cn.score = real_score; + } + else if (dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + int real_score = 0; + for (EXPlayer winer : winPlayerList) { + int score = cn.score; + real_score += score; + this.addNiaoScore(winer, dianPaoPlayer, score); + } + + cn.score = real_score; + } + } + } else { + if (zhua_ma) + { + int real_score = 0; + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + int score = winer.hu_score; + real_score += score; + this.addNiaoScore(winer, dianPaoPlayer, score); + winer.niaoCount ++; + break; + } + } + cn.score = real_score; + } + //爆炸马 加倍的情况 + else if (dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) { + } + else if (dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && dianPaoPlayer.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) { + } + else + { + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + int score = cn.score; + this.addNiaoScore(winer, dianPaoPlayer, score); + winer.niaoCount ++; + break; + } + } + } + } + } + + CountMaGengGongScore(); + + EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat); + + dianpao_countMaiMa(dianPaoPlayer); + } + + public void niao_tongPao_quanbao(int card, boolean quanbao, boolean zimo) { + if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) { + return; + } + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + + __zhuaNiao(dianPaoPlayer, getNiaoNum(card, zimo), true); + + List winPlayerList = new ArrayList(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.winer == 1) { + ((EXPlayer)player).niaoCount = 0; + winPlayerList.add((EXPlayer) player); + } + } + + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + if (quanbao) + { + for (CardNiao cn : niao) { + if (zhua_ma) + { + cn.score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + if (player.winer == 1) + { + int score = player.hu_score; + score = score * (this.maxPlayers - 1); + cn.score += score; + this.addNiaoScore(player, dianPaoPlayer, score); + } + else + { + for (EXPlayer winer : winPlayerList) { + int score = winer.hu_score; + score = score * (this.maxPlayers - 1); + cn.score += score; + this.addNiaoScore(player, dianPaoPlayer, score); + } + } + break; + } + } + } + //爆炸马 加倍的情况 + else if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + if (dianPaoPlayer.playerid == cn.playerId) + { + dianPaoPlayer.niaoCount ++; + for (EXPlayer winer : winPlayerList) { + int score = cn.score * winer.hu_score; + score = score * (this.maxPlayers - 1); + this.addNiaoScore(winer, dianPaoPlayer, score); + } + } + } + else if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + if (dianPaoPlayer.playerid == cn.playerId) + { + dianPaoPlayer.niaoCount ++; + for (EXPlayer winer : winPlayerList) { + int score = cn.score; + score = score * (this.maxPlayers - 1); + this.addNiaoScore(winer, dianPaoPlayer, score); + } + } + } + else + { + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + int score = winer.hu_score; + score = score * (this.maxPlayers - 1); + this.addNiaoScore(winer, dianPaoPlayer, score); + winer.niaoCount ++; + break; + } + } + } + } + } + else + { + for (CardNiao cn : niao) { + if (zhua_ma) + { + cn.score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + if (player.winer == 1) + { + int score = player.hu_score; + cn.score += score; + this.addAllNiaoScore(player, score); + } + else + { + for (EXPlayer winer : winPlayerList) { + int score = winer.hu_score; + cn.score += score; + this.addNiaoScore(winer, player, score); + } + } + break; + } + } + } + //爆炸马 加倍的情况 + else if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + if (dianPaoPlayer.playerid == cn.playerId) + { + dianPaoPlayer.niaoCount ++; + for (EXPlayer winer : winPlayerList) { + int score = cn.score * winer.hu_score; + this.addAllNiaoScore(winer, score); + } + } + } + else if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + if (dianPaoPlayer.playerid == cn.playerId) + { + dianPaoPlayer.niaoCount ++; + for (EXPlayer winer : winPlayerList) { + int score = cn.score; + this.addAllNiaoScore(winer, score); + } + } + } + else + { + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + int score = cn.score; + this.addAllNiaoScore(winer, score); + winer.niaoCount ++; + break; + } + } + } + } + } + + CountMaGengGongScore(); + + EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat); + + dianpao_countMaiMa(dianPaoPlayer); + } + + public void niao_dianPao(EXPlayer owner, int card) { + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + EXPlayer winer = owner; + EXRoom room = owner.getRoom(); + int num = getNiaoNum(card, false); + __zhuaNiao(owner, num, false); + + for (Entry entry : owner.room.playerMapById.entrySet()) { + ((EXPlayer)entry.getValue()).niaoCount = 0; + } + + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + for (CardNiao cn : niao) { + if (cn.playerId == winer.playerid || dianPaoPlayer.playerid == cn.playerId) { + if (cn.playerId == winer.playerid) { + winer.niaoCount++; + } + else if (dianPaoPlayer.playerid == cn.playerId) + { + dianPaoPlayer.niaoCount++; + } + + if (zhua_ma) + { + this.addNiaoScore(winer, dianPaoPlayer, cn.score); + } + //爆炸马 加倍的情况 + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + this.addNiaoScore(winer, dianPaoPlayer, cn.score); + } + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + this.addNiaoScore(winer, dianPaoPlayer, cn.score); + } + else + { + this.addNiaoScore(winer, dianPaoPlayer, cn.score); + } + } + } + + CountMaGengGongScore(); + + EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat); + dianpao_countMaiMa(dianPaoPlayer); + } + + public void niao_dianPao_quanbao(EXPlayer owner, int card, boolean quanbao, boolean zimo) { + if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) { + return; + } + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + EXPlayer winer = owner; + int num = getNiaoNum(card, zimo); + __zhuaNiao(owner, num, false); + + for (Entry entry : owner.room.playerMapById.entrySet()) { + ((EXPlayer)entry.getValue()).niaoCount = 0; + } + + if (quanbao == false && zimo == true) + { + if (config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = get12ZhangLuoDi(owner); + dianPaoPlayer = badPlayer; + quanbao = true; + } + } + + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + if (quanbao) + { + for (CardNiao cn : niao) { + if (cn.playerId == owner.playerid) { + if (zhua_ma) { + this.addNiaoScore(owner, dianPaoPlayer,cn.score * (this.maxPlayers - 1)); + } + //爆炸马 加倍的情况 + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) { + this.addNiaoScore(owner, dianPaoPlayer,cn.score * (this.maxPlayers - 1)); + } else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) { + this.addNiaoScore(owner, dianPaoPlayer,cn.score * (this.maxPlayers - 1)); + } else { + this.addNiaoScore(owner, dianPaoPlayer,cn.score * (this.maxPlayers - 1)); + } + + owner.niaoCount++; + } else { + if (zhua_ma) { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount++; + this.addNiaoScore(owner, dianPaoPlayer, cn.score); + break; + } + } + } + } + } + } + else + { + for (CardNiao cn : niao) { + if (cn.playerId == owner.playerid) { + if (zhua_ma) { + this.addAllNiaoScore(owner, cn.score); + } + //爆炸马 加倍的情况 + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + this.addAllNiaoScore(owner, cn.score); + } + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + this.addAllNiaoScore(owner, cn.score); + } + else + { + this.addAllNiaoScore(owner, cn.score); + } + + owner.niaoCount++; + } else { + if (zhua_ma) { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + this.addNiaoScore(owner, player, cn.score); + break; + } + } + } + } + } + } + + CountMaGengGongScore(); + + EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat); + zimo_countMaiMa(owner); + } + + public void niao_selfWin(EXPlayer owner, int card) { + if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) { + return; + } + int num = getNiaoNum(card, true); + + __zhuaNiao(owner, num, false); + + for (Entry entry : owner.room.playerMapById.entrySet()) { + ((EXPlayer)entry.getValue()).niaoCount = 0; + } + + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + for (CardNiao cn : niao) { + if (cn.playerId == owner.playerid) { + if (zhua_ma) + { + if (this.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && this.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = this.get12ZhangLuoDi(owner); + this.addScore(owner,badPlayer, cn.score * (this.maxPlayers - 1), EXScore.WIN); + } + else + { + this.addAllNiaoScore(owner, cn.score); + } + } + //爆炸马 加倍的情况 + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 1) + { + if (this.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && this.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = this.get12ZhangLuoDi(owner); + this.addScore(owner,badPlayer, cn.score * (this.maxPlayers - 1), EXScore.WIN); + } + else + { + this.addAllNiaoScore(owner, cn.score); + } + } + else if (owner.room.config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL && owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT) == 0) + { + if (this.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && this.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = this.get12ZhangLuoDi(owner); + this.addScore(owner,badPlayer, cn.score * (this.maxPlayers - 1), EXScore.WIN); + } + else + { + this.addAllNiaoScore(owner, cn.score); + } + } + else + { + if (this.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && this.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = this.get12ZhangLuoDi(owner); + this.addScore(owner,badPlayer, cn.score * (this.maxPlayers - 1), EXScore.WIN); + } + else + { + this.addAllNiaoScore(owner, cn.score); + } + } + owner.niaoCount++; + } else { + if (zhua_ma) + { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + if (this.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && this.get12ZhangLuoDi(owner) != null) { + EXPlayer badPlayer = this.get12ZhangLuoDi(owner); + this.addNiaoScore(owner, badPlayer, cn.score); + } + else { + this.addNiaoScore(owner, player, cn.score); + } + break; + } + } + } + } + } + + CountMaGengGongScore(); + + EXMainServer.gameCtr.sendNiaoEvt(owner, owner.seat); + + zimo_countMaiMa(owner); + } + + private void dianpao_countMaiMa(EXPlayer diaoPaoPlayer) + { + if (this.config.getInt(Config.ROOM_CONFIG_MAI_NIAO) <= 0) + { + return; + } + + int winer_num = 0; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) + { + winer_num++; + } + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid != diaoPaoPlayer.playerid) + { + for (Entry win_entry : this.playerMapById.entrySet()) { + EXPlayer win_player = (EXPlayer) win_entry.getValue(); + if (win_player.winer == 1) + { + int seat = 0; + if (winer_num == 1) + { + seat = this.lastBankerSeat; + } + else if (winer_num > 1) + { + seat = diaoPaoPlayer.seat; + } + + int zhong_ma_num = countPlayerMaiMaZhongMaNum(player, win_player, seat); + if (zhong_ma_num > 0) + { + addMaiNiaoScore(player, diaoPaoPlayer, win_player.hu_score*zhong_ma_num); + } + } + } + } + + if (player.winer != 1) + { + int seat = 0; + if (winer_num == 1) + { + seat = this.lastBankerSeat; + } + else if (winer_num > 1) + { + seat = diaoPaoPlayer.seat; + } + + int zhong_ma_num = countPlayerMaiMaZhongMaNum(player, diaoPaoPlayer, seat); + if (zhong_ma_num > 0) + { + for (Entry win_entry : this.playerMapById.entrySet()) { + EXPlayer win_player = (EXPlayer) win_entry.getValue(); + if (win_player.winer == 1) { + addMaiNiaoScore(win_player, player, win_player.hu_score*zhong_ma_num); + } + } + } + } + } + + EXMainServer.gameCtr.sendMaiNiaoEvt(diaoPaoPlayer, diaoPaoPlayer.seat); + } + + private void zimo_countMaiMa(EXPlayer owner) + { + if (this.config.getInt(Config.ROOM_CONFIG_MAI_NIAO) <= 0) + { + return; + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (owner.playerid == player.playerid) + { + int zhong_ma_num = countPlayerMaiMaZhongMaNum(owner, owner, this.lastBankerSeat); + if (zhong_ma_num > 0) + { + addAllMaiNiaoScore(owner, owner.hu_score*zhong_ma_num); + } + } + else if (player.winer != 1) + { + int zhong_ma_num = countPlayerMaiMaZhongMaNum(player, owner, this.lastBankerSeat); + if (zhong_ma_num > 0) + { + for (Entry entry2 : this.playerMapById.entrySet()) { + EXPlayer player2 = (EXPlayer) entry2.getValue(); + if (player2.winer != 1 && player2.playerid != owner.playerid && player2.playerid != player.playerid) + { + addMaiNiaoScore(player, player2, owner.hu_score*zhong_ma_num); + } + } + } + + for (Entry entry2 : this.playerMapById.entrySet()) { + EXPlayer player2 = (EXPlayer) entry2.getValue(); + if (player2.playerid != owner.playerid) + { + int zhong_ma_num2 = countPlayerMaiMaZhongMaNum(player, player2, this.lastBankerSeat); + if (zhong_ma_num2 > 0) + { + addMaiNiaoScore(owner, player, owner.hu_score*zhong_ma_num2); + } + } + } + } + } + + EXMainServer.gameCtr.sendMaiNiaoEvt(owner, owner.seat); + } + + private int countPlayerMaiMaZhongMaNum(EXPlayer owner, EXPlayer other, int start_seat) { + int zhong_ma_num = 0; + if (this.maxPlayers == 3) + { + for (int i = 0; i < owner.mai_niao.size(); i++) { + CardNiao cn = owner.mai_niao.get(i); + int card = cn.card; + int tem = card % 100; + if (start_seat == other.seat) { + if (card < 400) { + if (tem == 1 || tem == 4 || tem == 7) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.DONGFENG || card == Config.BEIFENG || card == Config.BAIBAN) { + cn.score = 1; + zhong_ma_num++; + } + } + } else if ((start_seat) % this.maxPlayers + 1 == other.seat && this.maxPlayers >= 2) { + if (card < 400) { + if (tem == 2 || tem == 5 || tem == 8) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.NANFENG || card == Config.HONGZHONG) { + cn.score = other.hu_score; + zhong_ma_num++; + } + } + } else if ((start_seat + 1) % this.maxPlayers + 1 == other.seat && this.maxPlayers >= 3) { + if (card < 400) { + if (tem == 3 || tem == 6 || tem == 9) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.XIFENG || card == Config.FACAI) { + cn.score = 1; + zhong_ma_num++; + } + } + } + } + } + else { + for (int i = 0; i < owner.mai_niao.size(); i++) { + CardNiao cn = owner.mai_niao.get(i); + int card = cn.card; + int tem = card % 100; + if (start_seat == other.seat) { + if (card < 400) { + if (tem == 1 || tem == 5 || tem == 9) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.DONGFENG || card == Config.HONGZHONG) { + cn.score = 1; + zhong_ma_num++; + } + } + } else if ((start_seat) % this.maxPlayers + 1 == other.seat && this.maxPlayers >= 2) { + if (card < 400) { + if (tem == 2 || tem == 6) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.NANFENG || card == Config.FACAI) { + cn.score = other.hu_score; + zhong_ma_num++; + } + } + } else if ((start_seat + 1) % this.maxPlayers + 1 == other.seat && this.maxPlayers >= 3) { + if (card < 400) { + if (tem == 3 || tem == 7) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.XIFENG || card == Config.BAIBAN) { + cn.score = 1; + zhong_ma_num++; + } + } + } else if ((start_seat + 2) % this.maxPlayers + 1 == other.seat && this.maxPlayers >= 4) { + if (card < 400) { + if (tem == 4 || tem == 8) { + cn.score = 1; + zhong_ma_num++; + } + } else { + if (card == Config.BEIFENG) { + cn.score = 1; + zhong_ma_num++; + } + } + } + } + } + + return zhong_ma_num; + } + + private final void baozhama_jiabei_zhuaNiao(EXPlayer owner, int niao_num, int allscore) { + this.niao.clear(); + if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_WU) + { + return; + } + + boolean niao_all = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL; + for (int index = 0; index < niao_num; index++) { + if (card.cardList.size() == 0) { + break; + } + + int card = this.card.pop(); + CardNiao cn = new CardNiao(); + cn.card = card; + this.niao.add(cn); + int tem = card % 100; + if (niao_all) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + if (card >= 400 || card == this.card.laiziCard || card == this.card.laiziCard2) { + cn.score = 10 * allscore; + } else { + cn.score = tem * allscore; + } + } + } + } + + private final void __zhuaNiao(EXPlayer owner, int niao_num, boolean isYiPaoDuoXiang) { + this.niao.clear(); + if (config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_WU) + { + return; + } + + int cur_niao_score = owner.niao_score; + boolean magengdi = config.getBoolean(Config.ROOM_CONFIG_MA_GEN_DI_FEN); + boolean zhua_ma = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ZHUAMA; + boolean niao_all = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL; + int niao_all_opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + if (magengdi || zhua_ma) + { + cur_niao_score = owner.hu_score; + } + + for (int index = 0; index < niao_num; index++) { + if (card.cardList.size() == 0) { + break; + } + + int card = this.card.pop(); + CardNiao cn = new CardNiao(); + cn.card = card; + this.niao.add(cn); + int tem = card % 100; + if (niao_all) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + if (niao_all_opt == 0) + { + if (card >= 400 || card == this.card.laiziCard || card == this.card.laiziCard2) { + cn.score = 10 * cur_niao_score; + } else { + cn.score = tem * cur_niao_score; + } + } + else if (niao_all_opt == 1) + { + if (isYiPaoDuoXiang) + { + if (card >= 400 || card == this.card.laiziCard || card == this.card.laiziCard2) { + cn.score = 10; + } else { + cn.score = tem; + } + } + else + { + if (card >= 400 || card == this.card.laiziCard || card == this.card.laiziCard2) { + cn.score = 10 * owner.hu_score; + } else { + cn.score = tem * owner.hu_score; + } + } + } + } + else if (zhua_ma) + { + EXPlayer bankerPlayer = (EXPlayer)this.playerMapBySeat.get(this.lastBankerSeat); + if (this.maxPlayers == 2) + { + if (card < 400) + { + if (tem == 1 || tem == 3 || tem == 5 || tem == 7 || tem == 9) { + if (bankerPlayer != null) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } + else if (tem == 2 || tem == 4 || tem == 6 || tem == 8) { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get(bankerPlayer.nextSeat); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + else + { + if (card == Config.NANFENG || card == Config.BEIFENG || card == Config.FACAI) + { + if (bankerPlayer != null) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } + else if (card == Config.DONGFENG || card == Config.XIFENG || card == Config.HONGZHONG || card == Config.BAIBAN) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get(bankerPlayer.nextSeat); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + } + else if (this.maxPlayers == 3) { + if (card < 400) { + if (tem == 1 || tem == 4 || tem == 7) { + if (bankerPlayer != null) { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } else if (tem == 2 || tem == 5 || tem == 8) { + if (this.maxPlayers >= 2) { + EXPlayer otherPlayer = (EXPlayer) this.playerMapBySeat.get((this.lastBankerSeat) % this.maxPlayers + 1); + if (otherPlayer != null) { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } else if (tem == 3 || tem == 6 || tem == 9) { + if (this.maxPlayers >= 3) { + EXPlayer otherPlayer = (EXPlayer) this.playerMapBySeat.get((this.lastBankerSeat + 1) % this.maxPlayers + 1); + if (otherPlayer != null) { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + } else { + if (card == Config.DONGFENG || card == Config.BEIFENG || card == Config.BAIBAN) { + if (bankerPlayer != null) { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } else if (card == Config.NANFENG || card == Config.HONGZHONG) { + if (this.maxPlayers >= 2) { + EXPlayer otherPlayer = (EXPlayer) this.playerMapBySeat.get((this.lastBankerSeat) % this.maxPlayers + 1); + if (otherPlayer != null) { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } else if (card == Config.XIFENG || card == Config.FACAI) { + if (this.maxPlayers >= 3) { + EXPlayer otherPlayer = (EXPlayer) this.playerMapBySeat.get((this.lastBankerSeat + 1) % this.maxPlayers + 1); + if (otherPlayer != null) { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + } + } + else + { + if (card < 400) + { + if (tem == 1 || tem == 5 || tem == 9) { + if (bankerPlayer != null) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } + else if (tem == 2 || tem == 6) { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + else if (tem == 3 || tem == 7) { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + else if (tem == 4 || tem == 8) { + if (this.maxPlayers >= 4) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+2)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + } + else + { + if (card == Config.DONGFENG || card == Config.HONGZHONG) + { + if (bankerPlayer != null) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + cn.score = owner.hu_score; + } + } + else if (card == Config.NANFENG || card == Config.FACAI) + { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + else if (card == Config.XIFENG || card == Config.BAIBAN) + { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + else if (card == Config.BEIFENG) + { + if (this.maxPlayers >= 4) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+2)%this.maxPlayers+1); + if (otherPlayer != null) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + cn.score = owner.hu_score; + } + } + } + } + } + } + else { + if (isYiPaoDuoXiang) + { + if (this.maxPlayers == 2) + { + EXPlayer bankerPlayer = (EXPlayer)this.playerMapBySeat.get(this.lastBankerSeat); + if (card < 400) + { + if (tem == 1 || tem == 3 || tem == 5 || tem == 7 || tem == 9) { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } + else if (tem == 2 || tem == 4 || tem == 6 || tem == 8) { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + else + { + if (card == Config.NANFENG || card == Config.BEIFENG || card == Config.FACAI) + { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } + else if (card == Config.DONGFENG || card == Config.XIFENG || card == Config.HONGZHONG || card == Config.BAIBAN) + { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + } + else if (this.maxPlayers == 3) + { + EXPlayer bankerPlayer = (EXPlayer)this.playerMapBySeat.get(this.lastBankerSeat); + if (card < 400) + { + if (tem == 1 || tem == 4 || tem == 7) { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } else if (tem == 2 || tem == 5 || tem == 8) { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } else if (tem == 3 || tem == 6 || tem == 9) { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + else + { + if (card == Config.DONGFENG || card == Config.BEIFENG || card == Config.BAIBAN) + { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } else if (card == Config.NANFENG || card == Config.HONGZHONG) + { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + else if (card == Config.XIFENG || card == Config.FACAI) + { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + } + else + { + EXPlayer bankerPlayer = (EXPlayer)this.playerMapBySeat.get(this.lastBankerSeat); + if (card < 400) + { + if (tem == 1 || tem == 5 || tem == 9) { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } + else if (tem == 2 || tem == 6) { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + else if (tem == 3 || tem == 7) { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + else if (tem == 4 || tem == 8) { + if (this.maxPlayers >= 4) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+2)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + else + { + if (card == Config.DONGFENG || card == Config.HONGZHONG) + { + if (bankerPlayer != null && bankerPlayer.winer == 1) + { + cn.playerId = bankerPlayer.playerid; + cn.seat = bankerPlayer.seat; + if (magengdi) + { + cn.score = bankerPlayer.hu_score; + } + else { + cn.score = bankerPlayer.niao_score; + } + } + } + else if (card == Config.NANFENG || card == Config.FACAI) + { + if (this.maxPlayers >= 2) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + else if (card == Config.XIFENG || card == Config.BAIBAN) + { + if (this.maxPlayers >= 3) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+1)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + else if (card == Config.BEIFENG) + { + if (this.maxPlayers >= 4) + { + EXPlayer otherPlayer = (EXPlayer)this.playerMapBySeat.get((this.lastBankerSeat+2)%this.maxPlayers+1); + if (otherPlayer != null && otherPlayer.winer == 1) + { + cn.playerId = otherPlayer.playerid; + cn.seat = otherPlayer.seat; + if (magengdi) + { + cn.score = otherPlayer.hu_score; + } + else { + cn.score = otherPlayer.niao_score; + } + } + } + } + } + } + } + else + { + if (this.maxPlayers == 2) + { + if (this.lastBankerSeat == owner.seat) + { + if (card < 400) + { + if (tem == 1 || tem == 3 || tem == 5 || tem == 7 || tem == 9) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.NANFENG || card == Config.BEIFENG|| card == Config.FACAI) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 2) + { + if (card < 400) + { + if (tem == 2 || tem == 4|| tem == 6|| tem == 8) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.DONGFENG || card == Config.XIFENG || card == Config.HONGZHONG || card == Config.BAIBAN) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + } + else if (this.maxPlayers == 3) + { + if (this.lastBankerSeat == owner.seat) + { + if (card < 400) + { + if (tem == 1 || tem == 4 || tem == 7) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.DONGFENG || card == Config.BEIFENG || card == Config.BAIBAN) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 2) + { + if (card < 400) + { + if (tem == 2 || tem == 5 || tem == 8) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.NANFENG || card == Config.HONGZHONG) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat+1)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 3) + { + if (card < 400) + { + if (tem == 3 || tem == 6 || tem == 9) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.XIFENG || card == Config.FACAI) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + } + else + { + if (this.lastBankerSeat == owner.seat) + { + if (card < 400) + { + if (tem == 1 || tem == 5 || tem == 9) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.DONGFENG || card == Config.HONGZHONG) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 2) + { + if (card < 400) + { + if (tem == 2 || tem == 6) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.NANFENG || card == Config.FACAI) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat+1)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 3) + { + if (card < 400) + { + if (tem == 3 || tem == 7) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.XIFENG || card == Config.BAIBAN) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + else if ((this.lastBankerSeat+2)%this.maxPlayers+1 == owner.seat && this.maxPlayers >= 4) + { + if (card < 400) + { + if (tem == 4 || tem == 8) { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + else + { + if (card == Config.BEIFENG) + { + cn.playerId = owner.playerid; + cn.seat = owner.seat; + cn.score = cur_niao_score; + } + } + } + } + } + } + } + } + + public void winCallback(EXPlayer owner, int card) { + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + niao_tongPao(card); + } else { + niao_dianPao(owner, card); + } + + this.endGame(); + } + } + + public void winCallback_qiangkong(EXPlayer owner, int card) { + boolean qiangkong_niao = config.getBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO); + boolean qg_type = this.config.getBoolean(Config.ROOM_CONFIG_QG_TYPE); + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + if (qiangkong_niao) + niao_tongPao_quanbao(card, qg_type, false); + } else { + if (qiangkong_niao) { + niao_dianPao_quanbao(owner, card, qg_type, false); + } + } + + this.endGame(); + } + } + +// public void settleRound() { +// saveMilitaryRound(playBackData.getData()); +// boolean total = this.round >= this.maxRound; +// if(this.entrusResultType ==EXRoom.ENTRUST_CURREN_RESULT) { +// for (Entry entry : this.playerMapById.entrySet()) { +// if(entry.getValue().isEntrust()) { +// total = true; +// break; +// } +// } +// } +// if (!total) +// EXMainServer.gameCtr.roomResult(this); +// else { +// this.saveMilitaryTotal(false); +// } +// this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); +// this.winCount = 0; +// +// +// if (total) { +// this.stateMachine.changeState(Global.getState(RoomDestoryGameState.class)); +// return; +// } +// } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void clear() { + super.clear(); + + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.winCount = this.piaoNiaoCount = 0; + this.niao.clear(); + + this.isGengZhuang = false; + this.first_zhuang_card = 0; + this.geng_zhuan_num = 0; + this.gent_zhuan_nextSeat = 0; + if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN)) + { + this.isGengZhuang = true; + } + this.lastBankerSeat = 0; + } + + public void handle10BeiBuJiFen(EXPlayer winner) + { + if (!this.config.getBoolean(Config.ROOM_CONFIG_10_BEI_BUJIFEN)) + { + return; + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (winner.playerid != player.playerid) + { + if (IsTingHu10Bei(player)) + { + player.tinghu10bei = true; + } + } + } + } + + public boolean IsTingHu10Bei(EXPlayer player) + { + List tempList = new ArrayList(); + boolean nowan = this.config.getBoolean(Config.ROOM_CONFIG_NO_WAN); + if (nowan) + { + for (int index = 1; index <= 9; index++) { + tempList.add(200 + index); + tempList.add(300 + index); + } + } + else { + for (int index = 1; index <= 9; index++) { + tempList.add(100 + index); + tempList.add(200 + index); + tempList.add(300 + index); + } + } + + //400 东风 403南风 406西风 409北风 412红中 415发财 418白板 + boolean wufeng = this.config.getBoolean(Config.ROOM_CONFIG_WU_FENG); + if (!wufeng) + { + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + } + + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + int laizi = config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, card, this.card.laiziCard, this.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, this, true)) { + int dahu_score = 0; + int cheng_score = 1; + for (Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + if (this.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + cheng_score *= cardType.score; + } + else + { + if (cardType.IsDaHu()) + { + dahu_score += cardType.score*WinCardType.DA_HU_BEI_SCORE; + } + else + { + cheng_score *= cardType.score; + } + } + } + + if (dahu_score * cheng_score >= 10) + { + return true; + } + } + } + + return false; + } + + public EXPlayer get12ZhangLuoDi(EXPlayer owner) + { + if (owner.opCardList.size() >= 4) + { + OpCard opCard = owner.opCardList.get(owner.opCardList.size() - 1); + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.KONG) + { + if (opCard.card_seat > 0) + { + EXPlayer badPlayer = (EXPlayer)this.playerMapBySeat.get(opCard.card_seat); + if (badPlayer != null) + { + return badPlayer; + } + } + } + } + return null; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXScore.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..b33f5bb --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,32 @@ +package extend.mj; + +import com.game.data.Score; + + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int KONG = 2; + public static final int AN_KONG = 4; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + public static final int GENG_ZHUAN = 5; + public static final int MA_GENG_GONG = 6; + public static final int MAI_NIAO = 7; + public static final int ZHONG_JIANG = 8; + + public EXScore(EXPlayer owner){ + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(KONG, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + this.round_log.put(GENG_ZHUAN, 0); + this.round_log.put(MA_GENG_GONG, 0); + this.round_log.put(MAI_NIAO, 0); + this.round_log.put(ZHONG_JIANG, 0); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/OpCard.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..f8d5712 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,45 @@ +package extend.mj; + +public class OpCard { + public int type; + public int card; + public int card_seat; + public int card2; + public int card3; + public int card4; + public int[] opcard; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card4 = 0; + this.card_seat = 0; + } + + public OpCard(int type, int card, int card_seat, int[] card_list) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card_seat = card_seat; + this.opcard = card_list; + } + + public OpCard(int type, int card, int card2, int card3) { + this.type = type; + this.card = card; + this.card2 = card2; + this.card3 = card3; + this.card_seat = 0; + } + + public OpCard(int type, int card, int card_seat) { + this.type = type; + this.card = card; + this.card2 = 0; + this.card3 = 0; + this.card_seat = card_seat; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..2898a18 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,117 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.*; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.tip.IRuleBase; + +/** + * ����������� + * + * + * + * 2017��9��19�� PlayerRuleManager.java + */ +public class PlayerRuleManager { + + /** + * ����ץ�� + */ + public static final int DRAW_RULE = 1; + + /** + * ���˳��� + */ + public static final int OTHER_DISCARD_RULE = 2; + /** + * ���ܺ����� + */ + public static final int KONG_HU_RULE = 3; + /** + * �������Ժ���ƹ��� + */ + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public static final int KONG_DRAW_RULE = 8; + public static final int CHENG_DRAW_RULE = 9; + public static final int CHENG_RULE = 10; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.KONG_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.CHENG_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerKongWinState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerDrawTipState) Global.getState(EXPlayerDrawTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List kongDrawRuleList = new ArrayList(); + kongDrawRuleList.add(new RuleSelfKong()); + kongDrawRuleList.add(new RulePongKong()); + kongDrawRuleList.add(new RuleOtherKongSelfWin()); + ruleMap.put(PlayerRuleManager.KONG_DRAW_RULE, kongDrawRuleList); + + List chengDrawRuleList = new ArrayList(); + chengDrawRuleList.add(new RuleSelfKong()); + chengDrawRuleList.add(new RulePongKong()); + chengDrawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.CHENG_DRAW_RULE, chengDrawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RulePongKongWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + //cpDiscardRuleList.add(new RulePongKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/RoomCard.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..daf769d --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,1601 @@ +package extend.mj; + +import com.game.Global; +import com.game.Util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + public Integer laiziCard; + public Integer laiziCard2; + public Integer laiziCardBefore; + public Integer laiziCard2Before; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + subCardList = new ArrayList<>(); + this.room = table; + laiziCard = 0; + laiziCard2 = 0; + laiziCardBefore = 0; + laiziCard2Before = 0; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + boolean liangmenPai = room.config.getBoolean(Config.LIANG_MEN_PAI); + boolean nowan = room.config.getBoolean(Config.ROOM_CONFIG_NO_WAN); + boolean notiao = false; + boolean notuo = false; + if (nowan == false && liangmenPai) + { + ArrayList rand = new ArrayList(); + rand.add(1); + rand.add(2); + rand.add(3); + Math.random(); + Collections.shuffle(rand); + int num = rand.get(0); + if (num == 1) + { + nowan = true; + } + else if (num == 2) + { + notiao = true; + } + else if (num == 3) + { + notuo = true; + } + } + + if (nowan) + { + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(200 + index); + this.cardList.add(300 + index); + } + } + } + else if (notiao) + { + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(300 + index); + } + } + } + else if (notuo) + { + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + else { + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + this.cardList.add(300 + index); + } + } + } + + //400 东风 403南风 406西风 409北风 412红中 415发财 418白板 + boolean wufeng = room.config.getBoolean(Config.ROOM_CONFIG_WU_FENG); + if (!wufeng) + { + for(int i =0;i<4;++i) { + this.cardList.add(Config.DONGFENG); + this.cardList.add(Config.NANFENG); + this.cardList.add(Config.XIFENG); + this.cardList.add(Config.BEIFENG); + this.cardList.add(Config.HONGZHONG); + this.cardList.add(Config.FACAI); + this.cardList.add(Config.BAIBAN); + } + } + + //0 无鬼 1白板做鬼 2翻鬼(随机一个牌做鬼) 3翻双鬼 + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + + if (laizi > 0) + { + ArrayList tempCard = new ArrayList(); + + for (int index = 1; index <= 9; index++) { + if (!nowan) + { + tempCard.add(100 + index); + } + + if (!notiao) + { + tempCard.add(200 + index); + } + + if (!notuo) + { + tempCard.add(300 + index); + } + } + + if (!wufeng) + { + tempCard.add(Config.DONGFENG); + tempCard.add(Config.NANFENG); + tempCard.add(Config.XIFENG); + tempCard.add(Config.BEIFENG); + tempCard.add(Config.HONGZHONG); + tempCard.add(Config.FACAI); + tempCard.add(Config.BAIBAN); + } + + Collections.shuffle(tempCard); + + if (laizi == 3) + { + this.laiziCard = tempCard.get(0); + this.laiziCardBefore = GetBeforeCard(this.laiziCard); + //朝天牌只有3个 + Util.removeCard(this.cardList, this.laiziCardBefore, 1); + if (this.laiziCard < 400) + { + if (this.laiziCard % 100 >= 1 && this.laiziCard % 100 <= 8) + { + this.laiziCard2 = this.laiziCard + 1; + } + else if (this.laiziCard % 100 == 9) + { + this.laiziCard2 = ((this.laiziCard / 100) * 100) + 1; + } + else + { + this.laiziCard2 = ((this.laiziCard / 100) * 100) + 1; + } + } + else + { + if (this.laiziCard == Config.DONGFENG) + { + this.laiziCard2 = Config.NANFENG; + } + else if (this.laiziCard == Config.NANFENG) + { + this.laiziCard2 = Config.XIFENG; + } + else if (this.laiziCard ==Config.XIFENG) + { + this.laiziCard2 = Config.BEIFENG; + } + else if (this.laiziCard ==Config.BEIFENG) + { + this.laiziCard2 = Config.HONGZHONG; + } + else if (this.laiziCard ==Config.HONGZHONG) + { + this.laiziCard2 = Config.FACAI; + } + else if (this.laiziCard ==Config.FACAI) + { + this.laiziCard2 = Config.BAIBAN; + } + else if (this.laiziCard ==Config.BAIBAN) + { + this.laiziCard2 = Config.DONGFENG; + } + else + { + this.laiziCard2 = Config.DONGFENG; + } + } + } + else + { + if (laizi == 1) + { + if (!wufeng) + { + this.laiziCard = Config.BAIBAN; + this.laiziCardBefore = GetBeforeCard(this.laiziCard); + this.laiziCard2 = 0; + //朝天牌只有3个 + Util.removeCard(this.cardList, this.laiziCardBefore, 1); + } + } + else if (laizi == 4) + { + if (!wufeng) + { + this.laiziCard = Config.HONGZHONG; + this.laiziCardBefore = GetBeforeCard(this.laiziCard); + this.laiziCard2 = 0; + //朝天牌只有3个 + Util.removeCard(this.cardList, this.laiziCardBefore, 1); + } + } + else + { + this.laiziCard = tempCard.get(0); + this.laiziCardBefore = GetBeforeCard(this.laiziCard); + this.laiziCard2 = 0; + this.laiziCard2Before = 0; + //朝天牌只有3个 + Util.removeCard(this.cardList, this.laiziCardBefore, 1); + } + } + } + + deal_select++; + deal_index = 1; + deal_tempCards_1 = 0; + deal_tempCards_2 = 0; + deal_tempCards_3 = 0; + deal_tempCards_4 = 0; + } + + private int GetBeforeCard(int card) + { + if (card < 400) + { + if (card % 100 >= 2 && card % 100 <= 9) + { + return card - 1; + } + else if (card % 100 == 1) + { + return card / 100 + 9; + } + else + { + return card; + } + } + else + { + if (card == Config.DONGFENG) + { + return Config.BAIBAN; + } + else if (card ==Config.NANFENG) + { + return Config.DONGFENG; + } + else if (card ==Config.XIFENG) + { + return Config.NANFENG; + } + else if (card ==Config.BEIFENG) + { + return Config.XIFENG; + } + else if (card ==Config.HONGZHONG) + { + return Config.BEIFENG; + } + else if (card ==Config.FACAI) + { + return Config.HONGZHONG; + } + else if (card ==Config.BAIBAN) + { + return Config.FACAI; + } + else + { + return Config.BAIBAN; + } + } + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public boolean isLaizi(int card) + { + if (laiziCard != 0 && card == laiziCard) + { + return true; + } + else if (laiziCard2 != 0 && card == laiziCard2) + { + return true; + } + + return false; + } + + public boolean isFanPai(int card) + { + if (laiziCardBefore != 0 && card == laiziCardBefore) + { + return true; + } + else if (laiziCard2Before != 0 && card == laiziCard2Before) + { + return true; + } + + return false; + } + + public void reInitCards(List cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } + +// public int pop() { +// +// if (this.cardList.size() == 0) { +// this.room.bankerSeat = this.room.activeSeat; +//// this.room.roundSettle(); +// } +// +// int card = this.cardList.remove(0); +// +// return card; +// +// } + + public int pop() { + Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public int deal_select = 0; + public List deal() { + if (deal_select >= 0) + { + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + boolean wufeng = room.config.getBoolean(Config.ROOM_CONFIG_WU_FENG); + boolean nowan = room.config.getBoolean(Config.ROOM_CONFIG_NO_WAN); + if (nowan || wufeng) + { + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + if (deal_select == 1) + { + return deal_shishanyao(); + } + else if (deal_select == 2) + { + return deal_qixiaodui(); + } + else if (deal_select == 3) + { + return deal_shibaluohan(); + } + else if (deal_select == 4) + { + return deal_hunyise(); + } + else if (deal_select == 5) + { + return deal_xiaoshanyuan(); + } + else if (deal_select == 6) + { + return deal_dashanyuan(); + } + else if (deal_select == 7) + { + return deal_xiaosixi(); + } + else if (deal_select == 8) + { + return deal_dasixi(); + } + else if (deal_select == 9) + { + return deal_qiangganghu(); + } + else if (deal_select == 10) + { + return deal_gangshangkaihua(); + } + else + { + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + } + + public int deal_index = 1; + public int deal_tempCards_1 = 0; + public int deal_tempCards_2 = 0; + public int deal_tempCards_3 = 0; + public int deal_tempCards_4 = 0; + public List deal_shishanyao() { + List dealCards = new ArrayList(); + + dealCards.add(101); + dealCards.add(109); + dealCards.add(201); + dealCards.add(209); + dealCards.add(301); + dealCards.add(309); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.FACAI); + dealCards.add(Config.BAIBAN); + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + + deal_index++; + + return dealCards; + } + + public List deal_qixiaodui() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + dealCards.add(105); + dealCards.add(106); + dealCards.add(106); + dealCards.add(107); + deal_tempCards_1 = 107; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + dealCards.add(205); + dealCards.add(206); + deal_tempCards_2 = 206; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(305); + deal_tempCards_4 = 305; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_pengpenghu() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_1 = 105; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_4 = Config.HONGZHONG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index >= 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_shibaluohan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_1 = 105; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = Config.BEIFENG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_hunyise() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_3 = Config.HONGZHONG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.HONGZHONG); + deal_tempCards_4 = Config.HONGZHONG; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index >= 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_xiaoshanyuan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.NANFENG); + deal_tempCards_3 = Config.NANFENG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(301); + dealCards.add(301); + dealCards.add(303); + dealCards.add(304); + deal_tempCards_4 = 304; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_dashanyuan() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.HONGZHONG); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.BAIBAN); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(Config.FACAI); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(Config.DONGFENG); + deal_tempCards_1 = Config.DONGFENG; + } + else if (deal_index == 2) + { + dealCards.add(201); + dealCards.add(201); + dealCards.add(201); + dealCards.add(202); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.NANFENG); + deal_tempCards_3 = Config.NANFENG; + } + else if (deal_index == 4) + { + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(304); + dealCards.add(305); + dealCards.add(306); + dealCards.add(307); + dealCards.add(308); + dealCards.add(309); + dealCards.add(301); + dealCards.add(302); + dealCards.add(303); + dealCards.add(305); + deal_tempCards_4 = 305; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_xiaosixi() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(109); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(109); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(109); + dealCards.add(Config.BEIFENG); + deal_tempCards_1 = Config.BEIFENG; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_4 = 105; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_dasixi() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(109); + deal_tempCards_1 = 109; + } + else if (deal_index == 2) + { + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(301); + dealCards.add(301); + dealCards.add(301); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + deal_tempCards_3 = 305; + } + else if (deal_index == 4) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(102); + dealCards.add(102); + dealCards.add(102); + dealCards.add(103); + dealCards.add(103); + dealCards.add(103); + dealCards.add(104); + dealCards.add(104); + dealCards.add(104); + dealCards.add(105); + deal_tempCards_4 = 105; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_qiangganghu() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(106); + dealCards.add(106); + dealCards.add(106); + dealCards.add(107); + dealCards.add(107); + dealCards.add(107); + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + dealCards.add(109); + deal_tempCards_1 = 109; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 205; + } + else if (deal_index == 3) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + dealCards.add(305); + deal_tempCards_3 = 301; + } + else if (deal_index == 4) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = 303; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } + + public List deal_gangshangkaihua() { + List dealCards = new ArrayList(); + List tempCards = new ArrayList(); + + if (deal_index == 1) + { + dealCards.add(101); + dealCards.add(101); + dealCards.add(101); + dealCards.add(106); + dealCards.add(106); + dealCards.add(106); + dealCards.add(107); + dealCards.add(107); + dealCards.add(107); + dealCards.add(108); + dealCards.add(108); + dealCards.add(108); + dealCards.add(109); + deal_tempCards_1 = 102; + } + else if (deal_index == 2) + { + dealCards.add(101); + dealCards.add(102); + dealCards.add(103); + dealCards.add(104); + dealCards.add(202); + dealCards.add(202); + dealCards.add(203); + dealCards.add(203); + dealCards.add(203); + dealCards.add(204); + dealCards.add(204); + dealCards.add(204); + dealCards.add(205); + deal_tempCards_2 = 109; + } + else if (deal_index == 3) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(302); + dealCards.add(302); + dealCards.add(302); + dealCards.add(303); + dealCards.add(303); + dealCards.add(303); + dealCards.add(304); + dealCards.add(304); + dealCards.add(304); + dealCards.add(305); + dealCards.add(305); + deal_tempCards_3 = 109; + } + else if (deal_index == 4) + { + dealCards.add(102); + dealCards.add(103); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.DONGFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.NANFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.XIFENG); + dealCards.add(Config.BEIFENG); + dealCards.add(Config.BEIFENG); + deal_tempCards_4 = 109; + } + + for(int i = 0; i< dealCards.size(); i++) { + Util.removeCard(this.cardList, dealCards.get(i), 1); + } + if (deal_tempCards_1 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_1, 1); + tempCards.add(deal_tempCards_1); + } + if (deal_tempCards_2 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_2, 1); + tempCards.add(deal_tempCards_2); + } + if (deal_tempCards_3 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_3, 1); + tempCards.add(deal_tempCards_3); + } + if (deal_tempCards_4 > 0) + { + Util.removeCard(this.cardList, deal_tempCards_4, 1); + tempCards.add(deal_tempCards_4); + } + tempCards.addAll(this.cardList); + this.cardList.clear(); + this.cardList.addAll(tempCards); + + deal_index++; + if (deal_index > 4) + { + deal_index = 1; + } + + return dealCards; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/RuleWeight.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..3cce43f --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,19 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 0b00001; + public final static int PONG = 0b00010; + public final static int KONG = 0b00100; + public final static int SELFKONG = 0b00100; + public final static int WIN = 0b01000; + public final static int SELF_WIN = 0b10000; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_PONG_KONG = 5; + public final static int TYPE_WIN = 6; + public final static int TYPE_ZHONG_JIANG = 100; +} + diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/SettleLog.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagAnalyseItem.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagAnalyseItem.java new file mode 100644 index 0000000..dc9f797 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagAnalyseItem.java @@ -0,0 +1,20 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagAnalyseItem { + //分析子项 + public int cbCardEye; //牌眼麻将 + public int cbCardEye2; //牌眼麻将 + public List cbOpCard; //组合类型 + public boolean isPengPengHu; + + public TagAnalyseItem() + { + this.cbCardEye = 0; + this.cbCardEye2 = 0; + this.cbOpCard = new ArrayList(); + this.isPengPengHu = false; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagKindItem.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagKindItem.java new file mode 100644 index 0000000..fe18c06 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/TagKindItem.java @@ -0,0 +1,17 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagKindItem { + public int type; //组合类型 + public int card; //中心麻将 + public Integer[] cbCardList; //麻将索引 + + public TagKindItem() + { + type = 0; + card = 0; + cbCardList = new Integer[3]; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/WinCardType.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/WinCardType.java new file mode 100644 index 0000000..ad8302d --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/WinCardType.java @@ -0,0 +1,205 @@ +package extend.mj; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class WinCardType { + public static final int JIHU = 1; //鸡胡类型 + + public static final int PINGHU = 2; //平胡类型 + + public static final int QIXIAODUI = 3; //七小对 + + public static final int HAOHUA_QIXIAODUI = 4; //豪华七小对 + + public static final int HAOHUA2_QIXIAODUI = 5; //双豪华七小对 + + public static final int HAOHUA3_QIXIAODUI = 6; //三豪华七小对 + + public static final int QINGYISE = 7; //清一色 + + public static final int PENGPENGHU = 8; //碰碰胡 + + public static final int GANGSHANGHUA = 9; //杠上开花 + + public static final int GANGSHANGPAO = 10; //杠上炮 + + public static final int QIANG_GANG_HU = 11; //抢杠胡 + + public static final int HUN_YI_SE = 12; //混一色 + + public static final int SHI_SHAN_YAO = 13; //十三幺 + + public static final int TIAN_HU = 14; //天胡 十倍 + + public static final int DI_HU = 15; //地胡 十倍 + + public static final int REN_HU = 16; //人胡 十倍 + + public static final int SHI_BA_LUO_HAN = 17; //十八罗汉 + + public static final int XIAO_SHAN_YUAN = 18; //小三元 + + public static final int DA_SHAN_YUAN = 19; //大三元 + + public static final int XIAO_SI_XI = 20; //小四喜 + + public static final int DA_SI_XI = 21; //大四喜 + + public static final int YAO_JIU = 22; //幺九 + + public static final int LAIZI4_HU = 23; //四鬼胡牌 + + public static final int QUAN_FENG = 24;//全风 + + public static final int QUAN_QIU_REN = 25;//全求人 + + public static final int QING_YAO_JIU = 26; //清幺九 + + public static final int ZI_YI_SE = 27; //字一色 + + public static final int WU_GUI_JIABEI = 28; //无鬼两倍 + public static final int LIU_JU_2BEI = 29; //流局两倍 + public static final int HAI_DI_NAO_YUE = 30; //海底捞月 + public static final int MEN_QING = 31; //门清 + public static final int XIAO_HU_ZHONG_DA_HU = 32; //选小胡有大胡的情况下,不显示具体的胡牌类型,只显示大胡几分 + + public static final int ONE_CHENG_QING_LAI_YOU = 33; //一撑清癞油 撑完一个癞子后补张胡牌,每个玩家出8分 + public static final int ONE_CHENG_YING_MO = 34; //一撑硬摸 撑完一个癞子后没有胡牌, 后面自摸胡牌,每个玩家出4分 + public static final int ONE_CHENG_LAI_YOU = 35; //一撑癞油 撑完一个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出4分 + public static final int ONE_CHENG_LAI_MO = 36; //一撑癞摸 撑完一个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出2分 + + public static final int TWO_CHENG_QING_LAI_YOU = 37; //二撑清癞油 撑完二个癞子后补张胡牌,每个玩家出16分 + public static final int TWO_CHENG_YING_MO = 38; //二撑硬摸 撑完二个癞子后没有胡牌, 后面自摸胡牌,每个玩家出8分 + public static final int TWO_CHENG_LAI_YOU = 39; //二撑癞油 撑完二个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出8分 + public static final int TWO_CHENG_LAI_MO = 40; //二撑癞摸 撑完二个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出4分 + + public static final int THREE_CHENG_QING_LAI_YOU = 41; //三撑清癞油 撑完三个癞子后补张胡牌,每个玩家出32分 + public static final int THREE_CHENG_YING_MO = 42; //三撑硬摸 撑完三个癞子后没有胡牌, 后面自摸胡牌,每个玩家出16分 + public static final int THREE_CHENG_LAI_YOU = 43; //三撑癞油 撑完三个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出16分 + public static final int THREE_CHENG_LAI_MO = 44; //三撑癞摸 撑完三个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出8分 + + public static final int FOUR_CHENG_QING_LAI_YOU = 45; //四撑清癞油 撑完四个癞子后补张胡牌,每个玩家出64分 + public static final int FOUR_CHENG_YING_MO = 46; //四撑硬摸 撑完四个癞子后没有胡牌, 后面自摸胡牌,每个玩家出32分 + public static final int FOUR_CHENG_LAI_YOU = 47; //四撑癞油 撑完四个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出32分 + public static final int FOUR_CHENG_LAI_MO = 48; //四撑癞摸 撑完四个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出16分 + + public static final int LIAN_GUN_DAI_PA = 49; //连滚带爬 胡的牌为翻牌, 并且手中还有一对翻牌 + + public static final int YING_MO = 50; //硬摸 自摸胡牌 + //public static final int LIAN_GUN_DAI_PA_SCORE = ; //连滚带爬 胡的牌为翻牌, 并且手中还有一对翻牌 + public static final int YING_MO_SCORE = 2; //硬摸 自摸胡牌,每个玩家出4分 + + public static final int ONE_CHENG_QING_LAI_YOU_SOCRE = 8; //一撑清癞油 撑完一个癞子后补张胡牌,每个玩家出8分 + public static final int ONE_CHENG_YING_MO_SCORE = 4; //一撑硬摸 撑完一个癞子后没有胡牌, 后面自摸胡牌,每个玩家出4分 + public static final int ONE_CHENG_LAI_YOU_SOCRE = 4; //一撑癞油 撑完一个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出4分 + public static final int ONE_CHENG_LAI_MO_SCORE = 2; //一撑癞摸 撑完一个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出2分 + + public static final int TWO_CHENG_QING_LAI_YOU_SOCRE = 16; //二撑清癞油 撑完二个癞子后补张胡牌,每个玩家出16分 + public static final int TWO_CHENG_YING_MO_SOCRE = 8; //二撑硬摸 撑完二个癞子后没有胡牌, 后面自摸胡牌,每个玩家出8分 + public static final int TWO_CHENG_LAI_YOU_SOCRE = 8; //二撑癞油 撑完二个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出8分 + public static final int TWO_CHENG_LAI_MO_SOCRE = 4; //二撑癞摸 撑完二个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出4分 + + public static final int THREE_CHENG_QING_LAI_YOU_SOCRE = 32; //三撑清癞油 撑完三个癞子后补张胡牌,每个玩家出32分 + public static final int THREE_CHENG_YING_MO_SOCRE = 16; //三撑硬摸 撑完三个癞子后没有胡牌, 后面自摸胡牌,每个玩家出16分 + public static final int THREE_CHENG_LAI_YOU_SOCRE = 16; //三撑癞油 撑完三个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出16分 + public static final int THREE_CHENG_LAI_MO_SOCRE = 8; //三撑癞摸 撑完三个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出8分 + + public static final int FOUR_CHENG_QING_LAI_YOU_SOCRE = 64; //四撑清癞油 撑完四个癞子后补张胡牌,每个玩家出64分 + public static final int FOUR_CHENG_YING_MO_SOCRE = 32; //四撑硬摸 撑完四个癞子后没有胡牌, 后面自摸胡牌,每个玩家出32分 + public static final int FOUR_CHENG_LAI_YOU_SOCRE = 32; //四撑癞油 撑完四个癞子后补张胡牌, 牌面还有一个癞子,每个玩家出32分 + public static final int FOUR_CHENG_LAI_MO_SOCRE = 16; //四撑癞摸 撑完四个癞子后没有胡牌, 后面自摸胡牌,, 牌面还有一个癞子, 每个玩家出16分 +//////////////////////////////////////////////////////////// + public static int BASE_HU_SCORE = 2; //基础分数 + public static int DA_HU_BEI_SCORE = 1; //大胡倍数 + public static int JIHU_SCORE = 1; //鸡胡类型 + public static int PINGHU_SCORE = 1; //平胡类型 + public static int MENGQING_SCORE = 1; //门清类型 + public static int QIXIAODUI_SOCRE = 2; //七小对 倍数 + public static int HAOHUA_QIXIAODUI_SCORE = 4; //豪华七小对 + public static int HAOHUA2_QIXIAODUI_SCORE = 6; //双豪华七小对 + public static int HAOHUA3_QIXIAODUI_SCORE = 8; //三豪华七小对 + public static int QINGYISE_SCORE = 2; //清一色 + public static int GANGSHANGHUA_SCORE = 2; //杠上开花 + public static int PENGPENGHU_SCORE = 2; //碰碰胡 + public static int GANGSHANGPAO_SOCRE = 1; //杠上炮 + public static int QIANG_GANG_HU_SOCRE = 1; //抢杠胡 + public static int HUN_YI_SE_SCORE = 2; //混一色 + public static int SHI_SHAN_YAO_SCORE = 10; //十三幺 + public static int TIAN_DI_HU_SCORE = 10; //天地胡 十倍 + public static int TIAN_HU_SCORE = 10; //天胡 20倍 + public static int DI_HU_SCORE = 10; //地胡 10倍 + public static int SHI_BA_LUO_HAN_SCORE = 10; //十八罗汉 + public static int DA_SHAN_YUAN_SCORE = 6; //大三元 + public static int XIAO_SHAN_YUAN_SCORE = 4; //小三元 + public static int XIAO_SI_XI_SCORE = 4; //小四喜 + public static int DA_SI_XI_SCORE = 6; //大四喜 + public static int YAO_JIU_SCORE = 1; //幺九 + public static int LAIZI4_HU_SCORE = 1; //四鬼胡牌 + public static int QUAN_FENG_SCORE = 1;//全风 + public static int QUAN_QIU_REN_SCORE = 1;//全求人 + public static int QING_YAO_JIU_SCORE = 1; //清幺九 + public static int ZI_YI_SE_SCORE = 1; //字一色 + public static int WU_GUI_JIABEI_SCORE = 2; //无鬼两倍 + public static int LIU_JU_2BEI_SCORE = 2; //流局两倍 + public static int HAI_DI_NAO_YUE_SCORE = 2; //海底捞月 + + public int type; + + public int value; + + public int score; + + public boolean is_dahu; + + public String desc; + + public ITArray opcard; + + //初始化房间的特殊参数 + static public void InitRoomSpecialConfig(EXRoom room) + { + //一脚癞油 + room.config.putBoolean(Config.ROOM_CONFIG_QG_TYPE, true); + room.config.putBoolean(Config.ROOM_CONFIG_GANGBAO_TYPE, true); + room.config.putBoolean(Config.ROOM_CONFIG_WU_FENG, true); + room.config.putBoolean(Config.ROOM_CONFIG_DAHU_CHENG, true); + + //fang gui + room.config.putInt(Config.ROOM_CONFIG_LAIZI, 2); + room.config.putBoolean(Config.ROOM_CONFIG_GUO_GONG, true); + } + + public WinCardType(int type, int value, int score, boolean is_dahu, String desc) { + this.type = type; + this.value = value; + this.score = score; + this.is_dahu = is_dahu; + this.desc = desc; + } + + public boolean IsDaHu() + { + return is_dahu; + } + + public ITObject toTObject() { + return toTObject(false); + } + + public ITObject toTObject(boolean is_opcard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", type); + obj.putInt("value", value); + obj.putInt("score", score); + if(is_opcard&&opcard!=null) { + obj.putTArray("opcard", opcard); + } + return obj; + } + + public String toString() { + return "type:" + type + " value:" + value + " score:" + score + " desc:" + desc; + } +} \ No newline at end of file diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..3538f12 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,66 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + if (player.getRoom().isLaizi(eventCard)) + { + return false; + } + + if (player.getRoom().isFanPai(eventCard)) + { + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + else { + if (Util.checkCard(eventCard, player.cardInhand, 3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java new file mode 100644 index 0000000..0d47ee2 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherKongSelfWin.java @@ -0,0 +1,315 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherGongSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleOtherKongSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + int laizi = config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + if (room.config.getBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei)) + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.GANGSHANGHUA_SCORE*2, false, "杠上开花"); + } + else + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGHUA, 1,WinCardType.GANGSHANGHUA_SCORE, false, "杠上开花"); + } + + boolean flag = false; + if (!room.config.getBoolean(Config.DIAO_YU) && WinCard.IsDiaoYu(player, player.cardInhand, player.drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false)) + { + WinCard win = new WinCard(player.cardInhand, 0, 0, false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + } + else { + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + } + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + player.tipMgr.addTip(tip); + + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + int cheng_num = 0; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer)entry.getValue(); + cheng_num += tempPlayer.cheng_num; + } + if (player.is_cheng) + { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_YOU, 1,WinCardType.ONE_CHENG_LAI_YOU_SOCRE, true, "一撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_YOU, 1,WinCardType.TWO_CHENG_LAI_YOU_SOCRE, true, "二撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_YOU, 1,WinCardType.THREE_CHENG_LAI_YOU_SOCRE, true, "三撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_YOU, 1,WinCardType.FOUR_CHENG_LAI_YOU_SOCRE, true, "四撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + } + } + else { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_MO, 1,WinCardType.ONE_CHENG_LAI_MO_SCORE, true, "一撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_MO, 1,WinCardType.TWO_CHENG_LAI_MO_SOCRE, true, "二撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_MO, 1,WinCardType.THREE_CHENG_LAI_MO_SOCRE, true, "三撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_MO, 1,WinCardType.FOUR_CHENG_LAI_MO_SOCRE, true, "四撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + } + } + + if (room.config.getBoolean(Config.lian_gun_dai_pai)) + { + if (room.card.laiziCardBefore > 0) + { + if (player.drawCard == room.card.laiziCardBefore) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + + if (room.card.laiziCard2Before > 0) + { + if (player.drawCard == room.card.laiziCard2Before) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + } + + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.winType = 1; + player.winCard = tip.card; + player.drawCard = tip.card; + + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + player.hu_score = room.config.getInt(Config.LAIYOU_DIFEN); + player.di_score = room.config.getInt(Config.LAIYOU_DIFEN); + + player.niao_score = WinCardType.BASE_HU_SCORE; + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + if (cardType.type != WinCardType.JIHU && cardType.type != WinCardType.PINGHU) + { + jia_score += cardType.score; + } + } + + if (cardType.type == WinCardType.LIAN_GUN_DAI_PA) + { + room.addAllScore(player, Config.AN_GANG_SCORE, EXScore.KONG); + player.an_gang_num++; + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score; + + player.stateMachine.changeState(Global.getState(PROtherGongSelfWinState.class)); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..f64c54b --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,128 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.HashMap; +import java.util.Map; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + if (!config.getBoolean(Config.ROOM_CONFIG_DIANPAO)) { + if (!config.getBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + return false; + } + } + + if(room.activeSeat == player.seat)return false; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + + if (player.cardInhand.size() == 1 && room.isLaizi(player.cardInhand.get(0))) + { + return false; + } + + if (room.isLaizi(room.activeCard)) + { + return false; + } + + int activieCard = room.activeCard; + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + if (activePlayer.gangshangpao && room.config.getBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei)) + { + WinCard.putWinCardType(map, WinCardType.GANGSHANGPAO, 1,WinCardType.GANGSHANGPAO_SOCRE*2, false, "杠上炮"); + } + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, false)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + tip.winMap = map; + player.tipMgr.addTip(tip); + + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + player.getRoom().activeCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + player.niao_score = WinCardType.BASE_HU_SCORE; + + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.laizi_count > 0) + { + player.hu_score = 1; + player.di_score = 1; + } + else { + player.hu_score = 2; + player.di_score = 2; + } + + player.hu_score = room.config.getInt(Config.LAIYOU_DIFEN); + player.di_score = room.config.getInt(Config.LAIYOU_DIFEN); + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + jia_score += cardType.score; + } + + if (cardType.type == WinCardType.LIAN_GUN_DAI_PA) + { + room.addAllScore(player, Config.AN_GANG_SCORE, EXScore.KONG); + player.an_gang_num++; + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score; + + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..019436d --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,77 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (player.isEntrust()) { + return false; + } + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + if (player.notPongList.contains(eventCard)) + { + return false; + } + } + + if (player.getRoom().isFanPai(eventCard)) + { + return false; + } + + if (player.getRoom().isLaizi(eventCard)) + { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + player.notPongList.add(eventCard); + } + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG)) + { + Util.removeCard(player.notPongList, tip.card, 4); + } + + player.stateMachine.changeState(Global.getState(PRPongState.class)); + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..e44c7c5 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,81 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + boolean result = false; + if (player.isEntrust()) { + return false; + } + for (int card : player.cardInhand) { + result = conditionCard(player, card) || result; + } + return result; + + } + + public boolean conditionCard(EXPlayer player, int card) { + + for (int[] cardGroup : player.pongGroup) { + if (card == cardGroup[0]) { + if (player.getRoom().isLaizi(card)) + { + continue; + } + if (player.getRoom().isFanPai(card)) + { + continue; + } + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(card)) + { + continue; + } + } + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_PONG_KONG); + player.tipMgr.addTip(tip); + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(card); + } + return true; + } + } + return false; + + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + Util.removeCard(player.notPongKongList, tip.card, 4); + } + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKongWin.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKongWin.java new file mode 100644 index 0000000..9f97f60 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RulePongKongWin.java @@ -0,0 +1,318 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRPongKongWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RulePongKongWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + + if(room.activeSeat == player.seat)return false; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat); + + int activieCard = room.activeCard; + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + if (room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG_2BEI)) + { + WinCard.putWinCardType(map, WinCardType.QIANG_GANG_HU, 1,WinCardType.QIANG_GANG_HU_SOCRE*2, false, "抢杠胡"); + } + else + { + WinCard.putWinCardType(map, WinCardType.QIANG_GANG_HU, 1, WinCardType.QIANG_GANG_HU_SOCRE, false, "抢杠胡"); + } + + boolean flag = false; + if (!room.config.getBoolean(Config.DIAO_YU) && WinCard.IsDiaoYu(player, player.cardInhand, player.drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false)) + { + WinCard win = new WinCard(player.cardInhand, room.activeCard, 0, 0, false, false); + if (win.checkWin(map, player, room, false)) { + flag = true; + } + } + else { + WinCard win = new WinCard(player.cardInhand, room.activeCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, false); + if (win.checkWin(map, player, room, false)) { + flag = true; + } + } + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + tip.winMap = map; + player.tipMgr.addTip(tip); + + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + Util.removeCard(tempCardList, player.drawCard, 1); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + int cheng_num = 0; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer)entry.getValue(); + cheng_num += tempPlayer.cheng_num; + } + if (player.is_cheng) + { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_YOU, 1,WinCardType.ONE_CHENG_LAI_YOU_SOCRE, true, "一撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_YOU, 1,WinCardType.TWO_CHENG_LAI_YOU_SOCRE, true, "二撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_YOU, 1,WinCardType.THREE_CHENG_LAI_YOU_SOCRE, true, "三撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_YOU, 1,WinCardType.FOUR_CHENG_LAI_YOU_SOCRE, true, "四撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + } + } + else { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_MO, 1,WinCardType.ONE_CHENG_LAI_MO_SCORE, true, "一撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_MO, 1,WinCardType.TWO_CHENG_LAI_MO_SOCRE, true, "二撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_MO, 1,WinCardType.THREE_CHENG_LAI_MO_SOCRE, true, "三撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_MO, 1,WinCardType.FOUR_CHENG_LAI_MO_SOCRE, true, "四撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + } + } + + if (room.config.getBoolean(Config.lian_gun_dai_pai)) + { + if (room.card.laiziCardBefore > 0) + { + if (player.drawCard == room.card.laiziCardBefore) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + + if (room.card.laiziCard2Before > 0) + { + if (player.drawCard == room.card.laiziCard2Before) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + } + + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + EXRoom room = player.getRoom(); + room.activeCard = tip.card; + player.winMap = tip.winMap; + + player.hu_score = room.config.getInt(Config.LAIYOU_DIFEN); + player.di_score = room.config.getInt(Config.LAIYOU_DIFEN); + + + player.niao_score = WinCardType.BASE_HU_SCORE; + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + jia_score += cardType.score; + } + + if (cardType.type == WinCardType.LIAN_GUN_DAI_PA) + { + room.addAllScore(player, Config.AN_GANG_SCORE, EXScore.KONG); + player.an_gang_num++; + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score;; + + player.stateMachine.changeState(Global.getState(PRPongKongWinState.class)); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..cff6235 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,91 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +import java.util.Map; +import java.util.Map.Entry; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if (player.isEntrust()) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + + int num = entry.getValue(); + if (player.getRoom().isLaizi(card)) + { + continue; + } + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + if (player.notPongKongList.contains(card)) + { + continue; + } + } + if (player.getRoom().isFanPai(card)) + { + if (num >= 3) + { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(card); + } + } + } + else { + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + player.notPongKongList.add(card); + } + } + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_GONG)) + { + Util.removeCard(player.notPongKongList, tip.card, 4); + } + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..b96df5c --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,307 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + EXRoom room = player.getRoom(); + int laizi = config.getInt(Config.ROOM_CONFIG_LAIZI); + HashMap map = new HashMap(); + + boolean flag = false; + if (!room.config.getBoolean(Config.DIAO_YU) && WinCard.IsDiaoYu(player, player.cardInhand, player.drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false)) + { + WinCard win = new WinCard(player.cardInhand, 0, 0, false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + } + else { + WinCard win = new WinCard(player.cardInhand, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + if (win.checkWin(map, player, room, true)) { + flag = true; + } + } + if (flag) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + tip.winMap = map; + tip.self = true; + player.tipMgr.addTip(tip); + + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(player.cardInhand); + WinCard win2 = new WinCard(tempCardList, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false); + int cheng_num = 0; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer)entry.getValue(); + cheng_num += tempPlayer.cheng_num; + } + if (player.is_cheng) + { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_YOU, 1,WinCardType.ONE_CHENG_LAI_YOU_SOCRE, true, "一撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_QING_LAI_YOU, 1,WinCardType.ONE_CHENG_QING_LAI_YOU_SOCRE, true, "一撑清癞油"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_YOU, 1,WinCardType.TWO_CHENG_LAI_YOU_SOCRE, true, "二撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_QING_LAI_YOU, 1,WinCardType.TWO_CHENG_QING_LAI_YOU_SOCRE, true, "二撑清癞油"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_YOU, 1,WinCardType.THREE_CHENG_LAI_YOU_SOCRE, true, "三撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_QING_LAI_YOU, 1,WinCardType.THREE_CHENG_QING_LAI_YOU_SOCRE, true, "三撑清癞油"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_YOU, 1,WinCardType.FOUR_CHENG_LAI_YOU_SOCRE, true, "四撑癞油"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_QING_LAI_YOU, 1,WinCardType.FOUR_CHENG_QING_LAI_YOU_SOCRE, true, "四撑清癞油"); + } + } + } + else { + if (cheng_num == 0) + { + if (win2.laizi_count <= 0) + { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + else { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.YING_MO, 1,WinCardType.YING_MO_SCORE, true, "硬摸"); + } + } + } + else if (cheng_num == 1) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_LAI_MO, 1,WinCardType.ONE_CHENG_LAI_MO_SCORE, true, "一撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.ONE_CHENG_YING_MO, 1,WinCardType.ONE_CHENG_YING_MO_SCORE, true, "一撑硬摸"); + } + } + else if (cheng_num == 2) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_LAI_MO, 1,WinCardType.TWO_CHENG_LAI_MO_SOCRE, true, "二撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.TWO_CHENG_YING_MO, 1,WinCardType.TWO_CHENG_YING_MO_SOCRE, true, "二撑硬摸"); + } + } + else if (cheng_num == 3) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_LAI_MO, 1,WinCardType.THREE_CHENG_LAI_MO_SOCRE, true, "三撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.THREE_CHENG_YING_MO, 1,WinCardType.THREE_CHENG_YING_MO_SOCRE, true, "三撑硬摸"); + } + } + else if (cheng_num == 4) + { + if (win2.laizi_count > 0) + { + WinCard win3 = new WinCard(player.cardInhand, 0, 0, false); + if (win2.laizi_count == 1 && win3.checkWin(map, player, room, true)) { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_LAI_MO, 1,WinCardType.FOUR_CHENG_LAI_MO_SOCRE, true, "四撑癞摸"); + } + } + else { + WinCard.putWinCardType(map, WinCardType.FOUR_CHENG_YING_MO, 1,WinCardType.FOUR_CHENG_YING_MO_SOCRE, true, "四撑硬摸"); + } + } + } + + if (room.config.getBoolean(Config.lian_gun_dai_pai)) + { + if (room.card.laiziCardBefore > 0) + { + if (player.drawCard == room.card.laiziCardBefore) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + + if (room.card.laiziCard2Before > 0) + { + if (player.drawCard == room.card.laiziCard2Before) + { + if (Util.checkCard(player.drawCard, tempCardList, 2)) + { + WinCard.putWinCardType(map, WinCardType.LIAN_GUN_DAI_PA, 1, 0, true, "连滚带爬"); + } + } + } + } + + return true; + } + player.is_cheng = false; + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.winCard = tip.card; + player.drawCard = tip.card; + player.winMap = tip.winMap; + EXRoom room = player.getRoom(); + + player.hu_score = room.config.getInt(Config.LAIYOU_DIFEN); + player.di_score = room.config.getInt(Config.LAIYOU_DIFEN); + + + player.niao_score = WinCardType.BASE_HU_SCORE; + + Global.logger.info("player:" + player.playerid + " di fen:" + player.di_score + " hu fen:" + player.hu_score + " niao fen:" + player.niao_score); + + int dahu_score = 1; + int jia_score = 0; + for (Map.Entry entry : player.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("player:" + player.playerid + " hu:" + cardType.toString()); + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + if (cardType.type != WinCardType.JIHU && cardType.type != WinCardType.PINGHU) + { + jia_score += cardType.score; + } + } + + if (cardType.type == WinCardType.LIAN_GUN_DAI_PA) + { + room.addAllScore(player, Config.AN_GANG_SCORE, EXScore.KONG); + player.an_gang_num++; + } + } + + if (dahu_score > 0) + { + player.hu_score *= dahu_score; + } + + player.hu_score += jia_score; + + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java new file mode 100644 index 0000000..8ec0134 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherGongSelfWinState.java @@ -0,0 +1,139 @@ +package extend.mj.player.rulestate; + + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PROtherGongSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + Util.removeCard(owner.cardInhand, owner.winCard, 1); + if (owner.opCardList.size() > 0) + { + OpCard opCard = owner.opCardList.get(owner.opCardList.size()-1); + if (opCard.type == RuleWeight.TYPE_KONG && opCard.card_seat > 0) + { + int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO); + int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + + owner.room.activeSeat = opCard.card_seat; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + + boolean qg_type = room.config.getBoolean(Config.ROOM_CONFIG_GANGBAO_TYPE); + if(qg_type) { //抢杠全包 + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + room.addScore(owner,activePlayer, owner.hu_score * (room.maxPlayers - 1),EXScore.WIN); + } + } + else + { + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + room.addAllScore(owner, owner.hu_score, EXScore.WIN); + } + } + + room.addAllPiaoNiaoScore(owner); + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.niao_dianPao_quanbao(owner ,owner.winCard, qg_type, true); + + room.endGame(); + return; + } + else if (opCard.type == RuleWeight.TYPE_SELF_KONG || (opCard.type == RuleWeight.TYPE_KONG && opCard.card_seat == 0)) + { + int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO); + int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + if (room.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && room.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = room.get12ZhangLuoDi(owner); + room.addScore(owner,badPlayer, owner.hu_score * (room.maxPlayers - 1), EXScore.WIN); + } + else + { + room.addAllScore(owner, owner.hu_score,EXScore.WIN); + } + } + + room.addAllPiaoNiaoScore(owner); + for (Map.Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.niao_dianPao_quanbao(owner ,owner.winCard, false, true); + + room.endGame(); + return; + } + } + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..8542437 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,135 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; +import extend.mj.player.state.EXPlayerKongDrawState; +import extend.mj.player.state.EXPlayerWaitKongWinState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PROtherKongState.java + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + owner.is_fang_jian_gang = false; + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size()-1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + room.addScore(owner,activePlayer, Config.MING_GANG_SCORE,EXScore.KONG); + owner.ming_gang_num++; + activePlayer.dian_gang_num++; + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(owner.getRoom().activeCard); + int card = room.activeCard; + + owner.is_fang_jian_gang = false; + if (owner.getRoom().isFanPai(card)) + { + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + + owner.kongGroup.add(kongGroup); + owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, activePlayer.seat, kongGroup) ); + Util.removeCard(owner.cardInhand, card, 3); + owner.gangshangpao = false; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + owner.fang_jian_num++; + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + owner.is_fang_jian_gang = false; + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + else { + owner.is_fang_jian_gang = true; + } + } + else { + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + + owner.kongGroup.add(kongGroup); + owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, activePlayer.seat, kongGroup)); + Util.removeCard(owner.cardInhand, card, 4); + owner.gangshangpao = true; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + + room.activeCard = card; + boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG_MING); + if(qiangkong) { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + if(room.tipMap.size() == 0){ + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + toNextState(owner); + }else{ + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + room.activeCard = 0; + room.lastDiscardSeat = 0; + owner.settleLog.add(Config.SETTLE_MING_KONG); + toNextState(owner); + } + } + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.is_fang_jian_gang) + { + owner.is_fang_jian_gang = false; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + else { + owner.is_fang_jian_gang = false; + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..56c9aa6 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,77 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.winer = 1; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + + int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO); + int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + room.addScore(owner,activePlayer, owner.hu_score, EXScore.WIN); + } + + room.addPiaoNiaoScore(owner, activePlayer); + activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO); + activePlayer.winer = 2; + activePlayer.last_winer = 2; + + owner.settleLog.add(Config.SETTLE_JIE_PAO); + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + if (room.config.getBoolean(Config.ROOM_CONFIG_XIAOHU_BEI)) + { + List typeList = new ArrayList(); + for (Map.Entry entry : owner.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.IsDaHu()) + { + typeList.add(cardType.type); + } + } + + if (typeList.size() > 0) + { + for(int i = 0; i < typeList.size(); i++) { + int type = typeList.get(i); + owner.winMap.remove(type); + } + //方便显示 + WinCard.putWinCardType(owner.winMap, WinCardType.XIAO_HU_ZHONG_DA_HU, 1,2, false, "大胡"); + } + } + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + room.bankerSeat = owner.seat; + room.winCount += 1; + + owner.winCard = room.activeCard; + + room.winCallback( owner ,owner.winCard); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongState.java new file mode 100644 index 0000000..04994e7 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongState.java @@ -0,0 +1,71 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerKongDrawState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.uitl.CardUtil; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRPongKongState.java + */ +public class PRPongKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + CardUtil.removeGroup(owner.pongGroup, card); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_PONG, card)); + + int[] kong = new int[4]; + kong[0] = card; + kong[1] = card; + kong[2] = card; + kong[3] = card; + owner.kongGroup.add(kong); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_KONG, card)); + owner.gangshangpao = true; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard); + + room.activeCard = card; + boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG); + if(qiangkong) { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + toNextState(owner); + } + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.settleLog.add(Config.SETTLE_MING_KONG); + owner.getRoom().addAllScore(owner, Config.BU_GANG_SCORE, EXScore.KONG); + owner.getRoom().activeCard = 0; + owner.ming_gang_num++; + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java new file mode 100644 index 0000000..4b70a04 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongKongWinState.java @@ -0,0 +1,88 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PRPongKongWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + owner.winer = 1; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO); + int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + + boolean qg_type = room.config.getBoolean(Config.ROOM_CONFIG_QG_TYPE); + if(qg_type && owner.winType == 1) { //抢杠全包 + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + room.addScore(owner,activePlayer, owner.hu_score * (room.maxPlayers-1), EXScore.WIN); + } + } + else + { + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + room.addAllScore(owner, owner.hu_score,EXScore.WIN); + } + } + + room.addPiaoNiaoScore(owner, activePlayer); + activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO); + activePlayer.winer = 2; + activePlayer.last_winer = 2; + + owner.settleLog.add(Config.SETTLE_JIE_PAO); + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + if (room.config.getBoolean(Config.ROOM_CONFIG_XIAOHU_BEI)) + { + List typeList = new ArrayList(); + for (Map.Entry entry : owner.winMap.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.IsDaHu()) + { + typeList.add(cardType.type); + } + } + + if (typeList.size() > 0) + { + for(int i = 0; i < typeList.size(); i++) { + int type = typeList.get(i); + owner.winMap.remove(type); + } + //方便显示 + WinCard.putWinCardType(owner.winMap, WinCardType.XIAO_HU_ZHONG_DA_HU, 1,2, false, "大胡"); + } + } + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + room.bankerSeat = owner.seat; + room.winCount += 1; + + owner.winCard = room.activeCard; + + room.winCallback_qiangkong( owner ,owner.winCard); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..8ba4008 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,61 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PRPongState.java + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, activePlayer.seat)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..87baf04 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,82 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.*; +import extend.mj.player.state.EXPlayerDiscardState; +import extend.mj.player.state.EXPlayerKongDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRSelfKongState.java + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + owner.is_fang_jian_gang = false; + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + if (owner.getRoom().isFanPai(card)) + { + Util.removeCard(owner.cardInhand, card, 3); + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + owner.selfKongGroup.add(kongGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card, owner.seat, kongGroup)); + owner.gangshangpao = false; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + + room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.KONG); + owner.an_gang_num++; + owner.settleLog.add(Config.SETTLE_AN_KONG); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + else { + Util.removeCard(owner.cardInhand, card, 4); + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + owner.selfKongGroup.add(kongGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card, owner.seat, kongGroup)); + owner.gangshangpao = true; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + + room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.AN_KONG); + owner.an_gang_num++; + owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class)); + owner.settleLog.add(Config.SETTLE_AN_KONG); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..9e4bf9f --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,86 @@ +package extend.mj.player.rulestate; + + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.mj.*; + +import java.util.Map.Entry; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + + Util.removeCard(owner.cardInhand, owner.winCard, 1); + + int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO); + int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + + //爆炸马 加倍的情况 + if (!(niao == Config.NIAO_TYPE_ALL && opt == 1)) + { + if (room.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && room.get12ZhangLuoDi(owner) != null) + { + EXPlayer badPlayer = room.get12ZhangLuoDi(owner); + room.addScore(owner,badPlayer, owner.hu_score * (room.maxPlayers - 1), EXScore.WIN); + } + else + { + room.addAllScore(owner, owner.hu_score,EXScore.WIN); + } + } + + room.addAllPiaoNiaoScore(owner); + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + fromPlayer.last_winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + + if (room.lastBankerSeat == 0) + { + room.lastBankerSeat = room.bankerSeat; + } + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.niao_selfWin(owner,owner.winCard); + room.endGame(); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java new file mode 100644 index 0000000..d8a3310 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerChengDrawState.java @@ -0,0 +1,105 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerChengDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.pop(); + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHENG_DRAW_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..20ad406 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,52 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; + +/** + * ��ҳ�����ʾ״̬ + * + * + * 2017��8��30�� + * EXPlayerDisCardTipState.java + */ +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + /* + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + */ + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..b8cc702 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,166 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +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.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.room.state.EXRoomSetpState; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * �ȴ���ҳ���״̬ + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + //ITObject reconParam = new TObject(); + //owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + //return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + owner.notPongList.clear(); + owner.louhu = false; + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + if (owner.getRoom().isLaizi(discard)) + { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + owner.cheng_num++; + owner.is_cheng = true; + owner.stateMachine.changeState(Global.getState(EXPlayerChengDrawState.class)); + } + } + else { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + break; + case ActionEvent.EVENT_TIMER_AUTO: + owner.louhu = false; + discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + + owner.notPongList.clear(); + EXMainServer.gameCtr.outCard(owner, discard); + owner.gangshangpao = false; + + if (owner.getRoom().isLaizi(discard)) + { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + owner.cheng_num++; + owner.is_cheng = true; + owner.stateMachine.changeState(Global.getState(EXPlayerChengDrawState.class)); + } + } + else { + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..f725517 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,211 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + boolean laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI) > 0 ? true : false; + + if(owner.seat == room.adminSeat) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if (!IsGoodCard(owner, drawCard, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while (true); + room.card.cardList.addAll(tempCardList); + } else { + if (owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else if (owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard(owner, drawCard, laizi)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else { + owner.drawCard = room.card.pop(); + } + } + } + + if (room.isLaizi(owner.drawCard)) + { + owner.laizi_num++; + } + + if (owner.laizi_num >= 4 && room.config.getBoolean(Config.si_lai_you_xi)) + { + owner.laizi_num = 0; + room.addAllScore(owner, room.config.getInt(Config.si_lai_you_xi_score), EXScore.ZHONG_JIANG); + EXMainServer.gameCtr.actionCard(owner, 0, RuleWeight.TYPE_ZHONG_JIANG, owner.seat, null); + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + + private boolean IsGoodCard(EXPlayer player, int drawCard, boolean laizi) { + if (player.getRoom().isLaizi(drawCard)) + { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + for (int[] cardGroup : player.pongGroup) { + if (drawCard == cardGroup[0]) { + return true; + } + } + + HashMap map = new HashMap(); + WinCard win = new WinCard(player.cardInhand, drawCard, player.getRoom().card.laiziCard, player.getRoom().card.laiziCard2, laizi, true); + if (win.checkWin(map, player, player.getRoom(), true)) { + return true; + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } + + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..a731cc4 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,69 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.taurus.core.entity.ITObject; + +import com.taurus.core.entity.TObject; +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ���ץ����ʾ״̬ + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ; + if(Global.gameId == 1 && win && id == 0)return; + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + /* + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + */ + owner.tipMgr.doAction(id); + } + else if (cmd.equals(EXActionEvent.EVENT_DISCARD)) + { + boolean flag = false; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + flag = true; + } + else { + flag = false; + } + } + if (flag) + { + int id = 0; + owner.tipMgr.doAction(id); + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, param); + } + else { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + } + } + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java new file mode 100644 index 0000000..35d14f2 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongDrawState.java @@ -0,0 +1,106 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerKongDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.isLiuJu()) { + room.endGameByLiuJu(); + return; + } + + ITObject config = room.config; + + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + int laizi = room.config.getInt(Config.ROOM_CONFIG_LAIZI); + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + HashMap map = new HashMap(); + WinCard win = new WinCard(owner.cardInhand, drawCard, room.card.laiziCard, room.card.laiziCard2, laizi > 0 ? true : false, true); + if(!(hz_hu && win.laizi_count >0)) { + if (win.checkWin(map, owner, room, true)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.pop(); + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.KONG_DRAW_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..fae3c10 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,58 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +import java.util.Map; + +/** + * ���������ʾ�ȴ� + * + * + * 2017��8��30�� + * EXPlayerKongWinState.java + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } + else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Map.Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..1263fff --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * Ʊ����ʾ״̬ + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoNiaoTipEvent(owner); + owner.startActionTimer(); + }else{ + _action(owner, 0, 0); + } + } + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piaoNiao = id; + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + } + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..db227ac --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,61 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * �����ʾ������� + * + * + * 2017��8��30�� + * EXPlayerTipState.java + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_ZI_DONG_HU)) + { + Tip tip = owner.tipMgr.getTip(RuleWeight.TYPE_WIN); + if (tip != null) + { + owner.startActionTimer(1000); + return; + } + } + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tipEvent(owner); + } + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if(cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..dff6a34 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,24 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * ������ҵȴ��������ǹ�ܺ� + * + * + * 2017��8��30�� + * EXPlayerWaitKongWinState.java + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..858aee0 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,39 @@ +package extend.mj.player.state; + + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * ��ҵȴ�״̬ + * + * + * 2017��8��30�� + * EXPlayerWaitState.java + */ +public class EXPlayerWaitState extends StateBase { + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.forceCheckWin = true; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + owner.forceCheckWin = false; + break; + default: + break; + } + + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..a3e1836 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,66 @@ +package extend.mj.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayBack; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; + +/** + * ���䷢��״̬ + * + * + * 2017��8��30�� + * EXRoomDealState.java + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } +// owner.isplaying = true; +// owner.round += 1; + + boolean piao_niao = owner.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if(piao_niao) { + owner.piaoNiaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + }else{ + this.toNextState(owner); + } + + } + + @Override + public void toNextState(EXRoom owner) { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) { + if(owner.piaoNiaoCount==0) { + this.toNextState(owner); + } + } + + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..47fbd44 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,42 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ����ת����λ + * + * + * 2017��8��30�� + * EXRoomSetpState.java + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + this.toNextState(owner); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..1272100 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,33 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * ���俪ʼ״̬ + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Action.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..454d9ca --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + + */ +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..79f1ab8 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * ����������� + * + * + * 2017��8��30�� + * RuleBase.java + */ +public interface IRuleBase { + + /** + * ������� + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * ִ�иù��� + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Tip.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..b4f6ce4 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,46 @@ +package extend.mj.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.mj.WinCardType; + +import java.util.Map; + +/** + * tip������ + * + * + * + * 2017��8��30�� Tip.java + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int winType; + public int type; + public boolean self; + public Map winMap; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + this.self = false; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/TipManager.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..9f40ee2 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,142 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; + +/** + * + * + * + * 2017��9��18�� TipManager.java + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + public Tip getTip(int type) + { + for (Entry entry : this.tipMap.entrySet()) + { + Tip tip = entry.getValue(); + if (tip.type == type) + { + return tip; + } + } + return null; + } + + private void checkLouhu() { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_LOUHU)) + { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + } + + public void choicAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..e8ed060 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,51 @@ +package extend.mj.uitl; + +import java.util.List; +import java.util.Map; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.mj.OpCard; +import extend.mj.WinCardType; + +public class CardUtil { + + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card == opcards.get(i).card) { + opcards.remove(i); + return; + } + + } + + } + + static public ITArray toMPData_WinMap(Map map) { + return toMPData_WinMap(map,false); + } + + static public ITArray toMPData_WinMap(Map map,boolean is_opcard) { + if (map != null && map.size() > 0) { + ITArray array = TArray.newInstance(); + for (Map.Entry entry : map.entrySet()) { + WinCardType wct = entry.getValue(); + array.addTObject(wct.toTObject(is_opcard)); + } + return array; + } + return null; + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..7e3309f --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,2226 @@ +package extend.mj.uitl; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITObject; +import extend.mj.*; + +import java.util.*; + +public class WinCard { + + public List cardList; + public int laizi_count; + public int laizi1_count; + public int laizi2_count; + public int laizi1 = 0; + public int laizi2 = 0; + public Map cbCardMap; + + public WinCard(List cardInhand, int addCard, int laizi1, int laizi2, boolean islaizi, boolean selfCard) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + if (selfCard) + { + this.cardList.add(addCard); + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + } + else { + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + this.cardList.add(addCard); + } + + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + //钓鱼 + static public boolean IsDiaoYu(EXPlayer player, List cardInhand, int drawCard, int laizi1, int laizi2, boolean islaizi) + { + EXRoom room = player.getRoom(); + WinCard win = new WinCard(cardInhand, laizi1, laizi2, islaizi); + if (drawCard > 0 && drawCard != laizi1 && drawCard != laizi2 && win.laizi_count == 1) + { + ArrayList cardList = new ArrayList(); + cardList.addAll(cardInhand); + + Util.removeCard(cardList, drawCard, 1); + for (int index = 1; index <= 9; index++) { + for(int index2 = 1; index2 <= 3; index2++) + { + int card = index2 * 100 + index; + if (card == laizi1 || card == laizi2) + continue; + ArrayList tempCardList = new ArrayList(); + tempCardList.addAll(cardList); + tempCardList.add(card); + WinCard temp = new WinCard(tempCardList, laizi1, laizi2, islaizi); + HashMap map = new HashMap(); + if (!temp.checkWin(map, player, room, true)) { + return false; + } + } + } + + return true; + } + return false; + } + + public WinCard(List cardInhand, int laizi1, int laizi2, boolean islaizi) { + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.cbCardMap = new HashMap(); + if (islaizi) { + this.laizi1 = laizi1; + this.laizi2 = laizi2; + this.laizi1_count = Util.cardNum(laizi1, this.cardList); + this.laizi2_count = Util.cardNum(laizi2, this.cardList); + this.laizi_count = this.laizi1_count + this.laizi2_count; + Util.removeCard(this.cardList, laizi1, this.laizi1_count); + Util.removeCard(this.cardList, laizi2, this.laizi2_count); + } + Collections.sort(this.cardList); + for(int i = 0; i < this.cardList.size(); i++) + { + int card = this.cardList.get(i); + if (this.cbCardMap.containsKey(card)) + { + int num = this.cbCardMap.get(card); + this.cbCardMap.put(card, num+1); + } + else + { + this.cbCardMap.put(card, 1); + } + } + } + + public boolean checkWin(Map map, EXPlayer player, EXRoom room, boolean zimo) { + if (this.cardList.size() == 0) { + return false; + } + + if (room.config.getInt(Config.YI_JIAO_LAI_YOU) != 0) + { + return false; + } + + if (room.config.getBoolean(Config.LAIYOU_YILAIDAODI)) + { + //两个癞子不能胡牌 + if (this.laizi_count >= 2) + { + return false; + } + } + + long startTime = System.currentTimeMillis(); + int[] intListCard = WinSplitCard.SwitchToCardData(this.cardList); + List tagAnalyseItemList = new ArrayList(); + boolean hu = WinSplitCard.AnalyseChiHuCard(map, room.config, intListCard, this.laizi_count, player.opCardList, tagAnalyseItemList); + + if ((System.currentTimeMillis() - startTime) > 10) + Global.logger.info("get_hu_info use time:" + (System.currentTimeMillis() - startTime)); + + if (hu) + { + boolean laizi4_hu = room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU); + if (laizi4_hu) + { + if (this.laizi_count >= 4) { + if (room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU_2BEI)) + { + putWinCardType(map, WinCardType.LAIZI4_HU, 1,WinCardType.LAIZI4_HU_SCORE * 2, false, "四鬼胡牌"); + } + else + { + putWinCardType(map, WinCardType.LAIZI4_HU, 1,WinCardType.LAIZI4_HU_SCORE, false, "四鬼胡牌"); + } + return true; + } + } + + boolean jiabei = true; + boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); + if (wuguijiabei && room.config.getInt(Config.ROOM_CONFIG_LAIZI) > 0) + { + if (this.laizi_count <= 0) + { + putWinCardType(map, WinCardType.WU_GUI_JIABEI, 1,WinCardType.WU_GUI_JIABEI_SCORE, false, "无鬼2倍"); + } + } + + boolean liuju2bei = room.config.getBoolean(Config.ROOM_CONFIG_LIUJU_2BEI); + if (liuju2bei) + { + if (room.last_liuju) + { + putWinCardType(map, WinCardType.LIU_JU_2BEI, 1,WinCardType.LIU_JU_2BEI_SCORE, false, "流局2倍"); + } + } + + if (zimo) + { + boolean tianhu = room.config.getBoolean(Config.ROOM_CONFIG_TIANDIHU); + if(tianhu) { + if (room.bankerSeat == player.seat) + { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if(!otherPlayer.outcardList.isEmpty() || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.TIAN_HU, 1,WinCardType.TIAN_HU_SCORE, true, "天胡"); + } + } + else if (player.outcardList.isEmpty() && player.opCardList.isEmpty()) + { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if (player.playerid != otherPlayer.playerid) + { + if(otherPlayer.outcardList.size() > 1 || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.DI_HU, 1,WinCardType.DI_HU_SCORE, true, "地胡"); + } + } + } + + if (room.card.cardList.size() == 0 && room.config.getBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + WinCard.putWinCardType(map, WinCardType.HAI_DI_NAO_YUE, 1,WinCardType.HAI_DI_NAO_YUE_SCORE, false, "海底捞月"); + } + } + else { + /* + boolean tiandihu = room.config.getBoolean(Config.ROOM_CONFIG_TIANDIHU); + if(tiandihu && room.bankerSeat == room.activeSeat) { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if (otherPlayer.seat == room.bankerSeat) + { + if(otherPlayer.outcardList.size() != 1 || otherPlayer.outcardList.get(0) != room.activeCard || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + else + { + if(!otherPlayer.outcardList.isEmpty() || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.REN_HU, 1,WinCardType.TIAN_DI_HU_SCORE); + } + } + */ + } + + int maxType = 0; + int maxScore = 0; + List typeList = new ArrayList(); + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + int type = cardType.type; + if (cardType.IsDaHu()) + { + if (type == WinCardType.TIAN_HU || type == WinCardType.DI_HU || type == WinCardType.QUAN_FENG || type == WinCardType.YAO_JIU + || type == WinCardType.SHI_BA_LUO_HAN || type == WinCardType.XIAO_SHAN_YUAN || type == WinCardType.DA_SHAN_YUAN + || type == WinCardType.XIAO_SI_XI || type == WinCardType.DA_SI_XI || type == WinCardType.ZI_YI_SE) + { + if (cardType.score > maxScore) + { + maxScore = cardType.score; + maxType = type; + } + } + typeList.add(type); + } + } + + if (maxType > 0) + { + for(int i = 0; i < typeList.size(); i++) + { + int type = typeList.get(i); + if (type != maxType) + { + map.remove(type); + } + } + } + + if (zimo) + { + + } + else { + if (room.config.getBoolean(Config.ROOM_CONFIG_MENG_QING)) { + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.type == WinCardType.JIHU || cardType.type == WinCardType.PINGHU) { + boolean flag = true; + for (int i = 0; i < player.opCardList.size(); i++) { + OpCard op_card = player.opCardList.get(i); + if (op_card.type != RuleWeight.TYPE_SELF_KONG) { + flag = false; + } + } + if (flag) { + WinCard.putWinCardType(map, WinCardType.MEN_QING, 1, WinCardType.MENGQING_SCORE, false, "门清"); + } + break; + } + } + } + + if (room.config.getBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU)) + { + WinCardType jihuType = map.get(WinCardType.JIHU); + if (jihuType != null) + { + //鸡胡不能吃胡 + return false; + } + } + + if (room.config.getBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + int hu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE)) + { + hu_score = WinCardType.BASE_HU_SCORE; + } + else + { + player.hu_score = room.maxPlayers - 1; + player.di_score = room.maxPlayers - 1; + } + + int dahu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + dahu_score = 1; + } + int cheng_score = 1; + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + { + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + cheng_score *= cardType.score; + } + } + else + { + if (cardType.IsDaHu()) + { + dahu_score += cardType.score*WinCardType.DA_HU_BEI_SCORE; + } + else + { + cheng_score *= cardType.score; + } + } + } + } + + if (dahu_score > 0) + { + hu_score *= dahu_score; + } + + hu_score *= cheng_score; + + if (hu_score < 20) + { + return false; + } + } + } + + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info player:" + player.playerid + " hu:" + cardType.toString()); + } + } + + return hu; + } + + public boolean checkWin2(Map map, EXPlayer player, EXRoom room, boolean zimo) { + if (this.cardList.size() == 0) { + return false; + } + + long startTime = System.currentTimeMillis(); + int[] intListCard = WinSplitCard.SwitchToCardData(this.cardList); + List tagAnalyseItemList = new ArrayList(); + HashMap new_map = new HashMap(); + new_map.putAll(map); + boolean tempHu = WinSplitCard.TempAnalyseChiHuCard(new_map, room.config, intListCard, this.laizi_count, player.opCardList, tagAnalyseItemList); + if (tempHu) + { + for(int i = 0; i < tagAnalyseItemList.size(); i++) + { + TagAnalyseItem item = tagAnalyseItemList.get(i); + if (item.cbOpCard.size() != 4) + { + Global.logger.error("Exception cbOpCard.size() != 4"); + } + + Global.logger.info("-------ieye:" + item.cbCardEye); + + for(int j = 0; j < item.cbOpCard.size(); j++) + { + OpCard op_card = item.cbOpCard.get(j); + if (op_card.type == RuleWeight.TYPE_CHOW) + { + Global.logger.info("----------chi:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card); + } + else { + Global.logger.info("----------pong:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card); + } + } + } + + for (Map.Entry entry :new_map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info player:" + player.playerid + " hu:" + cardType.toString()); + } + } + Global.logger.info("get_hu_info use time:" + (System.currentTimeMillis() - startTime)); + + startTime = System.currentTimeMillis(); + boolean hu = AnalyseChiHuCard(map, player.opCardList, room.config); + Global.logger.info("AnalyseChiHuCard use time:" + (System.currentTimeMillis() - startTime)); + if (tempHu == hu) + { + Global.logger.info("AnalyseChiHuCard == get_hu_info"); + if (hu) + { + for (Map.Entry entry : new_map.entrySet()) { + if (!map.containsKey(entry.getKey())) + { + Global.logger.error("get_hu_info has hu " + entry.getKey() + " AnalyseChiHuCard not has"); + } + } + + for (Map.Entry entry : map.entrySet()) { + if (!new_map.containsKey(entry.getKey())) + { + Global.logger.error("AnalyseChiHuCard has hu " + entry.getKey() + " get_hu_info not has"); + } + } + } + } + else { + Global.logger.error("Exception AnalyseChiHuCard != get_hu_info"); + } + + if (hu) + { + boolean laizi4_hu = room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU); + if (laizi4_hu) + { + if (this.laizi_count >= 4) { + if (room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU_2BEI)) + { + putWinCardType(map, WinCardType.LAIZI4_HU, 1,WinCardType.LAIZI4_HU_SCORE * 2, false, "四鬼胡牌"); + } + else + { + putWinCardType(map, WinCardType.LAIZI4_HU, 1,WinCardType.LAIZI4_HU_SCORE, false, "四鬼胡牌"); + } + return true; + } + } + + boolean jiabei = true; + boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); + if (wuguijiabei && room.config.getInt(Config.ROOM_CONFIG_LAIZI) > 0) + { + if (this.laizi_count <= 0) + { + putWinCardType(map, WinCardType.WU_GUI_JIABEI, 1,WinCardType.WU_GUI_JIABEI_SCORE, false, "无鬼2倍"); + } + } + + boolean liuju2bei = room.config.getBoolean(Config.ROOM_CONFIG_LIUJU_2BEI); + if (liuju2bei) + { + if (room.last_liuju) + { + putWinCardType(map, WinCardType.LIU_JU_2BEI, 1,WinCardType.LIU_JU_2BEI_SCORE, false, "流局2倍"); + } + } + + if (zimo) + { + boolean tianhu = room.config.getBoolean(Config.ROOM_CONFIG_TIANDIHU); + if(tianhu) { + if (room.bankerSeat == player.seat) + { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if(!otherPlayer.outcardList.isEmpty() || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.TIAN_HU, 1,WinCardType.TIAN_HU_SCORE, true, "天胡"); + } + } + else if (player.outcardList.isEmpty() && player.opCardList.isEmpty()) + { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if (player.playerid != otherPlayer.playerid) + { + if(otherPlayer.outcardList.size() > 1 || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.DI_HU, 1,WinCardType.DI_HU_SCORE, true, "地胡"); + } + } + } + + if (room.card.cardList.size() == 0 && room.config.getBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE)) + { + WinCard.putWinCardType(map, WinCardType.HAI_DI_NAO_YUE, 1,WinCardType.HAI_DI_NAO_YUE_SCORE, false, "海底捞月"); + } + } + else { + /* + boolean tiandihu = room.config.getBoolean(Config.ROOM_CONFIG_TIANDIHU); + if(tiandihu && room.bankerSeat == room.activeSeat) { + boolean flag = true; + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer otherPlayer = (EXPlayer)entry.getValue(); + if (otherPlayer.seat == room.bankerSeat) + { + if(otherPlayer.outcardList.size() != 1 || otherPlayer.outcardList.get(0) != room.activeCard || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + else + { + if(!otherPlayer.outcardList.isEmpty() || !otherPlayer.opCardList.isEmpty()) { + flag = false; + } + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.REN_HU, 1,WinCardType.TIAN_DI_HU_SCORE); + } + } + */ + } + } + + int maxType = 0; + int maxScore = 0; + List typeList = new ArrayList(); + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + int type = cardType.type; + if (cardType.IsDaHu()) + { + if (type == WinCardType.TIAN_HU || type == WinCardType.DI_HU || type == WinCardType.QUAN_FENG || type == WinCardType.YAO_JIU + || type == WinCardType.SHI_BA_LUO_HAN || type == WinCardType.XIAO_SHAN_YUAN || type == WinCardType.DA_SHAN_YUAN + || type == WinCardType.XIAO_SI_XI || type == WinCardType.DA_SI_XI || type == WinCardType.ZI_YI_SE) + { + if (cardType.score > maxScore) + { + maxScore = cardType.score; + maxType = type; + } + } + typeList.add(type); + } + } + + if (maxType > 0) + { + for(int i = 0; i < typeList.size(); i++) + { + int type = typeList.get(i); + if (type != maxType) + { + map.remove(type); + } + } + } + + if (zimo) + { + + } + else + { + if (room.config.getBoolean(Config.ROOM_CONFIG_MENG_QING)) + { + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + if (cardType.type == WinCardType.JIHU || cardType.type == WinCardType.PINGHU) + { + boolean flag = true; + for(int i = 0; i < player.opCardList.size(); i++) + { + OpCard op_card = player.opCardList.get(i); + if (op_card.type != RuleWeight.TYPE_SELF_KONG) + { + flag = false; + } + } + if (flag) + { + WinCard.putWinCardType(map, WinCardType.MEN_QING, 1,WinCardType.MENGQING_SCORE, false, "门清"); + } + break; + } + } + } + + + if (room.config.getBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU)) + { + WinCardType jihuType = map.get(WinCardType.JIHU); + if (jihuType != null) + { + //鸡胡不能吃胡 + return false; + } + } + + if (room.config.getBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO)) + { + int hu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE)) + { + hu_score = WinCardType.BASE_HU_SCORE; + } + else + { + player.hu_score = room.maxPlayers - 1; + player.di_score = room.maxPlayers - 1; + } + + int dahu_score = 0; + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + dahu_score = 1; + } + int cheng_score = 1; + for (Map.Entry entry : map.entrySet()) { + WinCardType cardType = entry.getValue(); + { + if (room.config.getBoolean(Config.ROOM_CONFIG_DAHU_CHENG)) + { + if (cardType.IsDaHu()) + { + dahu_score *= cardType.score; + } + else + { + cheng_score *= cardType.score; + } + } + else + { + if (cardType.IsDaHu()) + { + dahu_score += cardType.score*WinCardType.DA_HU_BEI_SCORE; + } + else + { + cheng_score *= cardType.score; + } + } + } + } + + if (dahu_score > 0) + { + hu_score *= dahu_score; + } + + hu_score *= cheng_score; + + if (hu_score < 20) + { + return false; + } + } + } + + return hu; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score, boolean isDaHu, String desc) { + if (map == null) + return null; + if (isDaHu) + { + map.remove(WinCardType.JIHU); + map.remove(WinCardType.PINGHU); + } + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score, isDaHu, desc); + map.put(type, wct); + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } + } + + //七小对 + public int IsQiXiaoDui(Map tempCardList, List opCards) + { + //组合判断 + if (opCards.size() != 0) return -1; + + //麻将判断 + int mCountTmp = 0; + int mDaDuiNum = 0; + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if ((num!=0) && (num!=2) && (num!=4)) + { + return -1; + } + if (num == 2) { + mCountTmp++; + } + else if (num == 4) { + mCountTmp += 2; + mDaDuiNum++; + } + } + + if (mCountTmp == 7) + { + return mDaDuiNum; + } + + return -1; + } + + public boolean IsZiYiSe(Map tempCardList, List opCards) + { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + if (card < 400) + { + return false; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card < 400) + { + return false; + } + } + + return true; + } + + public boolean IsQingYiSe(Map tempCardList, List opCards) + { + int perColor = -1; + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + return true; + } + + public boolean IsHunYiSe(Map tempCardList, List opCards) + { + int perColor = -1; + boolean hunyise = false; + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + boolean IsShiBaLuoHan(Map tempCardList, List opCards) + { + int count = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.type == RuleWeight.TYPE_KONG || op_card.type == RuleWeight.TYPE_SELF_KONG) + { + count++; + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + //混幺九 + boolean IsHuYaoJiu(TagAnalyseItem item) { + boolean yaoKeZe = false; + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } else { + yaoKeZe = true; + } + } + } + } + + if (yaoKeZe) + { + return true; + } + + return false; + } + + //清幺九 + boolean IsQingYaoJiu(TagAnalyseItem item) { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + } + + return true; + } + + boolean IsQuanFeng(TagAnalyseItem item) { + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card < 400) { + return false; + } + } + } + + return true; + } + + int IsDaXiaoSanYuan(Map tempCardList, List opCards) + { + byte mKeCount = 0; + byte mDuiCount = 0; + //组合判断 + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.HONGZHONG + || op_card.card == Config.FACAI + || op_card.card == Config.BAIBAN) + { + mKeCount++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + + if (card == Config.HONGZHONG + || card == Config.FACAI + || card == Config.BAIBAN) + { + if (num == 2) + { + mDuiCount++; + } + + if (num == 3) + { + mKeCount++; + } + } + } + + //大三元 + if (mKeCount ==3) + { + return 1; + } + + //小三元 + if ((mKeCount ==2) && (mDuiCount ==1)) + { + return 2; + } + + return 0; + } + + boolean QuanQiuRen(Map tempCardList, List opCards) + { + if (opCards.size() != 4) + { + return false; + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num != 0 && num != 2) + { + return false; + } + } + return false; + } + + boolean ThirteenOne(Map tempCardList, List opCards) + { + if (opCards.size() > 0) + { + return false; + } + + List tempList = new ArrayList(); + tempList.add(101); + tempList.add(109); + tempList.add(201); + tempList.add(209); + tempList.add(301); + tempList.add(309); + tempList.add(Config.DONGFENG); + tempList.add(Config.NANFENG); + tempList.add(Config.XIFENG); + tempList.add(Config.BEIFENG); + tempList.add(Config.HONGZHONG); + tempList.add(Config.FACAI); + tempList.add(Config.BAIBAN); + + int jiangnum = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card = tempList.get(i); + if (tempCardList.getOrDefault(card, 0) != 1) + { + if (tempCardList.getOrDefault(card, 0) == 2) + { + jiangnum++; + if (jiangnum >= 2) + { + return false; + } + } + else { + return false; + } + } + } + + if (jiangnum == 1) + { + return true; + } + return false; + } + + int IsDaXiaoSiXi(Map tempCardList, List opCards) + { + int keCount = 0; + int duiCount = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + keCount++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == Config.DONGFENG + || card == Config.NANFENG + || card == Config.XIFENG + || card == Config.BEIFENG) + { + if (num == 3) + { + keCount++; + } + + if (num == 2) + { + duiCount++; + } + } + } + + //大四喜 + if (keCount >= 4) + { + return 1; + } + //小四喜 + else if (keCount >= 3 && duiCount >= 1) + { + return 2; + } + + return 0; + } + + boolean DaSiXi(Map tempCardList, List opCards) + { + int count = 0; + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + count++; + } + } + + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 3) + { + if (card == Config.DONGFENG + || card == Config.NANFENG + || card == Config.XIFENG + || card == Config.BEIFENG) + { + count++; + } + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + boolean AnalyseChiHuCard(Map map, List opCards, ITObject config) + { + Map tempCardList = new HashMap(); + tempCardList.putAll(this.cbCardMap); + + List tempCardListEx = new ArrayList(); + for (int index = 1; index <= 9; index++) { + boolean nowan = config.getBoolean(Config.ROOM_CONFIG_NO_WAN); + if (!nowan) + { + tempCardListEx.add(100 + index); + } + tempCardListEx.add(200 + index); + tempCardListEx.add(300 + index); + } + + boolean wufeng = config.getBoolean(Config.ROOM_CONFIG_WU_FENG); + if (!wufeng) + { + tempCardListEx.add(Config.DONGFENG); + tempCardListEx.add(Config.NANFENG); + tempCardListEx.add(Config.XIFENG); + tempCardListEx.add(Config.BEIFENG); + tempCardListEx.add(Config.HONGZHONG); + tempCardListEx.add(Config.FACAI); + tempCardListEx.add(Config.BAIBAN); + } + + if (this.laizi_count == 1) + { + List> tempLaiziMapList = new ArrayList>(); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 2) + { + List> tempLaiziMapList = new ArrayList>(); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 3) + { + List> tempLaiziMapList = new ArrayList>(); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 4) + { + List> tempLaiziMapList = new ArrayList>(); + for(int z = 0; z < tempCardListEx.size(); z++) + { + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) +1); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) -1); + } + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 5) + { + List> tempLaiziMapList = new ArrayList>(); + for(int a = 0; a < tempCardListEx.size(); a++) + { + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) +1); + for(int z = 0; z < tempCardListEx.size(); z++) + { + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) +1); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) -1); + } + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) -1); + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 6) + { + List> tempLaiziMapList = new ArrayList>(); + for(int b = 0; b < tempCardListEx.size(); b++) + { + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) +1); + for(int a = 0; a < tempCardListEx.size(); a++) + { + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) +1); + for(int z = 0; z < tempCardListEx.size(); z++) + { + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) +1); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) -1); + } + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) -1); + } + + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) -1); + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 7) + { + List> tempLaiziMapList = new ArrayList>(); + for(int c = 0; c < tempCardListEx.size(); c++) + { + tempCardList.put(tempCardListEx.get(c), tempCardList.getOrDefault(tempCardListEx.get(c), 0) +1); + for(int b = 0; b < tempCardListEx.size(); b++) + { + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) +1); + for(int a = 0; a < tempCardListEx.size(); a++) + { + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) +1); + for(int z = 0; z < tempCardListEx.size(); z++) + { + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) +1); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) -1); + } + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) -1); + } + + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) -1); + } + + tempCardList.put(tempCardListEx.get(c), tempCardList.getOrDefault(tempCardListEx.get(c), 0) -1); + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (this.laizi_count == 8) + { + List> tempLaiziMapList = new ArrayList>(); + for(int d = 0; d < tempCardListEx.size(); d++) + { + tempCardList.put(tempCardListEx.get(d), tempCardList.getOrDefault(tempCardListEx.get(d), 0) +1); + for(int c = 0; c < tempCardListEx.size(); c++) + { + tempCardList.put(tempCardListEx.get(c), tempCardList.getOrDefault(tempCardListEx.get(c), 0) +1); + for(int b = 0; b < tempCardListEx.size(); b++) + { + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) +1); + for(int a = 0; a < tempCardListEx.size(); a++) + { + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) +1); + for(int z = 0; z < tempCardListEx.size(); z++) + { + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) +1); + for(int y = 0; y < tempCardListEx.size(); y++) + { + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) +1); + for(int x =0; x < tempCardListEx.size(); x++) + { + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) +1); + for(int i = 0; i < tempCardListEx.size(); i++) + { + Map tempLaiziMap = new HashMap(); + if (AnalyseChiHuCardEx(tempLaiziMap, tempCardList, tempCardListEx.get(i), opCards, config)) + { + tempLaiziMapList.add(tempLaiziMap); + } + } + tempCardList.put(tempCardListEx.get(x), tempCardList.getOrDefault(tempCardListEx.get(x), 0) -1); + } + tempCardList.put(tempCardListEx.get(y), tempCardList.getOrDefault(tempCardListEx.get(y), 0) -1); + } + tempCardList.put(tempCardListEx.get(z), tempCardList.getOrDefault(tempCardListEx.get(z), 0) -1); + } + tempCardList.put(tempCardListEx.get(a), tempCardList.getOrDefault(tempCardListEx.get(a), 0) -1); + } + + tempCardList.put(tempCardListEx.get(b), tempCardList.getOrDefault(tempCardListEx.get(b), 0) -1); + } + + tempCardList.put(tempCardListEx.get(c), tempCardList.getOrDefault(tempCardListEx.get(c), 0) -1); + } + + tempCardList.put(tempCardListEx.get(d), tempCardList.getOrDefault(tempCardListEx.get(d), 0) -1); + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + map.putAll(tempLaiziMap); + return true; + } + return false; + } + + if (AnalyseChiHuCardEx(map, tempCardList, 0, opCards, config)) + { + return true; + } + + return false; + } + + boolean AnalyseChiHuCardEx(Map map, Map cardListParam, int curCard, List opCards, ITObject config) + { + Map tempCardList = new HashMap<>(); + tempCardList.putAll(cardListParam); + + if (curCard > 0) + { + tempCardList.put(curCard, tempCardList.getOrDefault(curCard, 0)+1); + } + + List clearCardList = new ArrayList<>(); + for (Map.Entry entry : tempCardList.entrySet()) { + if (entry.getValue() == 0) + { + clearCardList.add(entry.getKey()); + } + } + + for(int i = 0; i < clearCardList.size(); i++) + { + tempCardList.remove(clearCardList.get(i)); + } + + //变量定义 + List tagAnalyseItemList = new ArrayList(); + List wChiHuKind = new ArrayList(); + + //分析麻将 + AnalyseCard(tempCardList, opCards, tagAnalyseItemList); + + //胡牌分析 + if (tagAnalyseItemList.size() > 0) + { + //牌型分析 + for (int i = 0;i < tagAnalyseItemList.size();i++) + { + //变量定义 + boolean bLianCard=false,bPengCard=false,b258Card=false; + TagAnalyseItem pAnalyseItem= tagAnalyseItemList.get(i); + + //牌型分析 + for (int j = 0;j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) { + bPengCard = true; + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + bLianCard = true; + } + } + + //牌型判断 + if (bLianCard==false && bPengCard==false) + { + return false; + } + + if (bLianCard && bPengCard == false) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, true, "平胡"); + } + else if (bLianCard && bPengCard) + { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, true, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + + //特殊--碰碰胡 + if ((bLianCard==false)&&(bPengCard==true)) + { + if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) + { + wChiHuKind.add(WinCardType.PENGPENGHU); + putWinCardType(map, WinCardType.PENGPENGHU, 1,WinCardType.PENGPENGHU_SCORE, true, "碰碰胡"); + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) + { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1,WinCardType.PINGHU_SCORE, true, "平胡"); + } + else + { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1,WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_YAO_JIU)) + { + if (config.getBoolean(Config.ROOM_CONFIG_han19)) + { + if (IsHuYaoJiu(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1,WinCardType.YAO_JIU_SCORE, true, "混幺九"); + } + } + else + { + if (IsQingYaoJiu(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1,WinCardType.YAO_JIU_SCORE, true, "清幺九"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QING_YAO_JIU)) + { + if (IsQingYaoJiu(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.QING_YAO_JIU, 1,WinCardType.QING_YAO_JIU_SCORE, true, "清幺九"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG)) + { + if (IsQuanFeng(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.QUAN_FENG); + putWinCardType(map, WinCardType.QUAN_FENG, 1,WinCardType.QUAN_FENG_SCORE, true, "全风"); + } + } + } + } + + //特殊胡牌 + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + int DaDuiNum = IsQiXiaoDui(tempCardList, opCards); + if (DaDuiNum >= 0) + { + wChiHuKind.add(WinCardType.QIXIAODUI); + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + if (DaDuiNum == 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + else if (DaDuiNum == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA_QIXIAODUI, 1, WinCardType.HAOHUA_QIXIAODUI_SCORE, true, "豪华七小对"); + } + else if (DaDuiNum == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA2_QIXIAODUI, 1, WinCardType.HAOHUA2_QIXIAODUI_SCORE, true, "双豪华七小对"); + } + else if (DaDuiNum == 3) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA3_QIXIAODUI, 1, WinCardType.HAOHUA3_QIXIAODUI_SCORE, true, "三豪华七小对"); + } + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHISHANGYAO)) + { + if (ThirteenOne(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.SHI_SHAN_YAO); + putWinCardType(map, WinCardType.SHI_SHAN_YAO, 1, WinCardType.SHI_SHAN_YAO_SCORE, true, "十三幺"); + } + } + + //结果判断 + if (wChiHuKind.size() > 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN) || config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + int sanyuan = IsDaXiaoSanYuan(tempCardList, opCards); + if (sanyuan > 0) + { + //大三元 + if (sanyuan == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN)) + { + wChiHuKind.add(WinCardType.DA_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SHAN_YUAN, 1, WinCardType.DA_SHAN_YUAN_SCORE, true, "大三元"); + } + } + //小山元 + else if (sanyuan == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SHAN_YUAN, 1, WinCardType.XIAO_SHAN_YUAN_SCORE, true, "小三元"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI) || config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + int sixi = IsDaXiaoSiXi(tempCardList, opCards); + if (sixi > 0) + { + //大四喜 + if (sixi == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SI_XI, 1, WinCardType.DA_SI_XI_SCORE, true, "大四喜"); + } + } + //小四喜 + else if (sixi == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SI_XI, 1, WinCardType.XIAO_SI_XI_SCORE, true, "小四喜"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + if (IsShiBaLuoHan(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.SHI_BA_LUO_HAN); + putWinCardType(map, WinCardType.SHI_BA_LUO_HAN, 1, WinCardType.SHI_BA_LUO_HAN_SCORE, true, "十八罗汉"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + if (QuanQiuRen(tempCardList, opCards)) + { + wChiHuKind.add(WinCardType.QUAN_QIU_REN); + putWinCardType(map, WinCardType.QUAN_QIU_REN, 1, WinCardType.QUAN_QIU_REN_SCORE, true, "全求人"); + } + } + + return true; + } + + return false; + } + + boolean AnalyseCard(Map tempCardList, List opCards, List tagAnalyseItemList) + { + //计算数目 + int cbCardCount = 0; + for (Map.Entry entry : tempCardList.entrySet()) { + cbCardCount += entry.getValue(); + } + + //效验数目 + if ((cbCardCount<2)||(cbCardCount>14)||((cbCardCount-2)%3!=0)) { + return false; + } + + //变量定义 + List tagKindList = new ArrayList(); + + //需求判断 + int cbLessKindItem=(cbCardCount-2)/3; + if (cbLessKindItem+opCards.size()!=4) + { + return false; + } + + //单吊判断 + if (cbLessKindItem==0) + { + //效验参数 + if (!((cbCardCount==2)&&(opCards.size()==4))) + { + return false; + } + + //牌眼判断 + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) + { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置结果 + for (int i = 0; i < opCards.size(); i++) + { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(src_card); + } + AnalyseItem.cbCardEye = card; + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + + return true; + } + } + + return false; + } + + //拆分分析 + if (cbCardCount>=3) + { + for (Map.Entry entry : tempCardList.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + //同牌判断 + if (num >= 3) + { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_PONG; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card; + kindItem.cbCardList[2] = card; + tagKindList.add(kindItem); + } + + //连牌判断 + if (card < 400 && card % 100 <= 7 && num >0) + { + for(int i = 1; i <= num; i++) + { + if (tempCardList.getOrDefault(card + 1, 0) >= i && tempCardList.getOrDefault(card + 2, 0) >= i) + { + TagKindItem kindItem = new TagKindItem(); + kindItem.type = RuleWeight.TYPE_CHOW; + kindItem.card = card; + kindItem.cbCardList[0] = card; + kindItem.cbCardList[1] = card + 1; + kindItem.cbCardList[2] = card + 2; + tagKindList.add(kindItem); + } + } + } + } + } + + //组合分析 + if (tagKindList.size() >= cbLessKindItem) + { + //变量定义 + Integer[] cbIndex = new Integer[4]; //{0,1,2,3}; + cbIndex[0] = 0; + cbIndex[1] = 1; + cbIndex[2] = 2; + cbIndex[3] = 3; + + TagKindItem[] pKindItem = new TagKindItem[4]; + pKindItem[0] = null; + pKindItem[1] = null; + pKindItem[2] = null; + pKindItem[3] = null; + + //开始组合 + do + { + //设置变量 + Map cbCardMap_temp = new HashMap(); + cbCardMap_temp.putAll(tempCardList); + + for (int i = 0;i < cbLessKindItem; i++) { + pKindItem[i] = tagKindList.get(cbIndex[i]); + } + + //数量判断 + boolean bEnoughCard=true; + for (int i = 0; i < cbLessKindItem * 3; i++) + { + //存在判断 + int cbCardIndex = pKindItem[i/3].cbCardList[i%3]; + if (cbCardMap_temp.getOrDefault(cbCardIndex, 0) <= 0) + { + bEnoughCard=false; + break; + } + else + { + if (cbCardMap_temp.containsKey(cbCardIndex)) + { + cbCardMap_temp.put(cbCardIndex, cbCardMap_temp.get(cbCardIndex)-1); + } + } + } + + //胡牌判断 + if (bEnoughCard == true) + { + //牌眼判断 + int cbCardEye = 0; + for (Map.Entry entry : cbCardMap_temp.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) + { + cbCardEye = card; + break; + } + } + + //组合类型 + if (cbCardEye != 0) + { + //变量定义 + TagAnalyseItem AnalyseItem = new TagAnalyseItem(); + + //设置组合 + for (int i = 0; i < opCards.size(); i++) + { + OpCard src_card = opCards.get(i); + OpCard op_card = new OpCard(src_card.type, src_card.card); + AnalyseItem.cbOpCard.add(op_card); + } + + //设置牌型 + for (int i = 0; i < cbLessKindItem; i++) + { + OpCard op_card = new OpCard(pKindItem[i].type, pKindItem[i].card); + AnalyseItem.cbOpCard.add(op_card); + } + + //设置牌眼 + AnalyseItem.cbCardEye = cbCardEye; + + //插入结果 + tagAnalyseItemList.add(AnalyseItem); + } + } + + //设置索引 + if (cbIndex[cbLessKindItem-1] == (tagKindList.size()-1)) + { + int i = cbLessKindItem-1; + for (;i>0;i--) + { + if ((cbIndex[i-1]+1) != cbIndex[i]) + { + int cbNewIndex=cbIndex[i-1]; + for (int j=(i-1);j 0); + } +} diff --git a/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinSplitCard.java b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinSplitCard.java new file mode 100644 index 0000000..d0c2e16 --- /dev/null +++ b/game_mj_yijiaolaiyou/src/main/java/extend/mj/uitl/WinSplitCard.java @@ -0,0 +1,2169 @@ +package extend.mj.uitl; + +import com.game.Global; +import com.taurus.core.entity.ITObject; +import extend.mj.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class WinSplitCard { + //获取数值 + public static int GetCardValue(int cbCardData) { return cbCardData % 100; } + //获取花色 + public static int GetCardColor(int cbCardData) { return cbCardData / 100; } + + //扑克转换 + public static int SwitchToCardData(int cbCardIndex) + { + int cbCardColor= cbCardIndex/10; + int cbCardValue= cbCardIndex%10; + if (cbCardIndex < 27) + { //9 -> 200 + 1 //10 -> 202 //11 -> 203 // 17 -> 209 // 18 -> 301 19->302 20 -> 303 26->309 + if (cbCardValue + (cbCardColor+1) >= 10) + { + return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 + 1; + } + else { + return (cbCardColor+1) * 100 + cbCardValue + (cbCardColor+1); + } + } + else { //27 -> 400 //28 -> 403 // 29 -> 406 // 30 -> 409 //31 -> 412 // 32 -> 415 // 33 -> 418 + if (cbCardValue + (cbCardColor+1) >= 10) + { + return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 * 3; + } + else { + return (cbCardColor+1) * 100 + (cbCardValue + cbCardColor) * 3; + } + } + } + + //扑克转换 + public static int SwitchToCardIndex(int cbCardData) + { + //扑克属性 + int cbCardColor=GetCardColor(cbCardData); + int cbCardValue=GetCardValue(cbCardData); + if (cbCardColor <= 3) + { + return (cbCardColor-1)*10+cbCardValue-cbCardColor; + } + else { + return (cbCardColor-1)*10+cbCardValue/3-cbCardColor+1; + } + } + + //扑克转换 + public static int[] SwitchToCardData(List cardInhand) + { + int[] cardIndex = new int[34]; + for(int i = 0; i < cardIndex.length; i++) + { + cardIndex[i] = 0; + } + + for(int i = 0; i < cardInhand.size(); i++) + { + int pos = SwitchToCardIndex(cardInhand.get(i)); + cardIndex[pos]++; + } + + return cardIndex; + } + + //扑克转换 + public static List SwitchToCardIndex(int[] cardIndex) + { + List cardIndexList = new ArrayList(); + for(int i = 0; i < cardIndex.length; i++) + { + for(int j = 0; j < cardIndex[i]; j++) + { + int card = SwitchToCardData(i); + cardIndexList.add(card); + } + } + return cardIndexList; + } + + public final static WinCardType putWinCardType(Map map, int type, int value,int score, boolean isDaHu, String desc) { + if (map == null) + return null; + if (isDaHu) + { + map.remove(WinCardType.JIHU); + map.remove(WinCardType.PINGHU); + } + if (map.containsKey(type)) { + WinCardType wct = map.get(type); + wct.value += value; + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } else { + WinCardType wct = new WinCardType(type, value,score, isDaHu, desc); + map.put(type, wct); + //Global.logger.info("putWinCardType: " + wct.toString()); + return wct; + } + } + + public static boolean IsZiYiSe(int[] hand_cards, int max_gui, List opCards) + { + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + if (op_card.card < 400) + { + return false; + } + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + if (card < 400) + { + return false; + } + } + } + + return true; + } + + public static boolean IsZiYiSe(TagAnalyseItem item) + { + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + if (card < 400) + { + return false; + } + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card < 400) + { + return false; + } + } + } + + return true; + } + + public static boolean IsQingYiSe(int[] hand_cards, int max_gui, List opCards) + { + int perColor = -1; + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + return true; + } + + public static boolean IsQingYiSe(TagAnalyseItem item) + { + int perColor = -1; + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + int color = card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (color >= 4) + { + return false; + } + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + } + return true; + } + + public static boolean IsHunYiSe(int[] hand_cards, int max_gui, List opCards) + { + int perColor = -1; + boolean hunyise = false; + + for(int i = 0; i < opCards.size(); i++) + { + OpCard op_card = opCards.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + } + + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num > 0) + { + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + } + + int need_gui = 0; + if (hunyise == false) + { + need_gui++; + hunyise = true; + } + + if (perColor == -1) + { + need_gui++; + perColor = 1; + } + + if (need_gui > max_gui) + { + return false; + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + public static boolean IsHunYiSe(TagAnalyseItem item) + { + int perColor = -1; + boolean hunyise = false; + if (item.cbCardEye != 0) + { + int card = item.cbCardEye; + int color = card / 100; + if (card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + int color = op_card.card / 100; + if (op_card.card < 400) + { + if (perColor == -1) + { + perColor = color; + } + else if (perColor != color) + { + return false; + } + else { + perColor = color; + } + } + else + { + hunyise = true; + } + } + else { + hunyise = true; + } + } + + if (perColor != -1 && hunyise) + return true; + + return false; + } + + public static boolean IsShiBaLuoHan(TagAnalyseItem item) + { + int count = 0; + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_KONG || op_card.type == RuleWeight.TYPE_SELF_KONG) + { + count++; + } + } + + if (count >= 4) + { + return true; + } + + return false; + } + + //混幺九 + public static boolean IsHuYaoJiu(TagAnalyseItem item) { + boolean yaoKeZe = false; + if (item.cbCardEye != 0) + { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + } + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0) + { + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } else { + yaoKeZe = true; + } + } + } + else { + yaoKeZe = true; + } + } + } + + if (yaoKeZe) + { + return true; + } + + return false; + } + + //清幺九 + public static boolean IsQingYaoJiu(TagAnalyseItem item) { + if (item.cbCardEye != 0) + { + if (item.cbCardEye < 400) { + int value = item.cbCardEye % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + + + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0) + { + if (card < 400) { + int value = card % 100; + if (value != 1 && value != 9) { + return false; + } + } + else + { + return false; + } + } + } + } + + return true; + } + + public static boolean IsQuanFeng(TagAnalyseItem item) { + for (int i = 0; i < item.cbOpCard.size(); i++) { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.type == RuleWeight.TYPE_CHOW) { + return false; + } else { + int card = op_card.card; + if (card != 0 && card < 400) { + return false; + } + } + } + + return true; + } + + + public static int IsDaXiaoSanYuan(TagAnalyseItem item) + { + byte mKeCount = 0; + byte mDuiCount = 0; + + if (item.cbCardEye != 0) + { + if (item.cbCardEye == Config.HONGZHONG + || item.cbCardEye == Config.FACAI + || item.cbCardEye == Config.BAIBAN) + { + mDuiCount++; + } + } + else { + mDuiCount++; + } + + //组合判断 + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card == Config.HONGZHONG + || op_card.card == Config.FACAI + || op_card.card == Config.BAIBAN) + { + mKeCount++; + } + } + else { + mKeCount++; + } + } + + //大三元 + if (mKeCount ==3) + { + return 1; + } + + //小三元 + if ((mKeCount ==2) && (mDuiCount ==1)) + { + return 2; + } + + return 0; + } + + public static int IsDaXiaoSiXi(TagAnalyseItem item) + { + int keCount = 0; + int duiCount = 0; + if (item.cbCardEye != 0) + { + if (item.cbCardEye == Config.DONGFENG + || item.cbCardEye == Config.NANFENG + || item.cbCardEye == Config.XIFENG + || item.cbCardEye == Config.BEIFENG) + { + duiCount++; + } + } + else { + duiCount++; + } + + for(int i = 0; i < item.cbOpCard.size(); i++) + { + OpCard op_card = item.cbOpCard.get(i); + if (op_card.card != 0) + { + if (op_card.card == Config.DONGFENG + || op_card.card == Config.NANFENG + || op_card.card == Config.XIFENG + || op_card.card == Config.BEIFENG) + { + keCount++; + } + } + } + + + //大四喜 + if (keCount >= 4) + { + return 1; + } + //小四喜 + else if (keCount >= 3 && duiCount >= 1) + { + return 2; + } + + return 0; + } + + public static boolean QuanQiuRen(List opCards) + { + if (opCards.size() != 4) + { + return false; + } + + return false; + } + + //七小对 + public static int IsQiXiaoDui(int[] hand_cards, int max_gui, List opCards) + { + //组合判断 + if (opCards.size() != 0) return -1; + + //麻将判断 + int mCountTmp = 0; + int mDaDuiNum = 0; + + int need_gui = 0; + int curDuiNum = 0; + for(int i = 0; i < hand_cards.length; i++) + { + int card = SwitchToCardData(i); + int num = hand_cards[i]; + if (num == 1) + { + need_gui++; + mCountTmp++; + curDuiNum++; + if (need_gui > max_gui) + { + return -1; + } + } + else if (num == 3) + { + need_gui++; + mCountTmp += 2; + mDaDuiNum++; + if (need_gui > max_gui) + { + return -1; + } + } + else if (num == 2) { + curDuiNum++; + mCountTmp++; + } + else if (num == 4) { + mCountTmp += 2; + mDaDuiNum++; + } + } + + if (need_gui > max_gui) + { + return -1; + } + + if ((max_gui - need_gui) % 2 != 0) + { + return -1; + } + + int guiDuiNum = (max_gui - need_gui) / 2; + if (curDuiNum <= guiDuiNum) + { + mCountTmp += curDuiNum; + mDaDuiNum += curDuiNum; + mDaDuiNum += (guiDuiNum-curDuiNum) / 2; + mCountTmp += (guiDuiNum-curDuiNum); + } + else { + mCountTmp += guiDuiNum; + mDaDuiNum += guiDuiNum; + } + + + if (mCountTmp == 7) + { + return mDaDuiNum; + } + + return -1; + } + + public static boolean ThirteenOne(int[] hand_cards, int max_gui, List opCards) + { + if (opCards.size() > 0) + { + return false; + } + + List tempList = new ArrayList(); + tempList.add(0); //101 + tempList.add(8); //109 + tempList.add(9); //201 + tempList.add(17); //209 + tempList.add(18); //301 + tempList.add(26); //309 + tempList.add(27); //东风 + tempList.add(28); + tempList.add(29); + tempList.add(30); + tempList.add(31); + tempList.add(32); + tempList.add(33); + + int jiangnum = 0; + int need_gui = 0; + for(int i = 0; i < tempList.size(); i++) + { + int card_num = hand_cards[tempList.get(i)]; + if (card_num != 1) + { + if (card_num == 0) + { + need_gui++; + if (need_gui > max_gui) + { + return false; + } + } + else if (card_num == 2) + { + jiangnum++; + if (jiangnum >= 2) + { + return false; + } + } + else { + return false; + } + } + } + + if (jiangnum == 0) + { + need_gui++; + jiangnum++; + if (need_gui > max_gui) + { + return false; + } + } + + if (jiangnum == 1) + { + return true; + } + + return false; + } + + public static boolean AnalyseChiHuCard(Map curMap, ITObject config, int[] hand_cards, int gui_num, List opCards, List tagAnalyseItemList) { + get_hu_info(hand_cards, gui_num, opCards, tagAnalyseItemList); + + //变量定义 + List wChiHuKind = new ArrayList(); + + List> tempLaiziMapList = new ArrayList>(); + + //特殊胡牌 + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards); + if (DaDuiNum >= 0) + { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + + wChiHuKind.add(WinCardType.QIXIAODUI); + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + if (DaDuiNum == 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + else if (DaDuiNum == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA_QIXIAODUI, 1, WinCardType.HAOHUA_QIXIAODUI_SCORE, true, "豪华七小对"); + } + else if (DaDuiNum == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA2_QIXIAODUI, 1, WinCardType.HAOHUA2_QIXIAODUI_SCORE, true, "双豪华七小对"); + } + else if (DaDuiNum == 3) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA3_QIXIAODUI, 1, WinCardType.HAOHUA3_QIXIAODUI_SCORE, true, "三豪华七小对"); + } + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + + Global.logger.info("get_hu_info-----begin------------"); + for (Map.Entry entry :map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info hu:" + cardType.toString()); + } + Global.logger.info("get_hu_info-----end------------"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHISHANGYAO)) + { + if (ThirteenOne(hand_cards, gui_num, opCards)) + { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + + wChiHuKind.add(WinCardType.SHI_SHAN_YAO); + putWinCardType(map, WinCardType.SHI_SHAN_YAO, 1, WinCardType.SHI_SHAN_YAO_SCORE, true, "十三幺"); + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + + Global.logger.info("get_hu_info-----begin------------"); + for (Map.Entry entry :map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info hu:" + cardType.toString()); + } + Global.logger.info("get_hu_info-----end------------"); + } + } + + //胡牌分析 + for (int i = 0; i < tagAnalyseItemList.size(); i++) { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + //变量定义 + int lianCardNum = 0; + int pengCardNum = 0; + int lianOrPengNum = 0; + TagAnalyseItem pAnalyseItem = tagAnalyseItemList.get(i); + + //牌型分析 + for (int j = 0; j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) { + if (cbWeaveKind.card == 0) + { + lianOrPengNum++; + } + else if (cbWeaveKind.card != 0 && cbWeaveKind.card2 == 0 && cbWeaveKind.card3 == 0) + { + lianOrPengNum++; + } + else { + pengCardNum++; + } + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + lianCardNum++; + } + } + + //特殊--碰碰胡 + if (pengCardNum + lianOrPengNum == 4 || pAnalyseItem.isPengPengHu) { + if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) { + wChiHuKind.add(WinCardType.PENGPENGHU); + putWinCardType(map, WinCardType.PENGPENGHU, 1, WinCardType.PENGPENGHU_SCORE, true, "碰碰胡"); + } else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + else if (lianCardNum + lianOrPengNum == 4) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_YAO_JIU)) { + if (config.getBoolean(Config.ROOM_CONFIG_han19)) { + if (IsHuYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "混幺九"); + } + } else { + if (IsQingYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "清幺九"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QING_YAO_JIU)) { + if (IsQingYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.QING_YAO_JIU, 1, WinCardType.QING_YAO_JIU_SCORE, true, "清幺九"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG)) { + if (IsQuanFeng(pAnalyseItem)) { + wChiHuKind.add(WinCardType.QUAN_FENG); + putWinCardType(map, WinCardType.QUAN_FENG, 1, WinCardType.QUAN_FENG_SCORE, true, "全风"); + } + } + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN) || config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + int sanyuan = IsDaXiaoSanYuan(pAnalyseItem); + if (sanyuan > 0) + { + //大三元 + if (sanyuan == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN)) + { + wChiHuKind.add(WinCardType.DA_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SHAN_YUAN, 1, WinCardType.DA_SHAN_YUAN_SCORE, true, "大三元"); + } + } + //小山元 + else if (sanyuan == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SHAN_YUAN, 1, WinCardType.XIAO_SHAN_YUAN_SCORE, true, "小三元"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI) || config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + int sixi = IsDaXiaoSiXi(pAnalyseItem); + if (sixi > 0) + { + //大四喜 + if (sixi == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SI_XI, 1, WinCardType.DA_SI_XI_SCORE, true, "大四喜"); + } + } + //小四喜 + else if (sixi == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SI_XI, 1, WinCardType.XIAO_SI_XI_SCORE, true, "小四喜"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + if (IsShiBaLuoHan(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.SHI_BA_LUO_HAN); + putWinCardType(map, WinCardType.SHI_BA_LUO_HAN, 1, WinCardType.SHI_BA_LUO_HAN_SCORE, true, "十八罗汉"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + if (QuanQiuRen(opCards)) + { + wChiHuKind.add(WinCardType.QUAN_QIU_REN); + putWinCardType(map, WinCardType.QUAN_QIU_REN, 1, WinCardType.QUAN_QIU_REN_SCORE, true, "全求人"); + } + } + + Global.logger.info("get_hu_info-----begin------------"); + if (pAnalyseItem.cbOpCard.size() != 4) + { + Global.logger.error("Exception cbOpCard.size() != 4"); + } + + Global.logger.info("get_hu_info-------ieye:" + pAnalyseItem.cbCardEye + " ieye2:" + pAnalyseItem.cbCardEye2); + + for(int j = 0; j < pAnalyseItem.cbOpCard.size(); j++) + { + OpCard op_card = pAnalyseItem.cbOpCard.get(j); + if (op_card.type == RuleWeight.TYPE_CHOW) + { + Global.logger.info("get_hu_info----------chi:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card); + } + else { + Global.logger.info("get_hu_info----------pong:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card); + } + } + for (Map.Entry entry :map.entrySet()) { + WinCardType cardType = entry.getValue(); + Global.logger.info("get_hu_info hu:" + cardType.toString()); + } + Global.logger.info("get_hu_info-----end------------"); + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + + + int maxType = 0; + int maxScore = 0; + List typeList = new ArrayList(); + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + int type = cardType.type; + if (cardType.IsDaHu()) + { + if (type == WinCardType.TIAN_HU || type == WinCardType.DI_HU || type == WinCardType.QUAN_FENG || type == WinCardType.YAO_JIU + || type == WinCardType.SHI_BA_LUO_HAN || type == WinCardType.XIAO_SHAN_YUAN || type == WinCardType.DA_SHAN_YUAN + || type == WinCardType.XIAO_SI_XI || type == WinCardType.DA_SI_XI || type == WinCardType.ZI_YI_SE) + { + if (cardType.score > maxScore) + { + maxScore = cardType.score; + maxType = type; + } + } + typeList.add(type); + } + } + + if (maxType > 0) + { + for(int i = 0; i < typeList.size(); i++) + { + int type = typeList.get(i); + if (type != maxType) + { + tempLaiziMap.remove(type); + } + } + } + + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + curMap.putAll(tempLaiziMap); + return true; + } + return false; + } + + public static boolean TempAnalyseChiHuCard(Map curMap, ITObject config, int[] hand_cards, int gui_num, List opCards, List tagAnalyseItemList) { + get_hu_info(hand_cards, gui_num, opCards, tagAnalyseItemList); + + //变量定义 + List wChiHuKind = new ArrayList(); + + List> tempLaiziMapList = new ArrayList>(); + + //特殊胡牌 + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards); + if (DaDuiNum >= 0) + { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + + wChiHuKind.add(WinCardType.QIXIAODUI); + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + { + if (DaDuiNum == 0) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + else if (DaDuiNum == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA_QIXIAODUI, 1, WinCardType.HAOHUA_QIXIAODUI_SCORE, true, "豪华七小对"); + } + else if (DaDuiNum == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA2_QIXIAODUI, 1, WinCardType.HAOHUA2_QIXIAODUI_SCORE, true, "双豪华七小对"); + } + else if (DaDuiNum == 3) + { + if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI)) + putWinCardType(map, WinCardType.HAOHUA3_QIXIAODUI, 1, WinCardType.HAOHUA3_QIXIAODUI_SCORE, true, "三豪华七小对"); + } + } + else { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI)) + { + if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番"); + } + else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI)) + { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍"); + } + else { + putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对"); + } + } + } + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHISHANGYAO)) + { + if (ThirteenOne(hand_cards, gui_num, opCards)) + { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + + wChiHuKind.add(WinCardType.SHI_SHAN_YAO); + putWinCardType(map, WinCardType.SHI_SHAN_YAO, 1, WinCardType.SHI_SHAN_YAO_SCORE, true, "十三幺"); + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(hand_cards, gui_num, opCards)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + } + } + + //胡牌分析 + for (int i = 0; i < tagAnalyseItemList.size(); i++) { + HashMap map = new HashMap(); + tempLaiziMapList.add(map); + //变量定义 + int lianCardNum = 0; + int pengCardNum = 0; + int lianOrPengNum = 0; + TagAnalyseItem pAnalyseItem = tagAnalyseItemList.get(i); + + //牌型分析 + for (int j = 0; j < pAnalyseItem.cbOpCard.size(); j++) { + OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j); + if (cbWeaveKind.type == RuleWeight.TYPE_PONG + || cbWeaveKind.type == RuleWeight.TYPE_KONG + || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG + || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) { + if (cbWeaveKind.card == 0) + { + lianOrPengNum++; + } + else if (cbWeaveKind.card != 0 && cbWeaveKind.card2 == 0 && cbWeaveKind.card3 == 0) + { + lianOrPengNum++; + } + else { + pengCardNum++; + } + } + + if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) { + lianCardNum++; + } + } + + //特殊--碰碰胡 + if (pengCardNum + lianOrPengNum == 4) { + if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) { + wChiHuKind.add(WinCardType.PENGPENGHU); + putWinCardType(map, WinCardType.PENGPENGHU, 1, WinCardType.PENGPENGHU_SCORE, true, "碰碰胡"); + } else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + } + else if (lianCardNum + lianOrPengNum == 4) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) { + wChiHuKind.add(WinCardType.PINGHU); + putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡"); + } else { + wChiHuKind.add(WinCardType.JIHU); + putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_YAO_JIU)) { + if (config.getBoolean(Config.ROOM_CONFIG_han19)) { + if (IsHuYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "混幺九"); + } + } else { + if (IsQingYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "清幺九"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QING_YAO_JIU)) { + if (IsQingYaoJiu(pAnalyseItem)) { + wChiHuKind.add(WinCardType.YAO_JIU); + putWinCardType(map, WinCardType.QING_YAO_JIU, 1, WinCardType.QING_YAO_JIU_SCORE, true, "清幺九"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG)) { + if (IsQuanFeng(pAnalyseItem)) { + wChiHuKind.add(WinCardType.QUAN_FENG); + putWinCardType(map, WinCardType.QUAN_FENG, 1, WinCardType.QUAN_FENG_SCORE, true, "全风"); + } + } + + boolean qing_se = false; + if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE)) + { + if (IsQingYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.QINGYISE); + putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色"); + qing_se = true; + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE)) + { + if (IsZiYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.ZI_YI_SE); + putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色"); + qing_se = true; + } + } + + if (!qing_se) + { + if (config.getBoolean(Config.ROOM_CONFIG_HUNYISE)) + { + if (IsHunYiSe(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.HUN_YI_SE); + putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色"); + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN) || config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + int sanyuan = IsDaXiaoSanYuan(pAnalyseItem); + if (sanyuan > 0) + { + //大三元 + if (sanyuan == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN)) + { + wChiHuKind.add(WinCardType.DA_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SHAN_YUAN, 1, WinCardType.DA_SHAN_YUAN_SCORE, true, "大三元"); + } + } + //小山元 + else if (sanyuan == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SHAN_YUAN, 1, WinCardType.XIAO_SHAN_YUAN_SCORE, true, "小三元"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI) || config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + int sixi = IsDaXiaoSiXi(pAnalyseItem); + if (sixi > 0) + { + //大四喜 + if (sixi == 1) + { + if (config.getBoolean(Config.ROOM_CONFIG_DASIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.DA_SI_XI, 1, WinCardType.DA_SI_XI_SCORE, true, "大四喜"); + } + } + //小四喜 + else if (sixi == 2) + { + if (config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI)) + { + wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN); + putWinCardType(map, WinCardType.XIAO_SI_XI, 1, WinCardType.XIAO_SI_XI_SCORE, true, "小四喜"); + } + } + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_SHIBALUOHAN)) + { + if (IsShiBaLuoHan(pAnalyseItem)) + { + wChiHuKind.add(WinCardType.SHI_BA_LUO_HAN); + putWinCardType(map, WinCardType.SHI_BA_LUO_HAN, 1, WinCardType.SHI_BA_LUO_HAN_SCORE, true, "十八罗汉"); + } + } + + if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE)) + { + if (QuanQiuRen(opCards)) + { + wChiHuKind.add(WinCardType.QUAN_QIU_REN); + putWinCardType(map, WinCardType.QUAN_QIU_REN, 1, WinCardType.QUAN_QIU_REN_SCORE, true, "全求人"); + } + } + } + + if (tempLaiziMapList.size() > 0) + { + int maxValue = 0; + int maxIndex = 0; + for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++) + { + Map tempLaiziMap = tempLaiziMapList.get(i_i); + int value = 0; + for (Map.Entry entry : tempLaiziMap.entrySet()) { + WinCardType cardType = entry.getValue(); + value += cardType.score; + } + if (value > maxValue) + { + maxValue = value; + maxIndex = i_i; + } + } + + Map tempLaiziMap = tempLaiziMapList.get(maxIndex); + curMap.putAll(tempLaiziMap); + return true; + } + return false; + } + + public static boolean get_hu_info(int[] hand_cards, int gui_num, List opCards, List tagAnalyseItemList) { + int[] cards = new int[34]; + System.arraycopy(hand_cards, 0, cards, 0, 34); + + int[] eye_tbl = new int[34]; + int eye_num = 0; + int empty = -1; + for (int i = 0; i < 34; ++i) { + // 优化手段,三不靠的牌,必做将 + int min = (i / 9) * 9; + int max = min + 8; + if (max == 35) max = 33; + if (cards[i] == 1 && + (i - 2 < min || cards[i - 2] == 0) && + (i - 1 < min || cards[i - 1] == 0) && + (i + 1 > max || cards[i + 1] == 0) && + (i + 2 > max || cards[i + 2] == 0)) { + if (gui_num < 0) { + return false; + } + eye_num = 1; + eye_tbl[0] = i; + empty = -1; + break; + } + if (empty == -1 && cards[i] == 0) empty = i; + if (cards[i] > 0 && cards[i] + gui_num >= 2) { + eye_tbl[eye_num++] = i; + } + } + if (empty > 0) { + eye_tbl[eye_num++] = empty; + } + + boolean hu = false; + int[] cache = {0, 0, 0, 0}; + TagAnalyseItem[] cache_item = {null, null, null, null}; + for (int i = 0; i < eye_num; i++) { + int eye = eye_tbl[i]; + if (eye == empty) { + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = 0; + tagItem.cbCardEye2 = 0; + hu = foreach_eye(cards, gui_num - 2, gui_num, 1000, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 2); + } + tagAnalyseItemList.add(tagItem); + } + } else { + int n = cards[eye]; + if (n == 1) { + cards[eye] = 0; + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = SwitchToCardData(eye); + tagItem.cbCardEye2 = 0; + hu = foreach_eye(cards, gui_num - 1, gui_num, eye / 9, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 1); + } + tagAnalyseItemList.add(tagItem); + } + } else { + cards[eye] -= 2; + TagAnalyseItem tagItem = new TagAnalyseItem(); + tagItem.cbCardEye = SwitchToCardData(eye); + tagItem.cbCardEye2 = SwitchToCardData(eye); + hu = foreach_eye(cards, gui_num, gui_num, eye / 9, cache, tagItem, cache_item); + if (hu) + { + //设置结果 + boolean isPengPengHu = true; + for (int j = 0; j < opCards.size(); j++) + { + OpCard src_card = opCards.get(j); + if (src_card.type == RuleWeight.TYPE_CHOW) + { + isPengPengHu = false; + } + OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card); + tagItem.cbOpCard.add(op_card); + } + if (isPengPengHu) + { + tagItem.isPengPengHu = isPengPengHu(cards, gui_num); + } + tagAnalyseItemList.add(tagItem); + } + } + cards[eye] = n; + } + } + + return tagAnalyseItemList.size() > 0; + } + + public static boolean isPengPengHu(int[] cards, int gui_num) + { + int need_gui = 0; + for(int i = 0; i < cards.length; i++) + { + int num = cards[i]; + if (num > 0) + { + if (num == 1) + { + need_gui += 2; + } + else if (num == 2) + { + need_gui++; + } + else if (num == 3) + { + + } + else if (num == 4) + { + return false; + } + } + } + + if (need_gui > gui_num) + { + return false; + } + + if ((gui_num - need_gui) % 3 == 0) + { + return true; + } + + return false; + } + + public static boolean foreach_eye(int[] cards, int gui_num, int max_gui, int eye_color, int[] cache, TagAnalyseItem item, TagAnalyseItem[] cacheItemList) { + int left_gui = gui_num; + for (int i = 0; i < 3; i++) { + int cache_index = -1; + if (eye_color != i) cache_index = i; + TagAnalyseItem cache_item = new TagAnalyseItem(); + int need_gui = check_normal(cards, i * 9, i * 9 + 8, max_gui, cache_index, cache, i, item, cacheItemList, cache_item); + if (cache_index > 0) { + cache[i] = need_gui + 1; + cacheItemList[i] = cache_item; + } + left_gui -= need_gui; + if (left_gui < 0) { + return false; + } + } + + int cache_index = -1; + if (eye_color != 3) cache_index = 3; + TagAnalyseItem cache_item = new TagAnalyseItem(); + int need_gui = check_zi(cards, max_gui, cache_index, cache, 3, item, cacheItemList, cache_item); + if (cache_index > 0) { + cache[3] = need_gui + 1; + cacheItemList[3] = cache_item; + } + for(int i = 1; i <= 4; i++) + { + if (left_gui - 3*i == need_gui) + { + for(int j = 0; j < i; j++) { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, 0, 0, 0); + item.cbOpCard.add(op_card); + } + } + } + + return left_gui >= need_gui; + } + + public static int check_normal(int[] cards, int from, int to, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) { + if (cache_index >= 0) { + int n = cache[cache_index]; + if (n > 0) { + TagAnalyseItem old_item = cacheItemList[cache_index]; + if (old_item != null) + { + for(int i = 0; i < old_item.cbOpCard.size(); i++) + { + OpCard op_card = old_item.cbOpCard.get(i); + item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3)); + + + OpCard cache_card = old_item.cbOpCard.get(i); + cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3)); + } + } + return n - 1; + } + } + + int n = 0; + for (int i = from; i <= to; i++) { + n = n * 10 + cards[i]; + } + + if (n == 0) return 0; + + boolean n3 = false; + for (int i = 0; i <= max_gui; i++) { + if ((n + i) % 3 == 0) { + n3 = true; + break; + } + } + + if (!n3) { + return max_gui + 1; + } + + return next_split(n, 0, max_gui, eye_color, item, cacheItemList, cache_item, 0); + } + + public static int next_split(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c = 0; + while (true) { + if (n == 0) return need_gui; + + while (n > 0) { + c = n % 10; + n = n / 10; + cur_index++; + if (c != 0) break; + } + if (c == 1 || c == 4) { + if (c == 4) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + cache_item.cbOpCard.add(cache_card); + } + return one(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } else if (c == 2) { + return two(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + else { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1)); + cache_item.cbOpCard.add(cache_card); + } + } + } + + public static int one(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c1 = n % 10; + int c2 = (n % 100) / 10; + + OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + if (c1 == 0) + { + op_card.card2 = 0; + cache_card.card2 = 0; + ++need_gui; + } + else { + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + n -= 1; + } + + if (c2 == 0) { + op_card.card3 = 0; + cache_card.card3 = 0; + ++need_gui; + } + else { + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + n -= 10; + } + + if (op_card.card2 == 0 && op_card.card3 == 0) + { + op_card.type = RuleWeight.TYPE_PONG; + cache_card.type = RuleWeight.TYPE_PONG; + } + + item.cbOpCard.add(op_card); + cache_item.cbOpCard.add(cache_card); + + if (n == 0) return need_gui; + + if (need_gui > max_gui) return need_gui; + + return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + + public static int two(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) { + int c1 = n % 10; + int c2 = (n % 100) / 10; + int c3 = (n % 1000) / 100; + int c4 = (n % 10000) / 1000; + + boolean choose_ke = true; + if (c1 != 0) { + if (c1 == 1) { + // 刻子 + if (c2 != 0 && c2 != 1) { + if (c2 == 2) { + if (c3 == 2) { + if (c4 == 2) choose_ke = false; + } else if (c3 == 3) { + if (c4 != 2) choose_ke = false; + } else { + choose_ke = false; + } + } else if (c2 == 3) { + if (c3 != 3) { + choose_ke = false; + } + } else if (c2 == 4) { + if (c3 == 2) { + if (c4 == 2 || c4 == 3 || c4 == 4) choose_ke = false; + } + if (c3 == 3) { + choose_ke = false; + } + } + } + } else if (c1 == 2) { + choose_ke = false; + } else if (c1 == 3) { + if (c2 == 2) { + if (c3 == 1 || c3 == 4) { + choose_ke = false; + } else if (c3 == 2) { + if (c4 != 2) choose_ke = false; + } + } + if (c2 == 3) { + choose_ke = false; + } else if (c2 == 4) { + if (c3 == 2) { + choose_ke = false; + } + } + } else if (c1 == 4) { + if (c2 == 2 && c3 != 2) { + choose_ke = false; + } else if (c2 == 3) { + if (c3 == 0 || c3 == 1 || c3 == 2) { + choose_ke = false; + } + } else if (c2 == 4) { + if (c3 == 2) choose_ke = false; + } + } + } // c1 == 0 全拆刻子 + + + if (choose_ke) { + need_gui += 1; + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0); + cache_item.cbOpCard.add(cache_card); + } else { + OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard op_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + OpCard cache_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1)); + + if (c1 < 2) { + need_gui += (2 - c1); + n -= c1; + if (c1 == 0) + { + op_card.card2 = 0; + op_card2.card2 = 0; + + cache_card.card2 = 0; + cache_card2.card2 = 0; + } + else if (c1 == 1) + { + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + op_card2.card2 = 0; + + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card2.card2 = 0; + } + } else { + n -= 2; + op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + op_card2.card2 = (eye_color+1)*100+(9-cur_index+1-1); + + cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1); + cache_card2.card2 = (eye_color+1)*100+(9-cur_index+1-1); + } + + if (c2 < 2) { + need_gui += (2 - c2); + n -= c2 * 10; + if (c2 == 0) + { + op_card.card3 = 0; + op_card2.card3 = 0; + + cache_card.card3 = 0; + cache_card2.card3 = 0; + } + else if (c2 == 1) + { + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + op_card2.card3 = 0; + + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card2.card3 = 0; + } + } else { + n -= 20; + op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + op_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2); + + cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2); + cache_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2); + } + + item.cbOpCard.add(op_card); + item.cbOpCard.add(op_card2); + + cache_item.cbOpCard.add(cache_card); + cache_item.cbOpCard.add(cache_card2); + } + + if (n == 0) return need_gui; + + if (need_gui > max_gui) return need_gui; + + return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index); + } + + public static int check_zi(int[] cards, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) { + if (cache_index >= 0) { + int n = cache[cache_index]; + if (n > 0) { + TagAnalyseItem old_item = cacheItemList[cache_index]; + if (old_item != null) + { + for(int i = 0; i < old_item.cbOpCard.size(); i++) + { + OpCard op_card = old_item.cbOpCard.get(i); + item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3)); + + OpCard cache_card = old_item.cbOpCard.get(i); + cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3)); + } + } + return n - 1; + } + } + + int need_gui = 0; + for (int i = 27; i < 34; i++) { + int c = cards[i]; + if (c == 0) continue; + if (c == 1 || c == 4) { + if (c == 1) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + cache_item.cbOpCard.add(cache_card); + } + else if (c == 4) + { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card); + OpCard op_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0); + item.cbOpCard.add(op_card2); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card); + OpCard cache_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card2); + } + need_gui = need_gui + 2; + } else if (c == 2) { + need_gui = need_gui + 1; + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0); + cache_item.cbOpCard.add(cache_card); + } + else { + OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + item.cbOpCard.add(op_card); + + OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i)); + cache_item.cbOpCard.add(cache_card); + } + if (need_gui > max_gui) return need_gui; + } + + return need_gui; + } +} diff --git a/game_mj_yijiaolaiyou/src/test/java/game_mj_yijiaolaiyou/Main.java b/game_mj_yijiaolaiyou/src/test/java/game_mj_yijiaolaiyou/Main.java new file mode 100644 index 0000000..525ce5e --- /dev/null +++ b/game_mj_yijiaolaiyou/src/test/java/game_mj_yijiaolaiyou/Main.java @@ -0,0 +1,9 @@ +package game_mj_yijiaolaiyou; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_mj_zhuanzhuan/config/game-config.xml b/game_mj_zhuanzhuan/config/game-config.xml new file mode 100644 index 0000000..bf8340c --- /dev/null +++ b/game_mj_zhuanzhuan/config/game-config.xml @@ -0,0 +1,11 @@ + + + + + 192.168.3.10 + 192.168.3.10 + 8981 + 8981 + 108 + true + \ No newline at end of file diff --git a/game_mj_zhuanzhuan/config/log4j.properties b/game_mj_zhuanzhuan/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_mj_zhuanzhuan/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_mj_zhuanzhuan/config/taurus-core.xml b/game_mj_zhuanzhuan/config/taurus-core.xml new file mode 100644 index 0000000..f1fc76a --- /dev/null +++ b/game_mj_zhuanzhuan/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_mj_zhuanzhuan/config/taurus-permanent.xml b/game_mj_zhuanzhuan/config/taurus-permanent.xml new file mode 100644 index 0000000..7d9ade7 --- /dev/null +++ b/game_mj_zhuanzhuan/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 2 + 1 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - test + extend.mj.EXMainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_mj_zhuanzhuan/pom.xml b/game_mj_zhuanzhuan/pom.xml new file mode 100644 index 0000000..4585b3e --- /dev/null +++ b/game_mj_zhuanzhuan/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_mj_zhuanzhuan + 1.0.0 + jar + + game_mj_zhuanzhuan + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_mj_zhuanzhuan + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/CardNiao.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/CardNiao.java new file mode 100644 index 0000000..a21039b --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/CardNiao.java @@ -0,0 +1,19 @@ +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("score", score); + return obj; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/Config.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/Config.java new file mode 100644 index 0000000..59380e6 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/Config.java @@ -0,0 +1,119 @@ +package extend.mj; + +public class Config { + + public static final int HONGZHONG = 412; + public static final int XIPAI_SCORE = 10; + + public static final String ROOM_CONFIG_DIANPAO = "dianpao"; + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuangxian"; + public static final String ROOM_CONFIG_FENGDING = "fengding"; + public static final String ROOM_CONFIG_FENGDING_SCORE = "fengding_score"; + public static final String ROOM_CONFIG_PIAO_NIAO = "piao_niao"; + public static final String ROOM_CONFIG_QIDUI = "qidui"; + public static final String ROOM_CONFIG_NIAO = "niao"; + public static final String ROOM_CONFIG_NIAO_OPT = "niao_opt"; + public static final String ROOM_CONFIG_NIAO_OPT_SCORE = "niao_opt_score"; + public static final String ROOM_CONFIG_HONGZHONG = "laizi"; + public static final String ROOM_CONFIG_WUGUI_JIABEI = "wuguijiabei"; + public static final String ROOM_CONFIG_QIANGKONG = "qiangkong"; + public static final String ROOM_CONFIG_QIANGKONG_NIAO = "qiangkong_niao"; + public static final String ROOM_CONFIG_HONGZHONG8 = "laizi8"; + public static final String ROOM_CONFIG_NONEALL = "none_is_all"; + public static final String ROOM_CONFIG_NIAO_SCORE = "niao_score"; + public static final String ROOM_CONFIG_QG_TYPE = "qianggang_type"; + public static final String ROOM_CONFIG_JIANGMA = "jiangma"; + public static final String ROOM_CONFIG_HZ_HU = "hz_hu"; + 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_DI_FEN = "di_fen"; //低分 + public static final String ROOM_CONFIG_LAIZI4_HU = "laizi4_hu"; //四鬼胡牌 + public static final String ROOM_CONFIG_QIANGGANG_DIANPAO = "qianggang_dianpao"; //抢杠算点炮 + public static final String ROOM_CONFIG_BI_HU = "bi_hu"; //必胡 + + public static final String SETTLE_DIAN_PAO = "dian_pao"; + public static final String SETTLE_JIE_PAO = "jie_pao"; + public static final String SETTLE_ZIMO = "zimo"; + public static final String SETTLE_AN_KONG = "an_kong"; + public static final String SETTLE_MING_KONG = "ming_kong"; + + public static final int NIAO_TYPE_159 =1; + public static final int NIAO_TYPE_ALL =2; + public static final int NIAO_TYPE_WOWO =3; + + /** + * + */ + 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_PIAONIAO_TIP = "833"; + /** + * + */ + public static final String GAME_EVT_PIAONIAO = "834"; + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXActionEvent.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXActionEvent.java new file mode 100644 index 0000000..db9bbf0 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXActionEvent.java @@ -0,0 +1,18 @@ +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_PIAO_NIAO = "piao_niao"; +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXGameController.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXGameController.java new file mode 100644 index 0000000..0342a48 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXGameController.java @@ -0,0 +1,272 @@ +package extend.mj; + +import java.util.Collections; +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; + +/** + * + * + * + * EXGameController.java + */ +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.weight+" 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; + TObject 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+"]"); + } + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcardArray){ + 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); + } + EXRoom room = player.getRoom(); + + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d ", player,from_seat,card,type)); + } + room.broadCastToClient(0, Config.GAME_EVT_ACTION, paramBroadCast); + ((EXPlayBack)room.playBackData).addActionCommand(player.seat, type, card, from_seat,opcardArray); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.cardInhand = owner.card.deal(); + Collections.sort(player.cardInhand); + if(Global.loggerDebug) { + Global.logger.info(player + " cardlist:" + player.cardInhand); + } + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + 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(); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + public void winEvent(EXPlayer owner,int from_seat,int win_card) { + 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("win_card", win_card); + param.putInt("from_seat", from_seat); + if(Global.loggerDebug) { + Global.logger.info(owner + " hupai!["+(owner.seat == from_seat?"self":"other")+"]"); + } + 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 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); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("xipai_score", owner.xi_pai_score); + 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 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("hu_score", player.score.round_log.get(EXScore.WIN)); + param.putInt("niao_score", player.score.round_log.get(EXScore.NIAO)); + param.putInt("gang_score", player.score.round_log.get(EXScore.KONG)); + param.putInt("piao_niao_score", player.score.round_log.get(EXScore.PIAO_NIAO)); + player.hp_info(param); + 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); + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + 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); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.playBackData.addResult(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXMainServer.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXMainServer.java new file mode 100644 index 0000000..1e98ee6 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXMainServer.java @@ -0,0 +1,98 @@ +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.PROtherKongState; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.player.rulestate.PRSelfKongState; +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.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.player.state.EXPlayerWaitState; +import extend.mj.room.state.EXRoomDealState; +import extend.mj.room.state.EXRoomSetpState; +import extend.mj.room.state.EXRoomStartGameState; + +/** + * + * + * EXMainServer.java + */ +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(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + 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()); + + + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayBack.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayBack.java new file mode 100644 index 0000000..ff097fc --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayBack.java @@ -0,0 +1,74 @@ +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 addResultData(ITObject resultData){ + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "Result"); + cmdObj.putTObject("data", resultData); + cmdList.addTObject(cmdObj); + } + 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){ + 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); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayer.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayer.java new file mode 100644 index 0000000..3023de5 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXPlayer.java @@ -0,0 +1,142 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +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; + +/** + * + * + * + * 2017��8��30�� + * EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + + // ������ + public List outcardList; + + public ITArray opCard; + + public List pongGroup; + public List kongGroup; + public List selfKongGroup; + public List opCardList; + + public int drawCard = 0; + public int winCard = 0; + + public TipManager tipMgr; + + public SettleLog settleLog; + + /** + * ©�� + */ + public boolean louhu = false; + + /** + * ǿ�Ƽ����� + */ + public boolean forceCheckWin = false; + /** + * 0 С�� 1 ���ܺ� + */ + public int winType = 0; + public List notPongKongList = new ArrayList<>(); + + public int niaoCount; + public int piaoNiao; + public boolean fengding; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + + pongGroup = new ArrayList<>(); + kongGroup = new ArrayList<>(); + selfKongGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + + opCard = new TArray(); + + tipMgr = new TipManager(this); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_DIAN_PAO, 0); + settleLog.put(Config.SETTLE_JIE_PAO, 0); + settleLog.put(Config.SETTLE_ZIMO, 0); + settleLog.put(Config.SETTLE_AN_KONG, 0); + settleLog.put(Config.SETTLE_MING_KONG, 0); + fengding = false; + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(self); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", cardInhand.size()); + playerData.putInt("score", score.total_score); + playerData.putInt("piao_niao", this.piaoNiao); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card", opcard.card); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + + return playerData; + } + + public void clear() { + super.clear(); + this.cardInhand.clear(); + this.notPongKongList.clear(); + this.winer = 0; + this.louhu = false; + this.outcardList.clear(); + this.drawCard = 0; + this.kongGroup.clear(); + this.pongGroup.clear(); + this.selfKongGroup.clear(); + this.opCardList.clear(); + this.score.resetRound(); + this.niaoCount = 0; + this.piaoNiao = 0; + this.fengding = false; + } + + + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXRoom.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXRoom.java new file mode 100644 index 0000000..c14f828 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXRoom.java @@ -0,0 +1,708 @@ +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.player.state.EXPlayerDisCardTipState; +import extend.mj.tip.Action; +import extend.mj.tip.TipManager; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winCount = 0; + public boolean liuju = false; + + public ArrayList niao; + + public int niao_score; + public int piaoNiaoCount; + public int adminSeat = 0; + + public int di_fen = 2; + public int niao_fen = 2; + + public int fengdingScore = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.niao = new ArrayList(); + this.fengdingScore = 0; + + 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.putBoolean(Config.ROOM_CONFIG_PIAO_NIAO, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_JIABEI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU)) + { + this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT_SCORE)) + { + this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE, 1); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_NIAO)) { + this.config.putInt(Config.ROOM_CONFIG_NIAO, 0); + } + if(!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT)) { + this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT, 0); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_JIANGMA)) { + this.config.putInt(Config.ROOM_CONFIG_JIANGMA, 0); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG)) { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_HONGZHONG8)) { + this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG8,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) { + this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_NIAO)) { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO,false); + } + + //this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, true); + //this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG, false); + this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false); + //this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false); + this.config.putInt(Config.ROOM_CONFIG_QG_TYPE, 0); //no use + this.config.putInt(Config.ROOM_CONFIG_NIAO_SCORE, 0); //no use + if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false); + } + this.niao_score = 2; + if(this.config.getInt(Config.ROOM_CONFIG_NIAO) > 0) { + int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE); + if(opt==2)this.niao_score = 1; + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_QIANGGANG_DIANPAO)) { + this.config.putBoolean(Config.ROOM_CONFIG_QIANGGANG_DIANPAO,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_BI_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_BI_HU,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_HONGZHONG)) { + this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_DIANPAO)) { + this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO,false); + } + + if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) { + this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false); + } + + 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_QIDUI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_QIDUI, false); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_DI_FEN)) + { + this.config.putInt(Config.ROOM_CONFIG_DI_FEN, 0); + this.di_fen = 2; + } + else { + int di_index = this.config.getInt(Config.ROOM_CONFIG_DI_FEN); + if (di_index == 0) + { + this.di_fen = 2; + } + else if (di_index == 1) + { + this.di_fen = 4; + } + else if (di_index == 2) + { + this.di_fen = 6; + } + else if (di_index == 3) + { + this.di_fen = 8; + } + } + + // this.entrustTime = this.config.getInt("tuoguan_active_time") * 60000; + // this.openEntrust = this.entrustTime > 0; + // this.entrusResultType = this.config.getInt("tuoguan_result_type"); + this.isEntrust=true; + this.adminSeat = 0; + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + + for (Entry 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); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN); + if(type == EXScore.WIN) { + if (zhuangxian) { + if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) { + score += 1; + } + } + + EXScore exscore = (EXScore) destPlayer.score; + EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer); + if (hu_score == null) { + hu_score = new EXScore.HUScore(); + hu_score.player = fromPlayer; + exscore.hu_score.add(hu_score); + } + + hu_score.score += score; + } + else if (type == EXScore.NIAO) + { + EXScore exscore = (EXScore) destPlayer.score; + EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer); + if (hu_score == null) { + hu_score = new EXScore.HUScore(); + hu_score.player = fromPlayer; + exscore.hu_score.add(hu_score); + } + + hu_score.niao_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 addAllScore(EXPlayer destPlayer, int socre, int type) { + for (Entry 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) { + this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO); + } + + public void addAllNiaoScore(EXPlayer destPlayer, int score) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.niaoCount ++; + addNiaoScore(destPlayer, fromPlayer, score); + } + } + + public void addPiaoNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer) { + boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if (piao_niao == false) return; + + this.addScore(destPlayer, fromPlayer,destPlayer.piaoNiao + fromPlayer.piaoNiao , EXScore.PIAO_NIAO); + } + + public void addAllPiaoNiaoScore(EXPlayer destPlayer) { + boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if (piao_niao == false) return; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + addPiaoNiaoScore(destPlayer,fromPlayer); + } + } + + private int getNiaoNum(int card, boolean isDianPao) { + int niao_num = 0; + int niao = this.config.getInt(Config.ROOM_CONFIG_NIAO); + switch (niao) { + case Config.NIAO_TYPE_159: + + int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT); + niao_num = opt * 2; + + break; + case Config.NIAO_TYPE_ALL: + niao_num = 1; + break; + case Config.NIAO_TYPE_WOWO: + int tem = card % 100; + niao_num = (card == Config.HONGZHONG) ? 10 : tem; + break; + } + return niao_num; + } + + public void niao_tongPao(int card) { + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + __zhuaNiao(dianPaoPlayer, getNiaoNum(card, false)); + List winPlayerList = new ArrayList(); + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (player.winer == 1) { + ((EXPlayer)player).niaoCount = 0; + winPlayerList.add((EXPlayer) player); + } + } + for (CardNiao cn : niao) { + boolean not_niao = true; + if (dianPaoPlayer.playerid == cn.playerId) { + for (EXPlayer winer : winPlayerList) { + int score = cn.score; + if(Global.gameId != 1&&winer.winType == 1) + score = score * (maxPlayers - 1); + winer.niaoCount ++; + this.addNiaoScore(winer, dianPaoPlayer, score); + } + not_niao = false; + } else { + for (EXPlayer winer : winPlayerList) { + if (winer.playerid == cn.playerId) { + int score = cn.score; + if (Global.gameId != 1&&winer.winType == 1) + score = score * (maxPlayers - 1); + this.addNiaoScore(winer, dianPaoPlayer, score); + not_niao = false; + winer.niaoCount ++; + break; + } + } + } + if (not_niao) + cn.score = 0; + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + for (EXPlayer winer : winPlayerList) { + if(winer.niaoCount == 6 ||winer.niaoCount == 0) { + this.addNiaoScore(winer, dianPaoPlayer, niao_score*6); + } + } + } + + EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat); + } + + public void niao_dianPao(EXPlayer owner, int card) { +// boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); +// if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { +// if (owner.winType != 1 && Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) { +// return; +// } +// } + EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat); + EXPlayer winer = owner; + int num = getNiaoNum(card, true); + boolean hongzhong = Util.checkCard(Config.HONGZHONG, owner.cardInhand); + int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA); + if(card!=Config.HONGZHONG&&!hongzhong&&jm_num>0) { + num +=jm_num; + } + __zhuaNiao(winer, num); + winer.niaoCount = 0; + for (CardNiao cn : niao) { + if (cn.playerId == winer.playerid || dianPaoPlayer.playerid == cn.playerId) { + int score = cn.score; + if(Global.gameId != 1&&owner.winType == 1) + score = score * (maxPlayers - 1); + winer.niaoCount ++; + this.addNiaoScore(winer, dianPaoPlayer, score); + } else { + cn.score = 0; + } + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + if(winer.niaoCount == 6 ||winer.niaoCount == 0) { + this.addNiaoScore(winer, dianPaoPlayer, niao_score*6); + } + } + EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat); + } + + public void niao_selfWin(EXPlayer owner, int card) { + if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) { + return; + } + int num = getNiaoNum(card, false); + boolean hongzhong = Util.checkCard(Config.HONGZHONG, owner.cardInhand); + int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA); + if(card!=Config.HONGZHONG&&!hongzhong&&jm_num>0) { + num +=jm_num; + } + __zhuaNiao(owner, num); + for (Entry entry : owner.room.playerMapById.entrySet()) { + ((EXPlayer)entry.getValue()).niaoCount = 0; + } + boolean jiabei = false; +// boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); +// if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) { +// if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) { +// jiabei = true; +// } +// } + for (CardNiao cn : niao) { + boolean not_niao = true; + if (cn.playerId == owner.playerid) { + if (jiabei) + { + this.addAllNiaoScore(owner, cn.score * 2); + } + else { + this.addAllNiaoScore(owner, cn.score); + } + not_niao = false; + } else { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid == cn.playerId) { + player.niaoCount ++; + if (jiabei) + { + this.addNiaoScore(owner, player, cn.score * 2); + } + else { + this.addNiaoScore(owner, player, cn.score); + } + not_niao = false; + break; + } + } + } + if (not_niao) + cn.score = 0; + } + boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL); + if(none_all) { + for (Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.niaoCount == 6 ||player.niaoCount == 0) { + if (jiabei) + { + this.addNiaoScore(owner, player, niao_score*6*2); + } + else { + this.addNiaoScore(owner, player, niao_score*6); + } + } + } + } +// for (OpCard opcard : owner.opCardList) { +// if (opcard.type == RuleWeight.TYPE_SELF_KONG) +// { +// this.addAllScore(owner, 3, EXScore.KONG); +// } +// else if (opcard.type == RuleWeight.TYPE_KONG && opcard.seat == 0) +// { +// this.addAllScore(owner, 3, EXScore.KONG); +// } +// else if (opcard.type == RuleWeight.TYPE_KONG && opcard.seat > 0) +// { +// EXPlayer activePlayer = (EXPlayer)this.playerMapBySeat.get(opcard.seat); +// if (activePlayer != null) +// { +// this.addScore(owner,activePlayer, 3,EXScore.KONG); +// } +// } +// } + EXMainServer.gameCtr.sendNiaoEvt(owner, owner.seat); + } + + private final void __zhuaNiao(EXPlayer owner, int niao_num) { + this.niao.clear(); + + boolean niao_all = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL; + for (int index = 0; index < niao_num; index++) { + if (card.cardList.size() == 0) { + break; + } + + int card = this.card.pop(); + CardNiao cn = new CardNiao(); + cn.card = card; + this.niao.add(cn); + int tem = card % 100; + if (niao_all) { + cn.playerId = owner.playerid; + if (card == Config.HONGZHONG || (Global.gameId == 1 &&tem == 1)) { + cn.score = 10; + } else { + cn.score = tem; + } + } else { + if (card == Config.HONGZHONG || tem == 1 || tem == 5 || tem == 9) { + cn.playerId = owner.playerid; + cn.score = niao_score; + } + } + } + + } + + public void winCallback(EXPlayer owner, int card) { + if (this.winCount >= this.actionList.size()) { + if (actionList.size() > 1) { + this.bankerSeat = this.activeSeat; + niao_tongPao(card); + } else { + niao_dianPao(owner, card); + } + + this.endGame(); + } + } + + @Override + public void endGame() { + boolean fengding = this.config.getBoolean(Config.ROOM_CONFIG_FENGDING); + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) { + List list = ((EXScore) player.score).hu_score; + for (EXScore.HUScore hu_score : list) { + int hu_num = hu_score.score; + int niao_num = hu_score.niao_score; + 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; + } + } + } + ((EXPlayBack)this.playBackData).addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.endGame(); + } + +// public void settleRound() { +// saveMilitaryRound(playBackData.getData()); +// boolean total = this.round >= this.maxRound; +// if(this.entrusResultType ==EXRoom.ENTRUST_CURREN_RESULT) { +// for (Entry entry : this.playerMapById.entrySet()) { +// if(entry.getValue().isEntrust()) { +// total = true; +// break; +// } +// } +// } +// if (!total) +// EXMainServer.gameCtr.roomResult(this); +// else { +// this.saveMilitaryTotal(false); +// } +// this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); +// this.winCount = 0; +// +// +// if (total) { +// this.stateMachine.changeState(Global.getState(RoomDestoryGameState.class)); +// return; +// } +// } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.winCount = this.piaoNiaoCount = 0; + this.niao.clear(); + this.niao_fen = 2; + this.di_fen = 2; + this.fengdingScore = 0; + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/EXScore.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXScore.java new file mode 100644 index 0000000..1e7631c --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/EXScore.java @@ -0,0 +1,45 @@ +package extend.mj; + +import com.game.data.Score; + +import java.util.ArrayList; +import java.util.List; + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int KONG = 2; + public static final int NIAO = 3; + public static final int PIAO_NIAO = 4; + + public List hu_score; + + public EXScore(EXPlayer owner){ + super(owner); + this.hu_score = new ArrayList<>(); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(KONG, 0); + this.round_log.put(NIAO, 0); + this.round_log.put(PIAO_NIAO, 0); + if(this.hu_score!=null) + this.hu_score.clear(); + } + + public HUScore getHuScore(EXPlayer from){ + for(HUScore hu_score : hu_score){ + if(hu_score.player.playerid == from.playerid){ + return hu_score; + } + } + return null; + } + + + public static final class HUScore{ + public int score; + public EXPlayer player; + public int niao_score; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/OpCard.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/OpCard.java new file mode 100644 index 0000000..32f8334 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/OpCard.java @@ -0,0 +1,19 @@ +package extend.mj; + +public class OpCard { + public int type; + public int card; + public int seat; + + public OpCard(int type, int card) { + this.type = type; + this.card = card; + this.seat = 0; + } + + public OpCard(int type, int card, int seat) { + this.type = type; + this.card = card; + this.seat = seat; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/PlayerRuleManager.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/PlayerRuleManager.java new file mode 100644 index 0000000..f935748 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/PlayerRuleManager.java @@ -0,0 +1,103 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.mj.player.rule.RuleOtherKong; +import extend.mj.player.rule.RuleOtherWin; +import extend.mj.player.rule.RulePong; +import extend.mj.player.rule.RulePongKong; +import extend.mj.player.rule.RuleSelfKong; +import extend.mj.player.rule.RuleSelfWin; +import extend.mj.player.state.EXPlayerDisCardTipState; +import extend.mj.player.state.EXPlayerDrawTipState; +import extend.mj.player.state.EXPlayerKongWinState; +import extend.mj.player.state.EXPlayerTipState; +import extend.mj.tip.IRuleBase; + +/** + * ����������� + * + * + * + * 2017��9��19�� PlayerRuleManager.java + */ +public class PlayerRuleManager { + + /** + * ����ץ�� + */ + public static final int DRAW_RULE = 1; + /** + * ���˳��� + */ + public static final int OTHER_DISCARD_RULE = 2; + /** + * ���ܺ����� + */ + public static final int KONG_HU_RULE = 3; + /** + * �������Ժ���ƹ��� + */ + public static final int CHOW_PONG_DISCARD_RULE = 7; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.KONG_HU_RULE, (EXPlayerKongWinState) Global.getState(EXPlayerKongWinState.class)); + tipMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, (EXPlayerDrawTipState) Global.getState(EXPlayerDrawTipState.class)); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleSelfKong()); + drawRuleList.add(new RulePongKong()); + drawRuleList.add(new RuleSelfWin()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleOtherKong()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List konghuList = new ArrayList(); + konghuList.add(new RuleOtherWin()); + ruleMap.put(PlayerRuleManager.KONG_HU_RULE, konghuList); + + List cpDiscardRuleList = new ArrayList(); + cpDiscardRuleList.add(new RuleSelfKong()); + cpDiscardRuleList.add(new RulePongKong()); + ruleMap.put(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, cpDiscardRuleList); + + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/RoomCard.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/RoomCard.java new file mode 100644 index 0000000..d793fec --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/RoomCard.java @@ -0,0 +1,163 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.game.Global; + +import extend.mj.uitl.WinCard; + + +public class RoomCard { + public List cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + subCardList = new ArrayList<>(); + this.room = table; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + + private void initCard() { + + for (int index = 1; index <= 9; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + this.cardList.add(300 + index); + } + } + + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + boolean laizi8 = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG8); + if(laizi) { + int laiziNum = laizi8 ? 8 :4; + WinCard.zhongWinNum = laiziNum; + for(int i =0;i cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } + +// public int pop() { +// +// if (this.cardList.size() == 0) { +// this.room.bankerSeat = this.room.activeSeat; +//// this.room.roundSettle(); +// } +// +// int card = this.cardList.remove(0); +// +// return card; +// +// } + + public int pop() { + Global.logger.info("pop cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + card = this.subCardList.remove(0); + }else { + this.room.bankerSeat = this.room.activeSeat; + } + }else { + card = this.cardList.remove(0); + } + return card; + + } + + public int popsub() { + Global.logger.info("pop sub cardlist size=>"+this.cardList.size()+":sub size==>"+subCardList.size()); + int card = 0; + if (this.subCardList.size() == 0) { + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + }else { + card = this.cardList.remove(0); + } + }else { + card = this.subCardList.remove(0); + } + return card; +// this.room.roundSettle(); + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + // ���� + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < 13; index++) { + dealCards.add(this.pop()); + } + +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(101); +// dealCards.add(Config.HONGZHONG); +// dealCards.add(Config.HONGZHONG); +// dealCards.add(Config.HONGZHONG); +// dealCards.add(Config.HONGZHONG); +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(102); +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(103); +// dealCards.add(104); + return dealCards; + + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/RuleWeight.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/RuleWeight.java new file mode 100644 index 0000000..b247e6f --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/RuleWeight.java @@ -0,0 +1,20 @@ +package extend.mj; + +public class RuleWeight { + public final static int CHOW = 0b00001; + public final static int PONG = 0b00010; + public final static int KONG = 0b00100; + public final static int SELFKONG = 0b00100; + public final static int WIN = 0b01000; + public final static int SELF_WIN = 0b10000; + + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KONG = 3; + public final static int TYPE_SELF_KONG = 4; + public final static int TYPE_PONG_KONG = 5; + public final static int TYPE_WIN = 6; + +} + diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/SettleLog.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/SettleLog.java new file mode 100644 index 0000000..a7c6e67 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/SettleLog.java @@ -0,0 +1,44 @@ +package extend.mj; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/TagAnalyseItem.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/TagAnalyseItem.java new file mode 100644 index 0000000..f3e4888 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/TagAnalyseItem.java @@ -0,0 +1,16 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagAnalyseItem { + //分析子项 + public int cbCardEye; //牌眼麻将 + public List cbOpCard; //组合类型 + + public TagAnalyseItem() + { + this.cbCardEye = 0; + this.cbOpCard = new ArrayList(); + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/TagKindItem.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/TagKindItem.java new file mode 100644 index 0000000..fe18c06 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/TagKindItem.java @@ -0,0 +1,17 @@ +package extend.mj; + +import java.util.ArrayList; +import java.util.List; + +public class TagKindItem { + public int type; //组合类型 + public int card; //中心麻将 + public Integer[] cbCardList; //麻将索引 + + public TagKindItem() + { + type = 0; + card = 0; + cbCardList = new Integer[3]; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherKong.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherKong.java new file mode 100644 index 0000000..fcf6da1 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherKong.java @@ -0,0 +1,50 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleOtherKong.java + */ +public class RuleOtherKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + + int eventCard = room.activeCard; + if (eventCard == Config.HONGZHONG || player.isEntrust()) { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 3)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.KONG, this, RuleWeight.TYPE_KONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + player.stateMachine.changeState(Global.getState(PROtherKongState.class)); + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherWin.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherWin.java new file mode 100644 index 0000000..ffadaec --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleOtherWin.java @@ -0,0 +1,62 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PROtherWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +/** + * ���Ƽ�� + * + * + * 2017��8��30�� + * RuleOtherWin.java + */ +public class RuleOtherWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if(!player.forceCheckWin&&player.louhu)return false; + EXRoom room = player.getRoom(); + ITObject config = room.config; + + if (!player.forceCheckWin&&!config.getBoolean(Config.ROOM_CONFIG_DIANPAO)) { + return false; + } + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + + int activieCard = room.activeCard; + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + WinCard win = new WinCard(player.cardInhand, room.activeCard, Config.HONGZHONG, laizi,qidui); + if(hz_hu&&win.zhong_count >0) { + return false; + } + if (win.checkQidui() || win.tryWin(room)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activieCard); + Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN); + tip.winType = player.forceCheckWin? 1 :0; + player.tipMgr.addTip(tip); + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.winType = tip.winType; + player.stateMachine.changeState(Global.getState(PROtherWinState.class)); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePong.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePong.java new file mode 100644 index 0000000..48cf238 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ����� + * + * + * 2017��8��30�� + * RulePong.java + */ +public class RulePong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == Config.HONGZHONG || player.isEntrust()) { + return false; + } + + if (Util.checkCard(eventCard, player.cardInhand, 2)) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player, Tip tip) { + if (Util.checkCard(tip.card, player.cardInhand, 3)) { + player.notPongKongList.add(tip.card); + } + player.stateMachine.changeState(Global.getState(PRPongState.class)); + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePongKong.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePongKong.java new file mode 100644 index 0000000..6a36a2e --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RulePongKong.java @@ -0,0 +1,59 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRPongKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RulePongKong.java + */ +public class RulePongKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + boolean result = false; + if (player.isEntrust()) { + return false; + } + for (int card : player.cardInhand) { + if(!player.notPongKongList.contains(card)) { + result = conditionCard(player, card) || result; + } + } + return result; + + } + + public boolean conditionCard(EXPlayer player, int card) { + + for (int[] cardGroup : player.pongGroup) { + if (card == cardGroup[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_PONG_KONG); + player.tipMgr.addTip(tip); + return true; + } + } + return false; + + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.stateMachine.changeState(Global.getState(PRPongKongState.class)); + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfKong.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfKong.java new file mode 100644 index 0000000..ff51846 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfKong.java @@ -0,0 +1,56 @@ +package extend.mj.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfKongState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; + +/** + * ���ܼ�� + * + * + * 2017��8��30�� + * RuleSelfKong.java + */ +public class RuleSelfKong implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + if (player.isEntrust()) { + return false; + } + Map cardMap = Util.getCardNumMap(player.cardInhand); + boolean result = false; + + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + if(card == Config.HONGZHONG)continue; + int num = entry.getValue(); + if (num >= 4) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG); + player.tipMgr.addTip(tip); + result = true; + } + } + return result; + } + + @Override + public void action(EXPlayer player,Tip tip) { + player.stateMachine.changeState(Global.getState(PRSelfKongState.class)); + + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfWin.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfWin.java new file mode 100644 index 0000000..93b26b5 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rule/RuleSelfWin.java @@ -0,0 +1,49 @@ +package extend.mj.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.player.rulestate.PRSelfWinState; +import extend.mj.tip.IRuleBase; +import extend.mj.tip.Tip; +import extend.mj.uitl.WinCard; + +/** + * ������� + * + * + * 2017��8��30�� + * RuleSelfWin.java + */ +public class RuleSelfWin implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // TODO Auto-generated method stub + ITObject config = player.room.config; + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + boolean laizi = config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + WinCard win = new WinCard(player.cardInhand, Config.HONGZHONG, laizi,qidui); + if (win.checkQidui() || win.tryWin(player.getRoom())) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(player.drawCard); + Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player,Tip tip) { + // TODO Auto-generated method stub + player.stateMachine.changeState(Global.getState(PRSelfWinState.class)); + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherKongState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherKongState.java new file mode 100644 index 0000000..ad4facd --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherKongState.java @@ -0,0 +1,89 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PROtherKongState.java + */ +public class PROtherKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size()-1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + room.addScore(owner,activePlayer, 3,EXScore.KONG); + + EXMainServer.gameCtr.changeActiveSeat(room,owner.seat); + owner.cardInhand.add(owner.getRoom().activeCard); + + + int [] kongGroup = new int [4]; + int card = room.activeCard; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + + owner.kongGroup.add(kongGroup); + owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, fromseat) ); + Util.removeCard(owner.cardInhand, card, 4); + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard); + owner.settleLog.add(Config.SETTLE_MING_KONG); +// owner.stateMachine.changeState( Global.getState(EXPlayerDrawState.class) ); + +// owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); +// if(room.tipMap.size() == 0){ + toNextState(owner); +// }else{ +// owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); +// } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherWinState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherWinState.java new file mode 100644 index 0000000..88d1795 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PROtherWinState.java @@ -0,0 +1,46 @@ +package extend.mj.player.rulestate; + +import com.game.state.StateBase; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PROtherWinState.java + */ +public class PROtherWinState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + int score = room.di_fen; + //int qg_type = room.config.getInt(Config.ROOM_CONFIG_QG_TYPE); + if(room.config.getBoolean(Config.ROOM_CONFIG_QIANGGANG_DIANPAO) == false &&owner.winType == 1) { + score = room.di_fen * ( room.maxPlayers - 1); + } + room.addScore(owner,activePlayer, score,EXScore.WIN); + room.addPiaoNiaoScore(owner, activePlayer); + activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO); + activePlayer.winer = 2; + + owner.settleLog.add(Config.SETTLE_JIE_PAO); + EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard); + + room.bankerSeat = owner.seat; + room.winCount += 1; + owner.winer = 1; + owner.winCard = room.activeCard; + + room.winCallback( owner ,owner.winCard); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongKongState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongKongState.java new file mode 100644 index 0000000..070f652 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongKongState.java @@ -0,0 +1,77 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; +import extend.mj.player.state.EXPlayerWaitKongWinState; +import extend.mj.uitl.CardUtil; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRPongKongState.java + */ +public class PRPongKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + + Util.removeCard(owner.cardInhand, card, 1); + CardUtil.removeGroup(owner.pongGroup, card); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_PONG, card)); + + int[] kong = new int[4]; + kong[0] = card; + kong[1] = card; + kong[2] = card; + kong[3] = card; + owner.kongGroup.add(kong); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard); + + room.activeCard = card; + boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG); + if(qiangkong) { + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null); + if(room.tipMap.size() == 0){ + toNextState(owner); + }else{ + owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class)); + } + }else { + toNextState(owner); + } + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.settleLog.add(Config.SETTLE_MING_KONG); + owner.getRoom().addAllScore(owner, 3, EXScore.KONG); + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongState.java new file mode 100644 index 0000000..5d82b46 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRPongState.java @@ -0,0 +1,67 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.OpCard; +import extend.mj.PlayerRuleManager; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDiscardState; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * 2017��8��30�� + * PRPongState.java + */ +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.activeCard); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + owner.pongGroup.add(pongGroup); + Util.removeCard(owner.cardInhand, card, 3); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard); + + if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){ + toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java new file mode 100644 index 0000000..f4d8a9f --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfKongState.java @@ -0,0 +1,53 @@ +package extend.mj.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; +import extend.mj.OpCard; +import extend.mj.RuleWeight; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ��Ӧ���ܴ���״̬ + * + * + * 2017��8��30�� + * PRSelfKongState.java + */ +public class PRSelfKongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + ITArray opCard = owner.opCard; + int card = opCard.getInt(0); + Util.removeCard(owner.cardInhand, card, 4); + int [] kongGroup = new int [4]; + kongGroup[0] = card; + kongGroup[1] = card; + kongGroup[2] = card; + kongGroup[3] = card; + owner.selfKongGroup.add(kongGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard); + + room.addAllScore(owner, 3, EXScore.KONG); + owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + owner.settleLog.add(Config.SETTLE_AN_KONG); + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java new file mode 100644 index 0000000..4ca847e --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/rulestate/PRSelfWinState.java @@ -0,0 +1,76 @@ +package extend.mj.player.rulestate; + + +import java.util.Map.Entry; + +import com.game.Util; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.EXRoom; +import extend.mj.EXScore; + +/** + * ��Ӧ��������״̬ + * + * + * 2017��8��30�� + * PRSelfWinState.java + */ +public class PRSelfWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + owner.winCard = owner.drawCard; + owner.winer = 1; + Util.removeCard(owner.cardInhand, owner.winCard, 1); + room.addAllScore(owner, room.di_fen,EXScore.WIN); + boolean jiabei = true; + boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI); + if (wuguijiabei && room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) + { + if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) + { + room.addAllScore(owner, room.di_fen,EXScore.WIN); + } + } + room.addAllPiaoNiaoScore(owner); + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + + EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard); + room.niao_selfWin(owner,owner.winCard ); + owner.room.bankerSeat = owner.seat; + owner.settleLog.add(Config.SETTLE_ZIMO); + room.endGame(); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..2e3d968 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ��ҳ�����ʾ״̬ + * + * + * 2017��8��30�� + * EXPlayerDisCardTipState.java + */ +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..3dcd07d --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDiscardState.java @@ -0,0 +1,146 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +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.Config; +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.room.state.EXRoomSetpState; + +import java.util.ArrayList; +import java.util.Collections; + +/** + * �ȴ���ҳ���״̬ + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + ITArray card_list = netParam.getTArray("card_list"); + ITArray outcard_list = netParam.getTArray("outcard_list"); + if (card_list == null) { + card_list = TArray.newInstance(); + } + if (outcard_list == null) { + outcard_list = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < card_list.size(); i++) + { + int card = card_list.getInt(i); + tmpCardList.add(card); + } + + ArrayList out_tmpCardList = new ArrayList(); + for(int i = 0; i < outcard_list.size(); i++) + { + int card = outcard_list.getInt(i); + out_tmpCardList.add(card); + } + + + Collections.sort(tmpCardList); + Collections.sort(out_tmpCardList); + + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(owner.cardInhand); + Collections.sort(tmpCardList2); + + ArrayList out_tmpCardList2 = new ArrayList(); + out_tmpCardList2.addAll(owner.outcardList); + Collections.sort(out_tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2) || !out_tmpCardList.equals(out_tmpCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + owner.louhu = false; + EXMainServer.gameCtr.outCard(owner, discard); + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_TIMER_AUTO: + owner.louhu = false; + discard = owner.drawCard; + if(owner.drawCard == 0) { + discard = owner.cardInhand.get(owner.cardInhand.size() - 1); + } + if(discard == Config.HONGZHONG) { + for (Integer card : owner.cardInhand) { + if(card !=Config.HONGZHONG) { + discard = card; + break; + } + } + } + EXMainServer.gameCtr.outCard(owner, discard); + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + default: + break; + } + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..ab2151e --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawState.java @@ -0,0 +1,223 @@ +package extend.mj.player.state; + +import com.game.Global; +import com.game.Util; +import com.game.state.StateBase; + +import com.taurus.core.entity.ITObject; +import extend.mj.*; +import extend.mj.uitl.WinCard; + +import java.util.ArrayList; + +/** + * ���ץ��״̬ + * + * + * 2017��8��30�� + * EXPlayerDrawState.java + */ +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.card.cardList.size() == 0) { + room.liuju = true; + room.endGame(); + return; + + } + + ITObject config = room.config; + boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI); + boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU); + boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG); + + if(owner.seat == room.adminSeat) { + double rand = Math.random() % 100; + if (room.while_list && !owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = owner.drawCard = room.card.popsub(); + + WinCard win = new WinCard(owner.cardInhand, drawCard, Config.HONGZHONG, laizi,qidui); + if(!(hz_hu && win.zhong_count >0)) { + if (win.checkQidui() || win.tryWin(room)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + continue; + } + } + } + + owner.drawCard = drawCard; + break; + } while(true); + + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + }else { + double rand = Math.random() % 100 * 100; + if (room.while_list && owner.is_white && rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + if(!IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + if (room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + if(owner.black_white_status == 2) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + double rand1 = Math.random() % 100 * 100; + if (rand1 <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if(IsGoodCard(owner, drawCard, qidui, hz_hu, laizi)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= 5) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + else { + owner.drawCard = room.card.pop(); + } + } + } + + int leftCount = room.card.getCount(); + ((EXGameController)Global.gameCtr).getCard(owner, leftCount); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE, owner); + } + + private boolean IsGoodCard(EXPlayer player, int drawCard, boolean qidui, boolean hz_hu, boolean laizi) { + if (drawCard == Config.HONGZHONG) + { + return true; + } + + if (Util.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + for (int[] cardGroup : player.pongGroup) { + if (drawCard == cardGroup[0]) { + return true; + } + } + + WinCard win = new WinCard(player.cardInhand, drawCard, Config.HONGZHONG, laizi,qidui); + if(!(hz_hu && win.zhong_count >0)) { + if (win.checkQidui() || win.tryWin(player.getRoom())) { + return true; + } + } + + if (drawCard < 400) + { + if (drawCard % 100 <= 7) + { + if (Util.cardNum(drawCard+1, player.cardInhand) >= 1 && Util.cardNum(drawCard+2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 3) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard-2, player.cardInhand) >= 1) + { + return true; + } + } + + if (drawCard % 100 >= 2 && drawCard % 100 <= 8) + { + if (Util.cardNum(drawCard-1, player.cardInhand) >= 1 && Util.cardNum(drawCard+1, player.cardInhand) >= 1) + { + return true; + } + } + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } + + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..f2b5baf --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,43 @@ +package extend.mj.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.game.Global; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * ���ץ����ʾ״̬ + * + */ +public class EXPlayerDrawTipState extends EXPlayerTipState { + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ; + if(Global.gameId == 1 && win && id == 0)return; + owner.tipMgr.doAction(id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java new file mode 100644 index 0000000..fae3c10 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerKongWinState.java @@ -0,0 +1,58 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +import java.util.Map; + +/** + * ���������ʾ�ȴ� + * + * + * 2017��8��30�� + * EXPlayerKongWinState.java + */ +public class EXPlayerKongWinState extends EXPlayerTipState{ + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.choicAction(id); + } + else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Map.Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..1263fff --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,54 @@ +package extend.mj.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.taurus.core.entity.ITObject; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; + +/** + * Ʊ����ʾ״̬ + * + */ +public class EXPlayerPiaoNiaoTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoNiaoTipEvent(owner); + owner.startActionTimer(); + }else{ + _action(owner, 0, 0); + } + } + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piaoNiao = id; + owner.tipMgr.clean(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoNiaoCount --; + EXMainServer.gameCtr.piaoNiaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO_NIAO, gid, null); + } + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner,id,gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + _action(owner,0,gid); + } + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerTipState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..05391c5 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerTipState.java @@ -0,0 +1,62 @@ +package extend.mj.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.mj.Config; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.RuleWeight; +import extend.mj.tip.Tip; + +/** + * �����ʾ������� + * + * + * 2017��8��30�� + * EXPlayerTipState.java + */ +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (owner.getRoom().config.getBoolean(Config.ROOM_CONFIG_BI_HU)) + { + Tip tip = owner.tipMgr.getTip(RuleWeight.TYPE_WIN); + if (tip != null) + { + owner.startActionTimer(1000); + return; + } + } + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tipEvent(owner); + } + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if(cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java new file mode 100644 index 0000000..dff6a34 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitKongWinState.java @@ -0,0 +1,24 @@ +package extend.mj.player.state; + +import com.game.state.StateBase; + +import extend.mj.EXPlayer; + +/** + * ������ҵȴ��������ǹ�ܺ� + * + * + * 2017��8��30�� + * EXPlayerWaitKongWinState.java + */ +public class EXPlayerWaitKongWinState extends StateBase{ + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + + } + + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..858aee0 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/player/state/EXPlayerWaitState.java @@ -0,0 +1,39 @@ +package extend.mj.player.state; + + +import com.game.state.StateBase; + +import extend.mj.EXActionEvent; +import extend.mj.EXMainServer; +import extend.mj.EXPlayer; +import extend.mj.PlayerRuleManager; + +/** + * ��ҵȴ�״̬ + * + * + * 2017��8��30�� + * EXPlayerWaitState.java + */ +public class EXPlayerWaitState extends StateBase { + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_KONG_WIN: + owner.forceCheckWin = true; + EXMainServer.playerRuleMgr.condition( PlayerRuleManager.KONG_HU_RULE , owner); + owner.forceCheckWin = false; + break; + default: + break; + } + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomDealState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomDealState.java new file mode 100644 index 0000000..1e40a54 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomDealState.java @@ -0,0 +1,114 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; +import extend.mj.*; +import extend.mj.player.state.EXPlayerPiaoNiaoTipState; + +import java.util.Map.Entry; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +/** + * ���䷢��״̬ + * + * + * 2017��8��30�� + * EXRoomDealState.java + */ +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + //随机定庄 + Random random = new Random(); + owner.bankerSeat = random.nextInt(2) + 1; + } +// owner.isplaying = true; +// owner.round += 1; + + boolean piao_niao = owner.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO); + if(piao_niao) { + owner.piaoNiaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + }else{ + this.toNextState(owner); + } + + } + + @Override + public void toNextState(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + ITObject param = new TObject(); + param.putInt("bank_seat", owner.bankerSeat); + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new EXPlayBack(owner); + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) { + if(owner.piaoNiaoCount==0) { + this.toNextState(owner); + } + } + + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomSetpState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..47fbd44 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomSetpState.java @@ -0,0 +1,42 @@ +package extend.mj.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.mj.EXMainServer; +import extend.mj.EXRoom; +import extend.mj.player.state.EXPlayerDrawState; + +/** + * ����ת����λ + * + * + * 2017��8��30�� + * EXRoomSetpState.java + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + this.toNextState(owner); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomStartGameState.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..1272100 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/room/state/EXRoomStartGameState.java @@ -0,0 +1,33 @@ +package extend.mj.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.mj.EXRoom; + +/** + * ���俪ʼ״̬ + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { +// owner.readyCount = 0; +// for (Entry entry : owner.playerMapById.entrySet()) { +// Player player = entry.getValue(); +// player.ready = false; +// player.clear(); +// player.initSeat(); +// } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Action.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Action.java new file mode 100644 index 0000000..454d9ca --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Action.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + + +import extend.mj.EXPlayer; + +/** + * + * + + */ +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player,this.tip); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/IRuleBase.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/IRuleBase.java new file mode 100644 index 0000000..79f1ab8 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/IRuleBase.java @@ -0,0 +1,27 @@ +package extend.mj.tip; + +import extend.mj.EXPlayer; + +/** + * ����������� + * + * + * 2017��8��30�� + * RuleBase.java + */ +public interface IRuleBase { + + /** + * ������� + * @param player + * @return + */ + public abstract boolean condition(EXPlayer player ); + + /** + * ִ�иù��� + * @param player + */ + public abstract void action(EXPlayer player ,Tip tip); + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Tip.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Tip.java new file mode 100644 index 0000000..434343a --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/Tip.java @@ -0,0 +1,40 @@ +package extend.mj.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +/** + * tip������ + * + * + * + * 2017��8��30�� Tip.java + */ +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int winType; + public int type; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/TipManager.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/TipManager.java new file mode 100644 index 0000000..bfd4b01 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/tip/TipManager.java @@ -0,0 +1,138 @@ +package extend.mj.tip; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.mj.EXPlayer; +import extend.mj.RuleWeight; + +/** + * + * + * + * 2017��9��18�� TipManager.java + */ +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + public Tip getTip(int type) + { + for (Entry entry : this.tipMap.entrySet()) + { + Tip tip = entry.getValue(); + if (tip.type == type) + { + return tip; + } + } + return null; + } + + private void checkLouhu() { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + this.owner.louhu = true; + break; + } + } + } + + public void choicAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + this.checkLouhu(); + this.owner.stateMachine.lastState.toNextState(owner); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.initOpCard(tip.opcard); + tip.rule.action(owner,tip); + + } else { + throw new Error("tip map has no id" + id); + } + + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/CardUtil.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/CardUtil.java new file mode 100644 index 0000000..6d95053 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/CardUtil.java @@ -0,0 +1,32 @@ +package extend.mj.uitl; + +import java.util.List; + +import extend.mj.OpCard; + +public class CardUtil { + + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card == opcards.get(i).card) { + opcards.remove(i); + return; + } + + } + + } + +} diff --git a/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/WinCard.java b/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/WinCard.java new file mode 100644 index 0000000..f51e9c6 --- /dev/null +++ b/game_mj_zhuanzhuan/src/main/java/extend/mj/uitl/WinCard.java @@ -0,0 +1,363 @@ +package extend.mj.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import com.game.Util; +import extend.mj.Config; +import extend.mj.EXRoom; + +public class WinCard { + + public int pair_count; + public Stack> stack; + public List cardList; + public int zhong_count; + public int zhongid = 0; + public boolean qidui; + public static int zhongWinNum = 4; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + if (card == zhongid) { + this.zhong_count += 1; + } else { + this.cardList.add(card); + } + } + Collections.sort(this.cardList); + } + + private boolean tryShunzi(int card) { + if (card < 400 && card % 100 > 7) { + return false; + } + if (Util.checkCard(card + 1, this.cardList) && Util.checkCard(card + 2, this.cardList)) { + Util.removeCard(this.cardList, card, 1); + Util.removeCard(this.cardList, card + 1, 1); + Util.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + return false; + } + + private boolean tryKezi(int card) { + + if (Util.checkCardAndRomve(card, this.cardList, 3)) { +// CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + + if (Util.checkCardAndRomve(card, this.cardList, 2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + return true; + } + return false; + + } + + private boolean tryKezi1Zhong(int card) { + + if (this.zhong_count >= 1 && Util.checkCardAndRomve(card, this.cardList,2)) { +// CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.zhong_count -= 1; + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryKezi2Zhong(int card) { + + if (this.zhong_count >= 2 && Util.checkCardAndRomve(card, this.cardList,1)) { +// CardUtil.removeCard(this.cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(this.zhongid); + this.zhong_count -= 2; + this.push(cardGroup); + return true; + } + return false; + + } + + private boolean tryShunzi1Zhong(int card) { + if (card % 100 > 8) { + return false; + } + + if (this.zhong_count < 1) { + return false; + } + + if (Util.checkCard(card + 1, this.cardList)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 1, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(this.zhongid); + this.push(cardGroup); + return true; + } + + if (Util.checkCard(card + 2, this.cardList) && ((card + 1) % 100 != 0)) { + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 2, 1); + this.zhong_count -= 1; + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + cardGroup.add(card + 2); + this.push(cardGroup); + return true; + } + + return false; + + } + + private boolean tryPair1Zhong(int card) { + + if (this.pair_count > 0) { + return false; + } + if (this.zhong_count < 1) { + return false; + } + Util.removeCard(cardList, card, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.zhong_count -= 1; + this.pair_count = 1; + return true; + + } + + private boolean tryPair2Zhong() { + + if (this.pair_count > 0) { + return false; + } + if (this.zhong_count < 2) { + return false; + } + List cardGroup = new ArrayList(); + cardGroup.add(this.zhongid); + cardGroup.add(this.zhongid); + this.push(cardGroup); + this.pair_count = 1; + this.zhong_count -= 2; + return true; + } + + public boolean tryWin(EXRoom room) { + if (room.config.getBoolean(Config.ROOM_CONFIG_LAIZI4_HU)) + { + if (this.zhong_count == zhongWinNum) { + return true; + } + } + + if (this.cardList.size() == 0 && this.pair_count == 1) { + return true; + } + if (this.cardList.size() == 0 && this.pair_count == 0) { + return tryPair2Zhong(); + } + + if (this.cardList.size() == 0) { + return false; + } + int activeCard = this.cardList.get(0); + + if (tryPair(activeCard)) { + if (tryWin(room)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + + } + + if (tryKezi(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryShunzi(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + + if (tryKezi1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryKezi2Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryShunzi1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.rollBack(); + + } + if (tryPair1Zhong(activeCard)) { + if (tryWin(room)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + } + return false; + } + + public WinCard(List cardInhand, int addCard, int zhongid, boolean isZhong, boolean qidui) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + this.qidui = qidui; + this.cardList.add(addCard); + if (isZhong) { + this.zhongid = zhongid; + this.zhong_count = Util.cardNum(zhongid, this.cardList); + Util.removeCard(this.cardList, zhongid, this.zhong_count); + } + Collections.sort(this.cardList); + } + + public WinCard(List cardInhand, int zhongid, boolean isZhong, boolean qidui) { + this.stack = new Stack>(); + this.cardList = new ArrayList(); + this.qidui = qidui; + this.cardList.addAll(cardInhand); + if (isZhong) { + this.zhongid = zhongid; + this.zhong_count = Util.cardNum(zhongid, this.cardList); + Util.removeCard(this.cardList, zhongid, this.zhong_count); + } + Collections.sort(this.cardList); + + } + + public boolean checkQidui() { + if (!this.qidui) + return false; + if ((this.cardList.size() + zhong_count) != 14) + return false; + List cardlist = new ArrayList<>(); + cardlist.addAll(this.cardList); + hongzhong_count = this.zhong_count; + return isQdPari(cardlist); + } + + private int hongzhong_count = 0; + private int qidui_pari_count = 0; + boolean isQdPari(List cardlist) { + if(qidui_pari_count == 7)return true; + if (cardlist.size() == 0)return true; + int card = cardlist.get(0); + if (Util.cardNum(card, cardlist) >= 2) { + Util.removeCard(cardlist, card, 2); + qidui_pari_count++; + if (isQdPari(cardlist)) { + return true; + } + } + + if (this.hongzhong_count > 0) { + Util.removeCard(cardlist, card, 1); + this.hongzhong_count--; + qidui_pari_count++; + if (isQdPari(cardlist)) { + return true; + } + } + return false; + + } + + public static void main(String[] args) { + + + long time = System.currentTimeMillis(); +// for(int i=0;i<1000000;++i) { + ArrayList cardInhand = new ArrayList(); + cardInhand.add(101); + cardInhand.add(102); + cardInhand.add(103); + cardInhand.add(104); + cardInhand.add(105); + cardInhand.add(106); + + cardInhand.add(204); + cardInhand.add(205); + cardInhand.add(206); + cardInhand.add(201); + cardInhand.add(202); + cardInhand.add(203); + + cardInhand.add(301); + cardInhand.add(301); + cardInhand.add(301); + cardInhand.add(108); + WinCard win = new WinCard(cardInhand,45,45,true,false); +// } + System.out.println( System.currentTimeMillis() - time); + } + +} diff --git a/game_mj_zhuanzhuan/src/test/java/game_mj_zhuanzhuan/Main.java b/game_mj_zhuanzhuan/src/test/java/game_mj_zhuanzhuan/Main.java new file mode 100644 index 0000000..236d370 --- /dev/null +++ b/game_mj_zhuanzhuan/src/test/java/game_mj_zhuanzhuan/Main.java @@ -0,0 +1,9 @@ +package game_mj_zhuanzhuan; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_pk_chuntian/config/game-config.xml b/game_pk_chuntian/config/game-config.xml new file mode 100644 index 0000000..ea7c41c --- /dev/null +++ b/game_pk_chuntian/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 127.0.0.1 + 0.0.0.0 + 8365 + 8965 + 65 + true + \ No newline at end of file diff --git a/game_pk_chuntian/config/log4j.properties b/game_pk_chuntian/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_pk_chuntian/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_pk_chuntian/config/taurus-core.xml b/game_pk_chuntian/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_pk_chuntian/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_chuntian/config/taurus-permanent.xml b/game_pk_chuntian/config/taurus-permanent.xml new file mode 100644 index 0000000..31220cb --- /dev/null +++ b/game_pk_chuntian/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - test + extend.extend.pk.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_pk_chuntian/pom.xml b/game_pk_chuntian/pom.xml new file mode 100644 index 0000000..87510e2 --- /dev/null +++ b/game_pk_chuntian/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_pk_chuntian + 1.0.0 + jar + + game_pk_chuntian + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_pk_chuntian + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_pk_chuntian/src/main/java/extend/pk/CardGroup.java b/game_pk_chuntian/src/main/java/extend/pk/CardGroup.java new file mode 100644 index 0000000..fed67c9 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/CardGroup.java @@ -0,0 +1,44 @@ +package extend.pk; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.pk.uitl.CardConfig; + +import java.util.List; + +public class CardGroup { + /** + * 当前type + */ + public CardConfig config; + + public int min_card; + /** + * 长度 + */ + public int len = 1; + + public List card_list; + + public ITArray card_list_mp; + + public ITObject toObject(boolean card_size) { + ITObject obj = TObject.newInstance(); + if (card_size) { + obj.putInt("card_size", card_list.size()); + } else { + obj.putTArray("card_list", card_list_mp); + } + + obj.putInt("type", config.type); + obj.putInt("min_card", min_card); + obj.putInt("len", len); + return obj; + } + + public String toString() { + return "{type:" + config + " min_card:" + min_card + " len:" + len + " list:" + card_list + "}"; + } + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/CardObj.java b/game_pk_chuntian/src/main/java/extend/pk/CardObj.java new file mode 100644 index 0000000..bc2d762 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/CardObj.java @@ -0,0 +1,21 @@ +package extend.pk; + +public class CardObj implements Comparable{ + public int card; + public int cardMod; + + public CardObj(int card) { + this.card = card; + this.cardMod = card % 100; + } + + @Override + public int compareTo(CardObj paramT) { + return cardMod == paramT.cardMod ? 0 : cardMod < paramT.cardMod ? -1 : 1; + } + + @Override + public String toString() { + return card + ""; + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/Config.java b/game_pk_chuntian/src/main/java/extend/pk/Config.java new file mode 100644 index 0000000..483dca8 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/Config.java @@ -0,0 +1,202 @@ +package extend.pk; + +public class Config { + + public static final int XIPAI_SCORE = 10; + + //-------------------------------玩法配置--------------------------------- + /** + * 玩法 单QKA2 去掉234 + */ + public static final String ROOM_CONFIG_SELECTDIQU = "selectDiqu"; + + + /** + * 有大必大 + */ + public static final String ROOM_CONFIG_YOUDABIDA = "youdabida"; + + + /** + * 报单必大 + */ + public static final String ROOM_CONFIG_BAODANBIDA = "baodanbida"; + + /** + * 三带二 + */ + public static final String ROOM_CONFIG_SANDAIER = "sandaier"; + + /** + * 四带一 + */ + public static final String ROOM_CONFIG_SIDAIYI = "sidaiyi"; + + + /** + * 反春 + */ + public static final String ROOM_CONFIG_FANCHUN = "fanchun"; + + /** + * 杀春翻倍 + */ + public static final String ROOM_CONFIG_SHACHUNFANBEI= "shachunfanbei"; + + /** + * 自然春翻倍 + */ + public static final String ROOM_CONFIG_ZIRANCHUNFANBEI = "ziranchunfanbei"; + + + /** + * 4个A自然春 + */ + public static final String ROOM_CONFIG_SIGEAZIRANCHUN = "sigeAziranchun"; + + + + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + //-------------------------------牌类型--------------------------------- + /** + * 单牌 + */ + public final static int TYPE_DANPAI = 1; + /** + * 对子 + */ + public final static int TYPE_DUIZI = 2; + /** + * 顺子 + */ + public final static int TYPE_SHUNZI = 3; + /** + * 连对 + */ + public final static int TYPE_LIANDUI = 4; + + + /** + * 3带2 + */ + public final static int TYPE_3_2 = 5; + /** + * 飞机 + */ + public final static int TYPE_FEIJI = 6; + + + /** + * 炸 + */ + public final static int TYPE_ZHA = 8; + + /** + * 4带1 + */ + public final static int TYPE_4_1 = 9; + + + /** + * 三条 + */ + public final static int TYPE_3_0 = 10; + + /** + * 拖拉机 + * 连三对,或者4对 + */ + public final static int TYPE_TUOLAJI = 11; + + public final static int TYPE_WUDUI = 12; + + + //-------------------------------协议--------------------------------- + + public static final String GAME_EVT_MING_PAI = "2117"; + /** + * 发牌协议 + */ + public static final String GAME_EVT_PLAYER_DEAL = "2011"; + /** + * 出牌 + */ + public static final String GAME_DIS_CARD = "1013"; + + /** + * 不出 + */ + public static final String GAME_DIS_PASS = "1014"; + + /** + * 出牌事件 + */ + public static final String GAME_EVT_DISCARD = "2021"; + /** + * 出牌提示事件 + */ + public static final String GAME_EVT_DISCARD_TIP = "2004"; + + /** + * 转盘指向事件 + */ + public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "2016"; + + /** + * pass事件 + */ + public static final String GAME_EVT_PASS = "2030"; + + /** + * 更新炸弹分数 + */ + public static final String GAME_EVT_UPDATE_BOM_SCORE = "2118"; + + /** + * 小结算 + */ + public static final String GAME_EVT_RESULT1 = "2007"; + + + /** + * 出牌错误 + */ + public static final String GAME_EVT_PUT_ERROR = "2111"; + + + /** + * 报春 + */ + public static final String GAME_NOTIFY_BAO_CHUN = "22033"; + + public static final String GAME_EVT_USER_BAO_CHUN_REQ = "22034"; + + public static final String GAME_EVT_ALERT_TongYi_BAO_CHUN = "22035"; + + public static final String GAME_EVT_USER_BAO_CHUN_RSP = "22036"; + + + /** + * 通知新的最后报春成功 + */ + public static final String GAME_EVT_BAO_CHUN_JIA = "22037"; + + /** + * 玩家抢报春 + */ + public static final int PUT_ERROR_MUST_OUT_MIN = 0; + public static final int PUT_ERROR_INVALID_TYPE = 1; + public static final int PUT_ERROR_MUST_OUT_MAX = 2; + public static final int PUT_ERROR_BOMB_CHAI =3; + + public static final String SETTLE_WIN_COUNT = "winnum"; + public static final String SETTLE_CHUNTIAN_COUNT = "springnum"; + + public static final String SETTLE_CTSTATUS = "springstatus"; + public static final String SETTLE_BOMB_COUNT = "boomnum"; + public static final String SETTLE_MAX_SCORE = "maxscore"; +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXActionEvent.java b/game_pk_chuntian/src/main/java/extend/pk/EXActionEvent.java new file mode 100644 index 0000000..cc3f369 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXActionEvent.java @@ -0,0 +1,14 @@ +package extend.pk; + +import com.game.ActionEvent; + +public class EXActionEvent extends ActionEvent{ + + public static final String EVENT_DISCARD = "1013"; + public static final String EVENT_PASS = "1014"; + + //public static final String EVENT_PIAO= "1015"; + public static final String EVENT_BAO_CHUN= "22034"; + public static final String EVENT_TONGYI_BAO_CHUN= "22036"; + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXGameController.java b/game_pk_chuntian/src/main/java/extend/pk/EXGameController.java new file mode 100644 index 0000000..bbf44cd --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXGameController.java @@ -0,0 +1,576 @@ +package extend.pk; + +import com.game.Constant; +import com.game.GameController; +import com.game.Global; +import com.game.data.Player; +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.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +/** + * + * + */ +public class EXGameController extends GameController { + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_DIS_CARD) + public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params); + } + + @ActionKey(Config.GAME_DIS_PASS) + public void RouterDisPass(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PASS, 0, params); + } + + + @ActionKey(Config.GAME_EVT_USER_BAO_CHUN_REQ) + public void RouterBaoChun(Session sender,ITObject params,int gid,Player owner) { + Global.logger.info("RouterBaoChun"); + owner.stateMachine.execute(EXActionEvent.EVENT_BAO_CHUN, 0, params); + } + + @ActionKey(Config.GAME_EVT_USER_BAO_CHUN_RSP) + public void RouterQiangBaoChun(Session sender,ITObject params,int gid,Player owner) { + Global.logger.info("RouterQiangBaoChun:"+owner.playerid); + owner.stateMachine.execute(EXActionEvent.EVENT_TONGYI_BAO_CHUN, 0, params); + } + + // 改变活动玩家 + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("index", activeSeat); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + public void sendPutError(EXPlayer owner,int code) { + ITObject param = new TObject(); + param.putInt("error", code); + owner.sendEvent(Config.GAME_EVT_PUT_ERROR, param); + } + + /** + * pass + * @param owner + */ + public void pass(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + if (Global.loggerDebug) { + Global.logger.info(owner + " pass!"); + } + owner.pass = true; + owner.last_outcard = null; + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addPassCommand(owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_PASS, response); + } + + + + public void outCard(EXPlayer owner,CardGroup ct) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("player", owner.seat); + response.putTObject("card_obj", ct.toObject(false)); + + owner.outCards.addAll(ct.card_list); + + room.lastDiscardSeat = owner.seat; + room.discard = ct; + owner.last_outcard = ct; + owner.pass = false; + room.firstCard = 0; + if (Global.loggerDebug) { + Global.logger.info(owner + " out card:" + ct); + } + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addOutCardCommand(owner.seat, ct); + CardUtil.removeCard(owner.cardInhand, ct.card_list); + + response.putInt("remain", owner.cardInhand.size()); + room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + + public void dealCard(EXRoom owner) { + if (owner.targetCards.size() == 0) { + Global.logger.info("dealcards"); + owner.card.init(); + } + + int maxDanPai = 0; + int maxDuizi = 0; + int maxSanZhang = 0; + boolean existWhite = false; + boolean existXingyunhao = false; + boolean existGeneral = false; + boolean existBlack = false; + double white_rate = 0; + + ArrayList tmpPlayerList = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmpPlayerList.add(player); + } + + Collections.shuffle(tmpPlayerList); + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + existXingyunhao = true; + } else { + if (player.black_white_status == 0) { + existGeneral = true; + } + else if (player.black_white_status == 1) { + existBlack = true; + } + else if (player.black_white_status == 2) { + existWhite = true; + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + white_rate = 100 - owner.white_value; + Global.logger.info("dealcards playerid:"+player.playerid+ " xingyuhao:"+player.is_white+" white_value:"+owner.white_value); + } + else { + continue; + } + + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value,player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + //player.cardInhand = owner.card.deal0(player.seat); + + + Collections.sort(player.cardInhand); + + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 2) + { + white_rate = player.black_white_rate; + Global.logger.info("dealcards playerid:"+player.playerid+ " white player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && (existGeneral || existBlack)) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 0) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " general player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value,player.black_white_status, white_rate, white_rate, 0, 0, 0); + //player.cardInhand = owner.card.deal0(player.seat); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && !existWhite && existBlack) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 1) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " black player:" + (player.black_white_rate+white_rate)); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite && !existGeneral) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, maxDanPai, maxDuizi, maxSanZhang); + } + + + + Collections.sort(player.cardInhand); + } + + Global.logger.info("sssss==>" + owner.supCards.size()); + if (owner.targetCards.size() > 0 && owner.adminSeat > 0 && owner.supCards.size() > 0) { + owner.card.cardList = owner.supCards.get(0); + } + + // 如果是首局,需要确定庄家 + if(owner.bankerSeat == 0) { + owner.bankerSeat = this.getBankerSeat(owner); + this.sendPlayerDeal(owner); + } + else + { + // owner.bankerSeat = this.getBankerSeat(owner); + this.sendPlayerDeal(owner); + } + + } + + /** + * 报春提示 + * @param owner + */ + public void baoChunTipEvent(EXPlayer owner,int reload) { + ITObject response = new TObject(); + response.putInt("baochun", reload); + owner.sendEvent(Config.GAME_NOTIFY_BAO_CHUN, response); + } + + public void baoChunEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("banker_seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_BAO_CHUN_JIA, param); + } + + /** + * 同意报春提示 + * @param owner + */ + public void tongYiBaoChunTipEvent(EXPlayer owner,int reload){ + ITObject response = new TObject(); + response.putInt("tongyibaochun", reload); + owner.sendEvent(Config.GAME_EVT_ALERT_TongYi_BAO_CHUN, response); + } + + /** + * 发生随机牌 用于指示谁首先出牌 + * @param owner + */ + private void sendMingPai(EXRoom owner,int card) { + + ITObject param = new TObject(); + param.putInt("mingpai", card); + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + exPlayer.sendEvent(Config.GAME_EVT_MING_PAI, param); + }; + } + /** + * 发牌 + * @param owner + */ + private void sendPlayerDeal(EXRoom owner){ + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + ITObject param = new TObject(); + ITArray handCard = CardUtil.toTArray(exPlayer.cardInhand); + param.putTArray("cards", handCard); + param.putInt("bank_seat", exPlayer.room.bankerSeat); + param.putInt("round", owner.round); + if (Global.loggerDebug) { + Global.logger.info(owner + " deal card:"+exPlayer.cardInhand); + } + exPlayer.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + }; + } + + private int getBankerSeatByCard(EXRoom owner) { + for (int index = 3; index <= 13; index++) { + for(int color = 4; color >= 1; color--) { + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (CardObj card : player.cardInhand) { + if (card.card == color *100 + index) { + owner.firstCard = card.card; + return player.seat; + } + } + } + } + } + return 0; + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + //如果是兩人的情況 + Random random = new Random(); + seat = random.nextInt(owner.maxPlayers)+1; + return seat; + } + + + + public void discardTipEvent(EXPlayer owner) { + ITObject param = new TObject(); + boolean gen = (owner.getRoom().lastDiscardSeat != 0 &&owner.getRoom().lastDiscardSeat != owner.seat); + param.putInt("play", gen ? 1 : 0); + if(gen) { + param.putTObject("card_obj", owner.getRoom().discard.toObject(true)); + + } + // 如果可以不出 + + + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + } + + private ITObject getRoomResultData(EXRoom owner,boolean total) { + + ITObject mp = TObject.newInstance(); + + EXPlayer win = owner.win; + boolean checkfc = false;//检测是否是反春 + boolean checkct = false;//检测是否是春天 + ITArray info = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.total_score); + obj.putInt("winscore", player.score.round_score); + player.hp_info(obj); + obj.putInt("thisboomnum", player.boomnum); + + obj.putTArray("cards", CardUtil.toTArray(player.cardInhand)); + obj.putBoolean("chuntian", player.chuntian); + + obj.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + obj.putTArray("outCards", CardUtil.toTArray(player.outCards)); + + if(total) { + obj.putInt("award", player.bonusScore); + + if(owner.endType == Constant.END_TYPE_ENTRUST) { + obj.putInt("entrust", player.entrust ? 1 : 0); + } + obj.putTObject("settle_log", player.settleLog.toTObject()); + obj.putInt("total_score", player.score.total_score); + + } + info.addTObject(obj); + Global.logger.info("bankerSeat: "+owner.bankerSeat); + Global.logger.info("EXPlayer discard:3,{}"+player.seat+"|"+player.dis_times+"|"+player.playerid); + if ((player.seat == owner.bankerSeat)&&(player.dis_times==1)){ + checkfc = true; + } + if((player.seat!=owner.bankerSeat)&&(player.dis_times==0)){ + checkct = true; + } + } + if(win != null) { + mp.putInt("winseat",win.seat); + } + else { + mp.putInt("winseat",0); + } + if(owner.baochunSeat!=0){ + if (owner.shachunSeat==0){ + mp.putInt("chuntianstatus",1); + }else { + mp.putInt("chuntianstatus",2); + } + }else if(checkct){ + mp.putInt("chuntianstatus",1); + }else { + mp.putInt("chuntianstatus", 0); + } + + if (owner.ziranchunover==1){ + mp.putInt("chuntianstatus",1); + } + if (checkfc&&owner.baochunSeat==0){ + mp.putInt("chuntianstatus",3); + } + owner.bankerSeat = win.seat; + + //mp.putTArray("remaincards", CardUtil.toTArray(owner.card.cardList)); + mp.putTArray("remaincards", CardUtil.toTArray(new ArrayList<>())); + mp.putTArray("info", info); + mp.putInt("xipai_score", owner.xi_pai_score); + return mp; + } + + public void roomResult(EXRoom owner) { + + ITObject result = getRoomResultData(owner,false); + result.putInt("type", 0); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + + /** + * 房间大结算 + * @param owner + * @param dissmiss + */ + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + + ITObject result = getRoomResultData(owner,true); + + long t = System.currentTimeMillis() / 1000; + result.putLong("time", t); + result.putInt("type", dissmiss?2:1); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXMainServer.java b/game_pk_chuntian/src/main/java/extend/pk/EXMainServer.java new file mode 100644 index 0000000..4c8705c --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXMainServer.java @@ -0,0 +1,64 @@ +package extend.pk; + +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.room.state.RoomStartGameState; +import extend.pk.player.state.*; +import extend.pk.room.state.*; + +import java.util.Map; + +/** + * + * + */ +public class EXMainServer extends MainServer { + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + gameCtr = (EXGameController) Global.gameCtr; + registerState(); + } + + private final void registerState() { + + Global.registerState(RoomStartGameState.class, new EXRoomStartGameState()); + Global.registerState(EXRoomSetpState.class, new EXRoomSetpState()); + Global.registerState(EXRoomDealState.class, new EXRoomDealState()); + Global.registerState(EXRoomPiaoState.class, new EXRoomPiaoState()); + Global.registerState(EXRoomBaoChunState.class, new EXRoomBaoChunState()); + + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerPassState.class, new EXPlayerPassState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + Global.registerState(EXPlayerBaoChunState.class, new EXPlayerBaoChunState()); + Global.registerState(EXPlayerTongYiBaoChunState.class, new EXPlayerTongYiBaoChunState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXPlayBack.java b/game_pk_chuntian/src/main/java/extend/pk/EXPlayBack.java new file mode 100644 index 0000000..9b4020a --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXPlayBack.java @@ -0,0 +1,48 @@ +package extend.pk; + + +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; +import extend.pk.uitl.CardUtil; + +public class EXPlayBack extends BasePlayBack{ + + public EXPlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + } + + protected ITObject getPlayerInfo(Player p) { + + EXPlayer player = (EXPlayer)p; + ITObject obj =super.getPlayerInfo(player); + ITArray cardInhand = CardUtil.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + + player.hp_info(obj); + return obj; + } + + public void addOutCardCommand(int seat, CardGroup ct) { + ITObject cmdData = ct.toObject(false); + addCommand("OutCard", seat, cmdData); + } + + public void addPassCommand(int seat) { + ITObject cmdData = TObject.newInstance(); + addCommand("pass", seat, cmdData); + } + + public void addNewRoundCommand() { + ITObject cmdData = TObject.newInstance(); + addCommand("newindex", 0, cmdData); + } + + public void addResultCommand(int seat,ITObject cmdData) { + addCommand("result", seat, cmdData); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXPlayer.java b/game_pk_chuntian/src/main/java/extend/pk/EXPlayer.java new file mode 100644 index 0000000..5c12a28 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXPlayer.java @@ -0,0 +1,129 @@ +package extend.pk; + +import com.game.data.Player; +import com.game.data.Room; +import com.game.data.Score; +import com.taurus.core.entity.ITObject; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * + * + */ +public class EXPlayer extends Player { + + /**默认action时间 20s*/ + public static final int DEFAULT_ACTION_TIME = 20000; + /**默认托管时间 1s*/ + public static final int DEFAULT_ENTRUST_TIME = 1000; + /** + * 默认准备时间 20s + */ + public static final int DEFAULT_READY_TIME = 20000; + + // 手牌 + public List cardInhand; + + //打出的牌 + public List outCards; + + public CardGroup last_outcard; + public boolean pass; + + // 放作弊场第一张牌是否关闭 + public int open = 0; + + /**春天 */ + public boolean chuntian; + + public SettleLog settleLog; + + public int boomnum = 0; + + public int baochun = -1; + + public int bonusScore = 0; + public int awardScore = 0; + + public int ziranchun = 0; + + public int dis_times = 0;//出牌次数 + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + cardInhand = new ArrayList<>(); + outCards = new ArrayList<>(); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_WIN_COUNT, 1); + settleLog.put(Config.SETTLE_CHUNTIAN_COUNT, 1); + settleLog.put(Config.SETTLE_CTSTATUS, 1); + settleLog.put(Config.SETTLE_BOMB_COUNT, 0); + settleLog.put(Config.SETTLE_MAX_SCORE, 20); + } + + protected Score newScore() { + return new EXScore(this); + } + + @Override + public ITObject getReloadInfo() { + ITObject playerData = super.getReloadInfo(); + playerData.putInt("card_size", this.cardInhand.size()); + if(last_outcard!=null) { + playerData.putTObject("last_outcard", last_outcard.toObject(false)); + } + + if(this.room.isplaying == false) { + playerData.putTArray("cards", CardUtil.toTArray(this.cardInhand)); + + playerData.putTArray("handCards", CardUtil.toTArray(this.cardInhand)); + playerData.putTArray("outCards", CardUtil.toTArray(this.outCards)); + + playerData.putInt("score", score.total_score); + playerData.putInt("winscore", score.round_score); + playerData.putInt("thisboomnum", boomnum); + playerData.putInt("open", open); + } + return playerData; + } + + @Override + public ITObject getInfo() { + ITObject playerData = super.getInfo(); + playerData.putInt("score", score.total_score); + return playerData; + } + + + public void clear() { + super.clear(); + + } + + public void clearEx() { + + this.score.resetRound(); + this.cardInhand.clear(); + this.outCards.clear(); + this.last_outcard = null; + this.pass = false; + this.chuntian =false; + + this.open = 0; + this.boomnum = 0; + this.baochun = -1; + this.ziranchun = 0; + this.dis_times = 0; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXRoom.java b/game_pk_chuntian/src/main/java/extend/pk/EXRoom.java new file mode 100644 index 0000000..d2b0a40 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXRoom.java @@ -0,0 +1,322 @@ +package extend.pk; + +import com.game.Global; +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.TArray; +import com.taurus.core.entity.TObject; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EXRoom extends Room { + public RoomCard card; + + /**上次打牌的座位*/ + public int lastDiscardSeat; + + /**打出牌的集合 */ + public CardGroup discard; + + public EXPlayer win; + + public int firstCard = 0; + + public Map card_config_map; + + public int piaoCount = 0; + + public List> supCards; + public List targetCards; + public int adminSeat = 0; + + public int baochunstate = -1; + + public int baochunSeat = 0; + + public int shachunSeat = 0; + + public int chooseover = 0; + + public int ziranchunover = 0 ; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this,10,maxPlayers,this.config.getInt(Config.ROOM_CONFIG_SELECTDIQU)); + card_config_map = new HashMap(); + card_config_map.put(CardConfig.DAN.type, CardConfig.DAN); + card_config_map.put(CardConfig.DUIZI.type, CardConfig.DUIZI); + card_config_map.put(CardConfig.LIANDUI.type, CardConfig.LIANDUI); + card_config_map.put(CardConfig.SHUNZI.type, CardConfig.SHUNZI); + card_config_map.put(CardConfig.ZHA.type, CardConfig.ZHA); + card_config_map.put(CardConfig.FEIJI.type, CardConfig.FEIJI); + card_config_map.put(CardConfig.SAN_2.type, CardConfig.SAN_2); + card_config_map.put(CardConfig.SI_1.type, CardConfig.SI_1); + card_config_map.put(CardConfig.TUOLAJI.type, CardConfig.TUOLAJI); + card_config_map.put(CardConfig.SANTIAO.type, CardConfig.SANTIAO); + + 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); + } + + this.isEntrust = true; + this.supCards = new ArrayList<>(); + this.targetCards = new ArrayList<>(); + this.adminSeat = 0; + this.chooseover = 0; + } + + public void clear() { + super.clear(); + } + + public void clearEx() { + this.activeSeat = 0; + this.discard = null; + this.lastDiscardSeat = 0; + this.win = null; + this.firstCard = 0; + this.baochunSeat = 0; + this.baochunstate = -1; + this.shachunSeat = 0; + this.ziranchunover = 0; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = super.getReloadInfo(player); + EXPlayer p = (EXPlayer) player; + + data.putTArray("hand_card", CardUtil.toTArray(p.cardInhand)); + + data.putTArray("handCards", CardUtil.toTArray(p.cardInhand)); + data.putTArray("outCards", CardUtil.toTArray(p.outCards)); + + data.putInt("open", p.open); + + data.putInt("last_outcard_seat", this.lastDiscardSeat); + + // 游戏结束 + if(this.isplaying == false) { + + if(this.win != null) { + data.putInt("winseat", this.win.seat); + } + else + { + data.putInt("winseat", 0); + } + if(this.card.getCount() > 0) { + data.putTArray("remaincards", CardUtil.toTArray(this.card.cardList)); + } + } + + return data; + } + + /** + * + * */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } + + public void addScore(Player destPlayer, Player fromPlayer, int score, int type) { + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int)fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + // + + 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; + } + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void addAllBombScore(EXPlayer destPlayer) { + + destPlayer.settleLog.add(Config.SETTLE_BOMB_COUNT); + destPlayer.boomnum++; + + TArray seatData=TArray.newInstance(); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + ITObject seatListData = TObject.newInstance(); + /*if(fromPlayer != destPlayer) { + // this.addScore(destPlayer, fromPlayer, 10, EXScore.ZHA); + seatListData.putInt("bom_score", -10); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + }else{ + seatListData.putInt("bom_score", 20); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + }*/ + } + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_BOM_SCORE, allData); + } + + /** + * 变更游戏积分 + * @param destPlayer + */ + public void addAllScore(Player destPlayer) { + + EXPlayer dp = (EXPlayer)destPlayer; + EXRoom room = dp.getRoom(); + boolean bSpring = false; + Global.logger.info("room.shachunSeat:"+room.shachunSeat); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + if(fromPlayer != destPlayer) { + + if(fromPlayer.cardInhand.size()>0) { + + int size = fromPlayer.cardInhand.size(); + int score = size; + + if (size==10){ + score = 20; + } + if (room.shachunSeat!=0){ + score = 20; + } + if (dp.ziranchun==1){ + score = 40; + } + if ((fromPlayer.seat == room.bankerSeat)&&(fromPlayer.dis_times==1)){ + score = 20; + } + Global.logger.info("fromPlayer:"+fromPlayer.playerid+"room.shachunSeat:"+room.shachunSeat); + Global.logger.info("score:"+score); + this.addScore(destPlayer, fromPlayer, score, EXScore.WIN); + } + } + } + + // 设置玩家的当初最大分数 + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + + if(destPlayer == player) { + player.settleLog.add(Config.SETTLE_WIN_COUNT); + } + + if(player.score.round_score > player.settleLog.get(Config.SETTLE_MAX_SCORE)) { + player.settleLog.put(Config.SETTLE_MAX_SCORE, player.score.round_score); + } + } + // 增加玩家春天的个数 + if(bSpring) { + dp.settleLog.add(Config.SETTLE_CHUNTIAN_COUNT); + } + + if(totalType()) { + + + int maxTotalScore = 0; + int maxTotalCount = 0; + + for (Entry entry : this.playerMapBySeat.entrySet()) { + + Player player = entry.getValue(); + + if(player.score.total_score > maxTotalScore) { + + maxTotalScore = player.score.total_score; + maxTotalCount = 1; + } + else if(player.score.total_score == maxTotalScore && maxTotalScore > 0) { + + maxTotalCount++; + } + } + + // 如果存在大赢家 + if(maxTotalScore > 0 && maxTotalCount > 0) { + + for (Entry entry : this.playerMapBySeat.entrySet()) { + + EXPlayer player = (EXPlayer)entry.getValue(); + + } + } + + } + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + @Override + public void endGame() { + addAllScore(win); + + this.chooseover = 0; + + EXPlayBack pb = (EXPlayBack)this.playBackData; + + Global.logger.error("EXRoom: endGame"); + ITObject pbResult = TObject.newInstance(); + + ITArray info = new TArray(); + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.round_score); + obj.putBoolean("entrust", player.entrust); + info.addTObject(obj); + } + pbResult.putTArray("result", info); + Global.logger.error("pbResult:"+pbResult); + pb.addResultCommand(win.seat, pbResult); + + pb.addNewRoundCommand(); + + Global.logger.error("end maxRound:"+this.maxRound); + Global.logger.error("end game:"+this.round); + super.endGame(); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/EXScore.java b/game_pk_chuntian/src/main/java/extend/pk/EXScore.java new file mode 100644 index 0000000..fc4343f --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/EXScore.java @@ -0,0 +1,18 @@ +package extend.pk; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + public static final int ZHA = 2; + + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(ZHA, 0); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/RoomCard.java b/game_pk_chuntian/src/main/java/extend/pk/RoomCard.java new file mode 100644 index 0000000..b791ae3 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/RoomCard.java @@ -0,0 +1,779 @@ +package extend.pk; + +import com.game.Global; +import extend.pk.uitl.CardUtil; + +import java.util.*; + +public class RoomCard { + + public static final int HEART_TEN = 310; + public static final int CARD_A = 14; + public static final int CARD_2 = 15; + public static final int CARD_3 = 3; + public List cardList; + public List cardListTemp; + EXRoom room; + int num; + int maxPlayer; + int selectDiqu; + Random rand = new Random(); + + int boomNumLimit = rand.nextInt(2) + 2; + int sangzhangNumLimit = rand.nextInt(5) + 10; + + int totalBoomNum = 0; + int totalSanZhangNum = 0; + + public RoomCard(EXRoom table,int num,int maxPlayer,int selectDiqu) { + Global.logger.info("RoomCard"); + this.cardList = new ArrayList(); + this.cardListTemp = new ArrayList(); + this.room = table; + this.num = num; + this.maxPlayer = maxPlayer; + this.selectDiqu = selectDiqu; + Global.logger.info("RoomCard:"); + } + + public void init() { + Global.logger.info("dealcards init:"); + this.boomNumLimit = rand.nextInt(2) + 2; + + this.sangzhangNumLimit = rand.nextInt(5) + 10; + + this.totalBoomNum = 0; + this.totalSanZhangNum = 0; + this.cardList.clear(); + Global.logger.info("dealcards init:"+this.boomNumLimit); + this.initCard(); + int currentBoomNum = 0; + int currentSanZhangNum = 0; + + Map result = new HashMap(); + do { + currentBoomNum = 0; + currentSanZhangNum = 0; + this.shuffle(); + for(int i = 0; i entry : result.entrySet()) { + if(entry.getValue() >= 4) { + currentBoomNum++; + } + else if(entry.getValue() == 3) { + currentSanZhangNum++; + } + } + } + } + }while((currentBoomNum + totalBoomNum > boomNumLimit) || (currentSanZhangNum + totalSanZhangNum > sangzhangNumLimit)); + } + + private void initCard() { + for (int index = 3; index <= 15; index++) { + // 方片 + + if(selectDiqu==0){ + if (index<12){ + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + }else{ + this.cardList.add(new CardObj(400 + index)); + } + + }else{ + if (index>4&&index!=15){ + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + } + } + + + + + rand.setSeed(System.currentTimeMillis()); + int len = this.cardList.size(); + for(int i = 0; i < len; i++) { + + int randpos = rand.nextInt(1000000000) % len; + CardObj cotemp = this.cardList.get(i); + + this.cardList.set(i, this.cardList.get(randpos)); + this.cardList.set(randpos,cotemp); + } + + Global.logger.info("RoomCard initCard(): "+this.cardList+"selectDiqu:"+selectDiqu); + } + + private void shuffle() { + for(int i = 0; i < 100; i++) + { + Collections.shuffle(this.cardList); + } + Random rand = new Random(); + int len = this.cardList.size(); + + for(int i = 0; i < 10000; i++) { + rand.setSeed(System.currentTimeMillis()); + int start = rand.nextInt(len); + int end = rand.nextInt(len); + + CardObj co = this.cardList.get(start); + this.cardList.set(start, this.cardList.get(end)); + this.cardList.set(end, co); + } + } + + public CardObj pop() { + CardObj card = this.cardList.remove(0); + return card; + } + + public int getCount() { + return this.cardList.size(); + } + + public List deal0(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(313)); + dealCards.add(new CardObj(311)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(208)); + + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(411)); + dealCards.add(new CardObj(311)); + + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(304)); + dealCards.add(new CardObj(303)); + } + + return dealCards; + } + + public List deal1(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + dealCards.add(new CardObj(303)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + } + + return dealCards; + } + + + public List deal2(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(205)); + dealCards.add(new CardObj(305)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(110)); + + } + else if(seat == 2) { + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + + //dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal3(int seat){ + + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(111)); + dealCards.add(new CardObj(112)); + dealCards.add(new CardObj(113)); + dealCards.add(new CardObj(114)); + dealCards.add(new CardObj(215)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal4(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(308)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(410)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal6(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(105)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(106)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(109)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List dealTest(int seat){ + + List dealCards = deal2(seat); + if(dealCards == null || dealCards.size() == 0) { + + dealCards = deal(); + } + + return dealCards; + } + + // 发牌 + public List deal(boolean room_white, boolean is_white, double room_rate, int white_black_status, double black_white_rate, double black_black_rate, int maxDanPai, int maxDuizi, int maxSanZhang) { + List dealCards = new ArrayList(); + + shuffle(); + + double rand1 = Math.random() % 100 * 100; + for (int index = 0; index < this.num ; index++) { + if (room_white && is_white) + { + if (rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards xingyun card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (white_black_status == 2) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards white card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else if (white_black_status == 1) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards black card"); + } + } +; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, true, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, true, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (room_white && rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + } + } + } + shuffle(); + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + + boolean isGooodCard(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + if (isGooodCard2(card, dealCards, black, maxDanPai, maxDuizi, maxSanZhang)) { + return true; + } + + if (maxDanPai != 0) + { + if (card >= maxDanPai) + { + return true; + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 1)) { + if (card >= maxDuizi) + { + return true; + } + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 2)) { + if (card >= maxSanZhang) + { + return true; + } + } + } + + return false; + } + + boolean isGooodCard2(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + double rand = Math.random() % 100 * 100; + if (black) + { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 70) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 70) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 70) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 70) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 70) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 50) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 50) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 50) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 50) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 50) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + + + return false; + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < this.num ; index++) { + dealCards.add(this.pop()); + } + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/SettleLog.java b/game_pk_chuntian/src/main/java/extend/pk/SettleLog.java new file mode 100644 index 0000000..86b78c6 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/SettleLog.java @@ -0,0 +1,44 @@ +package extend.pk; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java new file mode 100644 index 0000000..95575da --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java @@ -0,0 +1,149 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.pk.*; + + +import java.util.Map; + + +/** + * + */ +public class EXPlayerBaoChunState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + Global.logger.error("EXPlayerBaoChunState enter"); + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.baoChunTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + + EXMainServer.gameCtr.baoChunTipEvent(owner,1); + + owner.startActionTimer(); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + + + + + private void _action(EXPlayer owner,int id,int gid) { + owner.baochun = id; + EXRoom room = owner.getRoom(); + + int tmp = 0; + if (id==0){ + //不报春 + }else { + //获得报春最近的 + if(room.baochunSeat==0){ + room.baochunSeat = owner.seat; + }else{ + if(room.bankerSeat==room.maxPlayers){ + if((room.bankerSeat-room.baochunSeat)>(room.bankerSeat-owner.seat)){ + room.baochunSeat = owner.seat; + } + }else{ + if((room.baochunSeat-room.bankerSeat)<(owner.seat-room.bankerSeat)){ + room.baochunSeat = owner.seat; + } + } + } + } + Global.logger.info("EXRoom room maxPlayers:"+ room.maxPlayers); + Global.logger.info("EXRoom room bankerSeat:"+ room.bankerSeat); + Global.logger.info("EXRoom room activeSeat:"+ room.activeSeat); + Global.logger.info("Player room nextSeat:"+ owner.nextSeat); + + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat!=room.bankerSeat){ + Global.logger.info("baochun Player id:"+ player.playerid); + if (player.baochun==-1){ + tmp = -1; + } + } + } + // + + //owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Global.logger.error("EXPlayerBaoChunState id:"+id); + if (tmp==0){ + //全部选择完 + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + if (room.baochunSeat>0){ + //有人报春,庄家是否抢? + Global.logger.info("EXPlayerBaoChunState baochunSeat:"+room.baochunSeat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerTongYiBaoChunState.class)); + }else{ + //无人报春,庄家先出 + Global.logger.info("EXPlayerBaoChunState 开牌:"+room.baochunSeat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + + private void _tyaction(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + if (id==0){ + //庄家自己报春, + room.baochunSeat = room.bankerSeat; + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + }else { + //报春者报春 + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat==room.baochunSeat){ + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + Global.logger.error("EXPlayerBaoChunState cmd: "+cmd); + if (cmd.equals(EXActionEvent.EVENT_BAO_CHUN)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("baochun"); + _action(owner, id, gid); + }else if(cmd.equals(EXActionEvent.EVENT_TONGYI_BAO_CHUN)){ + ITObject netParam = (ITObject) param; + int id = netParam.getInt("tongyi"); + _tyaction(owner, id, gid); + }else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner, 0, gid); + } else if (cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} \ No newline at end of file diff --git a/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..fa16aa6 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java @@ -0,0 +1,380 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.Router; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.pk.*; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.uitl.CardCheck; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * 等待玩家出牌状态 + * + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + // 设置防作弊场开牌的标志 + owner.open = 1; + + EXRoom room = owner.getRoom(); + + //如果最后一次打牌的座位等于自己 并且牌型是炸弹 + if(room.lastDiscardSeat == owner.seat&&room.discard.config == CardConfig.ZHA) { + + room.addAllBombScore(owner);//炸弹玩家增加积分 + } + + //如果最后一次的打牌的座位不等于零并且最后一次打牌的座位不等于自己 + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + boolean bNextBaodan = false; + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + bNextBaodan = true; + } + CardGroup big_ct = CardCheck.genOutCard(owner.cardInhand, room.discard,room.config,bNextBaodan); + if(big_ct==null) { + Global.logger.error("big_ct: pass state"); + owner.stateMachine.changeState(Global.getState(EXPlayerPassState.class)); + return; + } + else { + + if(big_ct.config.type == Config.TYPE_ZHA ) { + // 如果能出完,就自动出完 + if(big_ct.card_list.size() == owner.cardInhand.size()) { + + doAction(owner,big_ct,true); + return; + } + } + else { + + boolean bContainZha = false; + + + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = cardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + bContainZha = true; + } + + + } + + if(big_ct.card_list.size() == owner.cardInhand.size() && bContainZha == false) { + doAction(owner,big_ct,true); + return; + } + } + } + } + else { + + // 自动出牌 + CardGroup auto_ct = CardCheck.autoOutLastHand(owner.cardInhand, room.config,false); + if(auto_ct != null) { + doAction(owner,auto_ct,true); + return; + } + } + EXMainServer.gameCtr.discardTipEvent(owner); + + owner.startActionTimer(); + } + + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.win = owner; + room.baochunstate = -1; + Global.logger.error("EXPlayerDiscard: over"); + room.endGame(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + + ITObject netParam = (ITObject) param; + ITArray card_list = netParam.getTArray("card"); + ITArray all_card = netParam.getTArray("all_card"); + + if (all_card != null) + { + ArrayList temCardList = new ArrayList(); + for(int i=0;i< all_card.size();++i) { + temCardList.add(all_card.getInt(i)); + } + Collections.sort(temCardList); + + ArrayList temCardList2 = new ArrayList(); + for(int i=0;i< owner.cardInhand.size();++i) { + temCardList2.add(owner.cardInhand.get(i).card); + } + Collections.sort(temCardList2); + + if (!temCardList.equals(temCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + Global.logger.info("EXPlayer discard:"); + // 如果出的牌的个数为0 或者大于手牌的数目 则是非法的 + if (card_list.size() == 0 || card_list.size() > owner.cardInhand.size()) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + List list = CardUtil.toList(card_list); + + + for(CardObj card : list) { + + boolean bNotExisted = false; + + for(CardObj handc : owner.cardInhand) { + if(card.card == handc.card) { + bNotExisted = true; + break; + } + } + + if(bNotExisted == false) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + if(owner.getRoom().firstCard != 0 && CardUtil.getCard1(owner.getRoom().firstCard, list) == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MIN); + return; + } + + CardGroup ct = CardCheck.getType(list, owner.room.config); + + if (ct == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + + + Global.logger.info("EXPlayer discard:2"); + //验证客户端发过来的类型 + if(!CardCheck.tryType(ct,owner.cardInhand.size(),owner.room.config)) { + + // tryType 判断3条a判断不出来, 所以 + if(!(ct.config.type == Config.TYPE_ZHA && + card_list.size() == 3 )) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + + //判断是否用A,2 + owner.dis_times = owner.dis_times + 1; + + Global.logger.info("EXPlayer discard:3,{}"+owner.dis_times); + doAction(owner,ct,false); + break; + + case EXActionEvent.EVENT_PASS: + pass(owner); + + break; + case EXActionEvent.EVENT_OFFLINE: + owner.startActionTimer(); + break; + case EXActionEvent.EVENT_TIMER_AUTO: + case EXActionEvent.EVENT_ENTRUST: + + AutoOut(owner); + break; + } + } + + private void AutoOut(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + CardGroup big_ct = null; + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && room.discard.config.type ==Config.TYPE_DANPAI && playerNext.cardInhand.size() == 1) { + + Map> cardMap =CardUtil.getCardListMap(owner.cardInhand); + big_ct = CardCheck.selectDanpai(cardMap,room.discard,room.config,true); + }else { + big_ct = CardCheck.tryBig(owner.cardInhand, room.discard); + } + + if (big_ct != null) { + big_ct.card_list_mp = CardUtil.toTArray(big_ct.card_list); + doAction(owner,big_ct,true); + } else { + Global.logger.info("big_ct == null pass !!!!!!!!!!!!"); + pass(owner); + } + + }else { + + // 在托管或者自动出牌的时候 系统先出炸弹,如果炸弹没有 再出单张 + // 将来可以把这个函数做的能智能一些,不光可以出炸弹 也可以出顺子飞机等等 + CardGroup out_ct = CardCheck.autoOut(owner.cardInhand, owner.room.config); + if(out_ct == null) { + + out_ct = new CardGroup(); + List out_list = new ArrayList<>(); + out_ct.card_list = out_list; + out_ct.config = CardConfig.DAN; + out_ct.len = 1; + + if(room.firstCard != 0) { + CardObj co = CardUtil.getCard1(room.firstCard, owner.cardInhand); + out_list.add(co); + } + else + { + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + out_list.add(owner.cardInhand.get(owner.cardInhand.size() -1)); + }else { + out_list.add(owner.cardInhand.get(0)); + } + } + } + + out_ct.card_list_mp = CardUtil.toTArray(out_ct.card_list); + out_ct.min_card = out_ct.card_list.get(0).cardMod; + + doAction(owner,out_ct,true); + } + } + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + private void doAction(EXPlayer owner,CardGroup ct,boolean skip) { + + EXRoom room = owner.getRoom(); + + boolean outcard = true; + + if(ct.config.type==Config.TYPE_SHUNZI){ + + boolean cf = false; + List cardOut = ct.card_list; + for (int i = 0; i< cardOut.size(); i++){ + if (cardOut.get(i).cardMod==2){ + cardOut.get(i).card = cardOut.get(i).card+13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod+13; + cf = true; + } + if (cardOut.get(i).cardMod==1){ + cardOut.get(i).card = cardOut.get(i).card+13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod+13; + cf = true; + } + } + if(cf){ + ct.card_list = cardOut; + ct.card_list_mp = CardUtil.toTArray(cardOut); + } + } + + if(!skip) { + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + outcard = CardCheck.tryCompete(room.discard, ct,room.config); + } + + // 如果玩家的下家只有一张牌,玩家出单张必须是最大的 + if(outcard && ct.config.type == Config.TYPE_DANPAI) { + + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && playerNext.cardInhand.size() == 1) { + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Integer number : cardMap.keySet()) { + + if(ct.min_card < number) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MAX); + return; + } + } + } + } + } + if(!outcard) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + + EXMainServer.gameCtr.outCard(owner,ct); + + if (room.baochunSeat!=0&&owner.seat!=room.baochunSeat){ + room.shachunSeat = owner.seat; + this.over(owner); + return; + } + + if (owner.cardInhand.size() == 0) { + this.over(owner); + return; + } else { + this.toNextState(owner); + } + } + + +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPassState.java b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPassState.java new file mode 100644 index 0000000..176aef1 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPassState.java @@ -0,0 +1,51 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; + +/** + * 等待玩家Pass状态 + * + * + */ +public class EXPlayerPassState extends StateBase { + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if(!owner.entrust) { + Timer passTimer = new Timer(1000, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + pass(owner); + } + }); + room.addTimer(passTimer); + }else { + pass(owner); + } + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..4df7620 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,52 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import extend.pk.EXPlayer; + + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java new file mode 100644 index 0000000..49f703e --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java @@ -0,0 +1,83 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map; + + +/** + * + */ +public class EXPlayerTongYiBaoChunState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + Global.logger.error("EXPlayerTongYiBaoChunState enter"); + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tongYiBaoChunTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + + EXMainServer.gameCtr.tongYiBaoChunTipEvent(owner,1); + + owner.startActionTimer(); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + private void _tyaction(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + if (id==0){ + //庄家自己报春, + room.baochunSeat = room.bankerSeat; + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + }else { + //报春者报春 + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat==room.baochunSeat){ + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + // owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + Global.logger.error("EXPlayerTongYiBaoChunState cmd: "+cmd); + if(cmd.equals(EXActionEvent.EVENT_TONGYI_BAO_CHUN)){ + ITObject netParam = (ITObject) param; + int id = netParam.getInt("tongyi"); + _tyaction(owner, id, gid); + } else if (cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} \ No newline at end of file diff --git a/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java new file mode 100644 index 0000000..497a1f4 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java @@ -0,0 +1,52 @@ +package extend.pk.room.state; + +import com.game.Global; + +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerBaoChunState; +import extend.pk.uitl.CardCheck; + +import java.util.Map; + + +public class EXRoomBaoChunState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Global.logger.error("EXRoomBaoChunState enter"); + + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + + //检测是否自然春: + Boolean ziRanChun = CardCheck.CheckZiRanChun(player.cardInhand,owner.config); + if (ziRanChun){ + //自然春,不用报春直接倒牌 + player.ziranchun = 1; + owner.ziranchunover = 1; + this.over(player); + return; + } + + + if (owner.bankerSeat!=player.seat){ + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerBaoChunState.class)); + } + } + + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + room.win = owner; + room.baochunstate = -1; + Global.logger.error("EXPlayerDiscard: over"); + room.endGame(); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomDealState.java b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomDealState.java new file mode 100644 index 0000000..1da958d --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomDealState.java @@ -0,0 +1,89 @@ +package extend.pk.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.permanent.TPServer; +import extend.pk.*; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 房间发牌状态 + * + * + */ +public class EXRoomDealState extends StateBase { + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 3000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //owner.card.init(); + if(owner.bankerSeat!=0&&!owner.playerMapBySeat.containsKey(owner.bankerSeat)) { + owner.bankerSeat = 0; + } + EXMainServer.gameCtr.dealCard(owner); + + owner.playBackData = new EXPlayBack(owner); + + Global.logger.error("deal room tonextstate"); + //定庄家 + + if(owner.baochunstate<0){ + owner.stateMachine.changeState(Global.getState(EXRoomBaoChunState.class)); + } + // owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomPiaoState.java b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..c0e797b --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomPiaoState.java @@ -0,0 +1,25 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; + +import java.util.Map.Entry; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomSetpState.java b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..531cdcf --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomSetpState.java @@ -0,0 +1,36 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDiscardState; + +/** + * 房间转换座位 + * + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + + + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomStartGameState.java b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..2c5cae6 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/room/state/EXRoomStartGameState.java @@ -0,0 +1,38 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map.Entry; + +/** + * 房间开始状态 + * + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.clearEx(); + } + owner.clearEx(); + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/uitl/CardCheck.java b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardCheck.java new file mode 100644 index 0000000..e07c502 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardCheck.java @@ -0,0 +1,1440 @@ +package extend.pk.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +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.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.RoomCard; + + +/** + * + * + */ +public class CardCheck { + + /** + * 服务器跟牌判定 + * @param cardInhand + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup genOutCard(List cardInhand,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + + CardGroup cg = null; + //Global.logger.info("genoutcard:"+cardInhand+",out:"+out); + Map> cardMap =CardUtil.getCardListMap(cardInhand); + int handCardSize = cardInhand.size(); + // 如果有炸弹 并且玩家手上仅剩下炸弹 就不用找了 直接出牌就可以了 + cg = selectZha(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + //如果有推土机 就不用找了 直接出牌就可以了 + if (out.config.type!=Config.TYPE_ZHA){ + CardGroup tempCg = selectTuolaji(cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是一张单牌,则寻找一个合适的单牌,如果找不到就用炸弹,炸弹没有则过 + if(out.config.type == Config.TYPE_DANPAI) { + + CardGroup tempCg = selectDanpai(cardMap,out,roomConfig,nextBaodan); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是不能带牌的牌型(对子,顺子,连队)则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_DUIZI + || out.config.type == Config.TYPE_SHUNZI + || out.config.type == Config.TYPE_LIANDUI) { + + CardGroup tempCg = selectWithoutCardType(handCardSize,cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的三带牌型 ,则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_3_2) { + + boolean bLack = false; + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的飞机牌型,则寻找合适的牌型,如果找不到用则炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_FEIJI) { + + boolean bLack = false; + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果是四带二或者四带三 就不处理了,如果有炸弹,则玩家自己去选择是炸还是跟,如果没有炸弹 玩家也大不了,所以后面就不用判断了 + if(cg != null) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + return cg; + } + + public static Boolean CheckZiRanChun(List cardInhand,ITObject roomConfig){ + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + System.out.println(cardMap); + + int len = cardInhand.size(); + + cg = checkFeiji(len,cardMap,roomConfig,false); + if (cg!=null){ + return true; + } + + cg = checkShunzi(len,cardMap,roomConfig); + if (cg!=null){ + return true; + } + + //检查5对 + cg = checkWudui(len,cardMap,roomConfig); + System.out.println(cg); + if (cg!=null){ + return true; + } + return false; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectZha(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + + boolean bThreeA = false; + + int minValue = 0; + if(out.config.type == Config.TYPE_ZHA) { + minValue = out.min_card; + } + + for(Map.Entry> entry : cardMap.entrySet()) { + + if(entry.getValue().size() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA && entry.getValue().size() == 3)) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + + return cg; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectTuolaji(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + int minValue = 0; + if(out.config.type == Config.TYPE_TUOLAJI) { + minValue = out.min_card; + } + + int minCard = 0; + int maxCard = 0; + int count = 0; + int len = 3; + System.out.println("mimvalue:"+minValue); + System.out.println(cardMap); + ArrayList temp = new ArrayList<>(); + ArrayList ctp = new ArrayList<>(); + for(Map.Entry> entry : cardMap.entrySet()) { + System.out.println(entry.getValue()); + if(entry.getValue().size() >= 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + count++; + ctp.add(entry.getKey()); + temp.addAll(entry.getValue()); + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + if (count>=3){ + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + break; + } + } + + } + + + } + if(count>len){ + //如果对子大于3对 + if (((int) ctp.get(2)==(int)ctp.get(1)+1)&&((int) ctp.get(1)-(int) ctp.get(0)==1)){ + //也是拖拉机 + + temp.remove(temp.size()-1); + temp.remove(temp.size()-1); + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + } + + if (((int) ctp.get(3)==(int)ctp.get(2)+1)&&((int) ctp.get(2)-(int) ctp.get(1)==1)){ + //也是拖拉机 + temp.remove(0); + temp.remove(0); + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + } + + } + + if(cg==null){ + return null; + } + if(minValue>=cg.min_card){ + return null; + } + + return cg; + } + + /** + * 选择单牌 + * @param cardMap + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup selectDanpai(Map> cardMap,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + int minValue = out.min_card + 1; + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + if(!nextBaodan) { + + for(int i = minValue; i <= 15; i++) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3 ))) { + + } + else { + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + else + { + for(int i = 15; i >= minValue; i--) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3))) { + + } + else { + + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + + return cg; + } + + /** + * 选择不需要带牌的牌型 + * @param handCardSize + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectWithoutCardType(int handCardSize,Map> cardMap,CardGroup out,ITObject roomConfig) { + CardGroup cg = null; + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>14)) { + + int count =0; + + for(int i = min_card; i <= 14;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >=out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + private static CardGroup selectWithCardType(List cardInhand, + Map> cardMap, + CardGroup out, + ITObject roomConfig, + boolean bLack) { + + CardGroup cg = null; + + int handCardSize = cardInhand.size(); + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>15)) { + + int count =0; + + for(int i = min_card; i <= 15;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >= out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + int sd = out.config.repeat_num * len + out.config.with_card_num * len; + + + + if(bLack == false && handCardSize < sd) { + + return cg; + } + + + // 新建一个临时的列表,来保存剩余的牌 + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + // 如果剩余的牌有炸弹,则需要把剩余牌中的炸弹对应的牌从临时列表中剔除,以确定是否有足够的单牌 + // 如果因为剔除的原因,最后牌型不能做成,那就提示他有炸弹出就可以了 + Map> reservedCardMap = CardUtil.getCardListMap(tem_list); + int duiNum = 0; + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num == 4 || (entry.getKey() == RoomCard.CARD_A && bThreeA && num == 3)) { + + CardUtil.removeCard(tem_list, entry.getValue()); + } + + if(num >= 2) { + duiNum++; + } + } + + + + + // 如果手牌数多于牌型的基本要求 + if(handCardSize >= sd) { + + if(tem_list.size() < out.config.with_card_num * len) { + return cg; + } + + for(int m = 0; m < out.config.with_card_num * len; m++) { + card_list.add(tem_list.get(m)); + } + } + else { + + card_list.addAll(tem_list); + } + + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + /** + * 得到所出牌的牌型 + * @param cardOut + * @param roomConfig + * @return + */ + public static CardGroup getType(List cardOut,ITObject roomConfig) { + + CardGroup cg = autoOutLastHand(cardOut,roomConfig,true); + System.out.println(cg); + if(cg==null){ + boolean cf = false; + for (int i = 0; i< cardOut.size(); i++){ + if (cardOut.get(i).cardMod==15){ + cardOut.get(i).card = cardOut.get(i).card-13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod-13; + cf = true; + } + if (cardOut.get(i).cardMod==14){ + cardOut.get(i).card = cardOut.get(i).card-13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod-13; + cf = true; + } + } + if (cf){ + cg = autoOutLastHand(cardOut, roomConfig,true ); + } + } + + if(cg == null) { + int len = cardOut.size(); + int sidai = roomConfig.getInt(Config.ROOM_CONFIG_SIDAIYI); + // 看看所处的牌是否 4带2 或者4带3 + if((len == 5 && sidai == 1)) { + + Map cardMap =CardUtil.getCardNumMap(cardOut); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + + cg.config = CardConfig.SI_1; + + + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj : cardOut) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + } + } + } +// Global.logger.info("getType:{}"+cg); + return cg; + } + + /** + * + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOutLastHand(List cardInhand,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + int len = cardInhand.size(); +// Global.logger.info("autoOutLastHand len:"+len); + if(len == 1) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DAN; + cg.min_card = cardInhand.get(0).cardMod; + cg.len = 1; + } + else if(len == 2) { + cg = checkTwo(cardMap); + } + else if(len == 3) { + cg = checkThree(cardMap,roomConfig); + } + else if(len == 4) { + cg = checkFour(cardMap,roomConfig); + } + else if(len == 5) { + cg = checkFive(cardMap,roomConfig,bSpecial); + }else{ + if (cg == null) { + cg = checkShunzi(len,cardMap,roomConfig); + if(cg == null&&len%2==0) { + cg = checkTuoLaJi(len,cardMap,roomConfig); + if(cg == null) { + + cg = checkFeiji(len,cardMap,roomConfig,bSpecial); + } + } + } + } + + if(cg != null) { + + for(CardObj cardObj : cardInhand) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + private static int getMaxCardNum(Map cardMap) { + int maxNum = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue() > maxNum) { + maxNum = entry.getValue(); + } + } + + return maxNum; + } + + public static boolean isConfig4_2_and_4_3(ITObject roomConfig) { + + return false; + + } + + private static CardGroup checkTwo(Map cardMap) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DUIZI; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + return cg; + } + + private static CardGroup checkThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SANTIAO; + cg.min_card = entry.getKey(); + cg.len = 3; + }else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 3 && minCard != 0 && maxCard != 0 && minCard + 2 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 3; + } + } + } + return cg; + } + + private static CardGroup checkFour(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + }else if(entry.getValue() == 3) { + + /*boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + }*/ + + if(entry.getKey() == RoomCard.CARD_A ) { + return cg; + } + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + if(minCard != 0 && maxCard != 0 && minCard + 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = 2; + } + }else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2){ + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 4 && minCard != 0 && maxCard != 0 && minCard + 3 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 4; + } + } + } + return cg; + } + + private static CardGroup checkFive(Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_1; + cg.min_card = entry.getKey(); + cg.len = 1; + + }else if(entry.getValue() == 3 /*|| (entry.getValue() == 4 && bSpecial == true)*/) { + + if(entry.getValue() != 4 && cardMap.size() >= 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + } + else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 5 && minCard != 0 && maxCard != 0 && minCard + 4 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 5; + } + } + } + + return cg; + } + + private static CardGroup checkShunzi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkLiandui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + return cg; + } + + private static CardGroup checkWudui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue()==4){ + count=count+2; + }else if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + count++; + } + else + { + break; + } + } + if (count==5){ + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.WUDUI; + cg.min_card = minCard; + cg.len = 10; + + return cg; + } + return cg; + } + + private static CardGroup checkFeiji(int len,Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int[] cardThreeCount = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0}; + System.out.println("cardM:"+cardMap); + boolean bThreeA = false; + + int num2 = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + // 如果有炸弹 则不允许自动出牌 + if(bSpecial == false && (entry.getValue() == 4 || (entry.getKey() == RoomCard.CARD_A && entry.getValue() == 3 && bThreeA == true))) { + return cg; + } + + if(entry.getValue() >= 3) { + cardThreeCount[entry.getKey()] = 1; + } + else if(entry.getValue() == 2) { + num2++; + } + } + + + int left = 0; + int right = 0; + + for(int i = 4; i < cardThreeCount.length; i++) { + if(left == 0) { + + if(cardThreeCount[i] == 1 && cardThreeCount[i - 1] == 1) { + left = i - 1; + right = i; + } + } + else { + // 如果有连续的继续寻找 + if(cardThreeCount[i] == 1 && right + 1 == i) { + + right = i; + } + else + { + left = 0; + right = 0; + } + } + // 判断出来一个顺子,就判定一下是否可以全部出 + if(left != 0 && right != 0) { + + int threeCount = right - left + 1; + int sl = threeCount * 5; + + if(len <= sl) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + + + } + } + + return cg; + } + + /** + * 拖拉机 + */ + private static CardGroup checkTuoLaJi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = count; + } + } + } + + return cg; + } + + /** + * 自动出牌 + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOut(List cardInhand,ITObject roomConfig) { + + CardGroup cg = null; + + //支持3A炸弹 + boolean bThreeA = false; + + + // 寻找炸弹 + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA == true && entry.getValue() == 3)) { + + cg = new CardGroup(); + List out_list = new ArrayList<>(); + + cg.card_list = out_list; + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj :cardInhand) { + + if(cardObj.cardMod == entry.getKey()) { + out_list.add(cardObj); + } + } + } + } + + return cg; + } + + + /** + * 验证牌型 + * @param ct + * @param left_count + * @return + */ + public static boolean tryType(CardGroup ct,int left_count,ITObject roomConfig) { + List cardInhand = ct.card_list; + int size = cardInhand.size(); + CardConfig config = ct.config; + + if(size < config.min_card_num || size > config.max_card_num) { + return false; + } + int len = ct.len; + if(len 0 && size == left_count) { + + // 牌太少了 出牌太多了 + if(size < len * config.repeat_num || size > tem_size) { + return false; + } + // 如果带的牌不够 + if(size < tem_size) { + if(ct.config.type == Config.TYPE_3_2) { + + } + // 如果是飞机 + else if(ct.config.type == Config.TYPE_FEIJI) { + + } + } + + } + //没有带牌 没有全出 + else { + if(tem_size!=size) { + return false; + } + } + } + + if (config.type == Config.TYPE_3_0){ + //三 + return true; + } + + if (config.type == Config.TYPE_3_2){ + if(config.with_card_num==2){ + return true; + } + } + + if (config.type == Config.TYPE_TUOLAJI){ + return true; + } + + + int min_card = ct.min_card; + int max_card = min_card+len -1; + + if(len>1&&max_card>15) { + return false; + } + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + for(int i=min_card;i<=max_card;++i) { + if(!cardMap.containsKey(i)) { + return false; + } + if(cardMap.get(i) < config.repeat_num) { + return false; + } + } + return true; + } + + + + /** + * 比牌大小 + * @param banker + * @param other + * @return + */ + public final static boolean tryCompete(CardGroup banker, CardGroup other,ITObject roomConfig) { + int bankerCradType = banker.config.type; + int otherCradType = other.config.type; + + if(bankerCradType != Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) { + return true; + } + if(bankerCradType!= Config.TYPE_ZHA&&bankerCradType!=Config.TYPE_TUOLAJI && otherCradType == Config.TYPE_TUOLAJI){ + return true; + } + + if(bankerCradType != otherCradType) { + return false; + } + + if(other.min_card > banker.min_card) { + if(otherCradType == Config.TYPE_ZHA) { + return true; + } + else + { + + if(other.len == banker.len) { + + if(otherCradType == Config.TYPE_3_2 || otherCradType == Config.TYPE_FEIJI) { + + } + + return true; + } + else + { + return false; + } + } + } + + return false; + } + + + public final static CardGroup tryBig(List cardInhand,CardGroup other) { + + List card_list = new ArrayList(); + int size = cardInhand.size(); + CardConfig config = other.config; + Map> cardMap = null; + int len = other.len; + + if(size >= len*config.repeat_num) { + + int min_card = other.min_card + 1;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + + int max_card = min_card+len -1; //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + + if(!(len>1&&max_card>14)) {//长度如果大于一并且最大的牌 + + int count =0; + cardMap = CardUtil.getCardListMap(cardInhand); + int max = 15; + for(int i=min_card;i<=max;++i) { + + List list =cardMap.get(i); + + if(cardMap.containsKey(i)&&list.size() >=config.repeat_num) { + + //不出炸牌 + if(other.config.type !=Config.TYPE_ZHA && list.size()>=4) { + count=0; + card_list.clear(); + continue; + } + + for(int k=0;k0) { + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + //不把炸牌带出去 + int rcard_size = 0; + rcard: + for(int k=0;k tem_list1 = cardMap.get(card); + if(tem_list1.size()>=4) { + CardUtil.removeCard(tem_list, tem_list1); + rcard_size += 4; + break rcard; + } + } + int with_card_size = config.with_card_num * len; + if(rcard_size == 0) { + with_card_size = tem_list.size()=4) { + if(cardMap==null) { + cardMap = CardUtil.getCardListMap(cardInhand); + } + + for (Entry> entry : cardMap.entrySet()) { + int card = entry.getKey(); + List list = entry.getValue(); + if(list.size() >=4) { + CardGroup ct = new CardGroup(); + ct.config = CardConfig.ZHA; + ct.card_list = list; + ct.len = 1; + ct.min_card = card; + return ct; + } + } + } + return null; + } + + public static boolean checkStartSpring(List cardInhand) { + + boolean bRet = false; + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + if(cardMap.getOrDefault(RoomCard.CARD_3, 0) == 4) { + + bRet = true; + } + else if(cardMap.getOrDefault(RoomCard.CARD_2, 0) == 1 && cardMap.getOrDefault(RoomCard.CARD_A, 0) == 3){ + + bRet = true; + } + + + return bRet; + } + + + public static void main(String[] args) { + + ITObject test = new TObject(); + ITArray card_list = new TArray(); + ITArray card_list2 = new TArray(); + + card_list.addInt(206); + card_list.addInt(207); + card_list.addInt(308); + + + + card_list2.addInt(115); + + card_list2.addInt(214); + card_list2.addInt(213); + card_list2.addInt(203); + card_list2.addInt(210); + card_list2.addInt(209); + card_list2.addInt(307); + //card_list.addInt(207); + test.putInt("sidaiyi",0); + + List tlist2 = CardUtil.toList(card_list2); + List tlist = CardUtil.toList(card_list); + CardGroup ct = CardCheck.getType(tlist, test ); + //System.out.println(ct); + //System.out.println(CheckZiRanChun(tlist,test)); + /* + if(ct.config.type==Config.TYPE_SHUNZI&&ct.config.type==Config.TYPE_LIANDUI&&ct.config.type==Config.TYPE_TUOLAJI) { + boolean cf = false; + List cardOut = ct.card_list; + for (int i = 0; i < cardOut.size(); i++) { + if (cardOut.get(i).cardMod == 1) { + cardOut.get(i).card = cardOut.get(i).card + 13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod + 13; + cf = true; + } + if (cardOut.get(i).cardMod == 2) { + cardOut.get(i).card = cardOut.get(i).card + 13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod + 13; + cf = true; + } + } + if (cf) { + ct.card_list = cardOut; + } + }*/ + //ct.card_list = tlist; + //System.out.println(ct); + if (ct!=null){ + Boolean a = CardCheck.tryType(ct,4,test); + System.out.println("DO:"+a); + } + + if(ct!=null){ + CardGroup ct2 = CardCheck.genOutCard(tlist2, ct,test,false); + System.out.println("A:"+ct2); + } + // CardCheck.tryBig(); + //CardGroup ct = CardCheck.getType(list, owner.room.config); + + + + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/uitl/CardConfig.java b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardConfig.java new file mode 100644 index 0000000..4d6e7f6 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardConfig.java @@ -0,0 +1,44 @@ +package extend.pk.uitl; + +import extend.pk.Config; + +public enum CardConfig { + DAN( "单牌", Config.TYPE_DANPAI, 1, 1, 1, 1, 0), + DUIZI( "对子", Config.TYPE_DUIZI, 1, 2, 2, 2, 0), + SHUNZI( "顺子", Config.TYPE_SHUNZI, 3, 1, 3, 10, 0), + LIANDUI( "姐妹对", Config.TYPE_LIANDUI, 2, 2, 4, 10, 0), + SAN_2( "三带二", Config.TYPE_3_2, 1, 3, 3, 5, 2), + FEIJI( "飞机", Config.TYPE_FEIJI, 2, 3, 6, 10, 4), + SI_1( "四带一", Config.TYPE_4_1, 1, 4, 5, 5, 1), + SANTIAO( "三条", Config.TYPE_3_0, 3, 1, 3, 3, 0), + + TUOLAJI( "拖拉机", Config.TYPE_TUOLAJI, 3, 2, 6, 10, 0), + + WUDUI( "五小对", Config.TYPE_WUDUI, 10, 1, 10, 10, 0), + + ZHA( "炸弹", Config.TYPE_ZHA, 1, 4, 4, 4, 0); + + public final int type; + public final String name; + public final int min_len; + public final int repeat_num; + public final int min_card_num; + public final int max_card_num; + public final int with_card_num; + + + private CardConfig(String name,int type,int min_len,int repeat_num,int min_card_num,int max_card_num,int with_card_num) { + this.name = name; + this.type = type; + + this.min_len = min_len; + this.repeat_num = repeat_num; + this.min_card_num = min_card_num; + this.max_card_num = max_card_num; + this.with_card_num = with_card_num; + } + + public String toString() { + return this.name; + } +} diff --git a/game_pk_chuntian/src/main/java/extend/pk/uitl/CardUtil.java b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardUtil.java new file mode 100644 index 0000000..632e961 --- /dev/null +++ b/game_pk_chuntian/src/main/java/extend/pk/uitl/CardUtil.java @@ -0,0 +1,377 @@ +package extend.pk.uitl; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.pk.CardObj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CardUtil { + + + /** + * list to TArray + * + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (CardObj card : list) { + result.addInt(card.card); + } + return result; + } + + public static final CardObj getCard(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.cardMod == eventCard) { + return card; + } + } + return null; + } + + public static final CardObj getCard1(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.card == eventCard) { + return card; + } + } + return null; + } + + /** + * 检测牌数量 + * + * @param eventCard + * @param cardList + * @param num + * @return + */ + public static final boolean checkCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result == num) + return true; + } + } + return false; + } + + public static final boolean checkGoodCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result >= num) + return true; + } + } + return false; + } + + public static final boolean checkShunZi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + } + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkSevenShunzi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + + if (result >= 6) + { + return true; + } + return false; + } + + public static final boolean checkFenJi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+1, cardList, 3)) + { + result++; + } + if (checkGoodCard(eventCard-1, cardList, 3)) + { + result++; + } + } + + if (result >= 2) + { + return true; + } + return false; + } + + public static final boolean checkFourDui(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 1)) + { + result++; + } + + if (checkGoodCard(eventCard+1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 2)) + { + result++; + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 2)) + { + result++; + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkQPai(int eventCard, List cardList) { + int result = 0; + if (eventCard >= 12) + { + result++; + for (CardObj card : cardList) { + if (card.cardMod >= 12) { + result++; + } + } + } + + if (result >= 5) + { + return true; + } + return false; + } + + /** + * TArray to list + * @param list + * @return + */ + public static final List toList(ITArray list) { + List tem = new ArrayList(); + for(int i=0;i getCardNumMap(List cardList) { + Map result = new HashMap(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + return result; + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final void getCardNumMap(Map result,List cardList) { + result.clear(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + public static final void getCardNumMap(Map result,List cardList, CardObj tempCard) { + result.clear(); + result.put(tempCard.cardMod, 1); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final Map> getCardListMap(List cardList) { + Map> result = new HashMap>(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + List list = new ArrayList(); + list.add(card); + result.put(card.cardMod, list); + } else { + List list = result.get(card.cardMod); + list.add(card); + } + } + return result; + } + + static public void removeCard(List cardList, List cards) { + for (int i = 0; i < cards.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).card ==cards.get(i).card) { + cardList.remove(j); + break; + } + } + } + } +} diff --git a/game_pk_chuntian/src/test/java/game_pk_chuntian/Main.java b/game_pk_chuntian/src/test/java/game_pk_chuntian/Main.java new file mode 100644 index 0000000..81ed31b --- /dev/null +++ b/game_pk_chuntian/src/test/java/game_pk_chuntian/Main.java @@ -0,0 +1,9 @@ +package game_pk_chuntian; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_pk_dazhadan/config/game-config.xml b/game_pk_dazhadan/config/game-config.xml new file mode 100644 index 0000000..79b3420 --- /dev/null +++ b/game_pk_dazhadan/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.3.10 + 192.168.3.10 + 8641 + 8641 + 68 + true + \ No newline at end of file diff --git a/game_pk_dazhadan/config/log4j.properties b/game_pk_dazhadan/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_pk_dazhadan/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_pk_dazhadan/config/taurus-core.xml b/game_pk_dazhadan/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_pk_dazhadan/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_dazhadan/config/taurus-permanent.xml b/game_pk_dazhadan/config/taurus-permanent.xml new file mode 100644 index 0000000..7e70489 --- /dev/null +++ b/game_pk_dazhadan/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - test + extend.extend.pk.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_pk_dazhadan/pom.xml b/game_pk_dazhadan/pom.xml new file mode 100644 index 0000000..bd0d255 --- /dev/null +++ b/game_pk_dazhadan/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_pk_dazhadan + 1.0.0 + jar + + game_pk_dazhadan + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_pk_dazhadan + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_pk_dazhadan/src/main/java/extend/pk/CardGroup.java b/game_pk_dazhadan/src/main/java/extend/pk/CardGroup.java new file mode 100644 index 0000000..fc7ee92 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/CardGroup.java @@ -0,0 +1,45 @@ +package extend.pk; + +import java.util.List; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.pk.uitl.CardConfig; + +public class CardGroup { + /** + * 当前type + */ + public CardConfig config; + + public int min_card; + /** + * 长度 + */ + public int len = 1; + + public List card_list; + + public ITArray card_list_mp; + + public ITObject toObject(boolean card_size) { + ITObject obj = TObject.newInstance(); + if (card_size) { + obj.putInt("card_size", card_list.size()); + } else { + obj.putTArray("card_list", card_list_mp); + } + + obj.putInt("type", config.type); + obj.putInt("min_card", min_card); + obj.putInt("len", len); + return obj; + } + + public String toString() { + return "{type:" + config + " min_card:" + min_card + " len:" + len + " list:" + card_list + "}"; + } + +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/CardObj.java b/game_pk_dazhadan/src/main/java/extend/pk/CardObj.java new file mode 100644 index 0000000..bc2d762 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/CardObj.java @@ -0,0 +1,21 @@ +package extend.pk; + +public class CardObj implements Comparable{ + public int card; + public int cardMod; + + public CardObj(int card) { + this.card = card; + this.cardMod = card % 100; + } + + @Override + public int compareTo(CardObj paramT) { + return cardMod == paramT.cardMod ? 0 : cardMod < paramT.cardMod ? -1 : 1; + } + + @Override + public String toString() { + return card + ""; + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/Config.java b/game_pk_dazhadan/src/main/java/extend/pk/Config.java new file mode 100644 index 0000000..0f86729 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/Config.java @@ -0,0 +1,179 @@ +package extend.pk; + +public class Config { + /** + * 首局出牌规则 + */ + public static final String ROOM_CONFIG_RULE = "rule"; + + /** + * 第一局系统随机选一张先出,随后赢家先出 + */ + public static final int RULE_RANDOM = 2; + + /** + * 飘分玩法 + */ + public static final String ROOM_CONFIG_PIAO = "piao"; + + /** + * 打鸟 + */ + public static final String ROOM_CONFIG_DANIAO = "daniao"; + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + public static final String KE_BAO_PAI = "ke_bao_pai"; //可包牌 + public static final String XI_YA_SI_YOU_FEN = "xiyasi_youfen"; //喜压死有分 + public static final String QU_DIAO_34 = "qudiao_34"; //去掉34 + public static final String WU_ZHANG_SUAN_XI = "wu_zhang_suan_xi"; //五张算喜 + public static final String KE_ZUO_LIAN_ZI_2 = "kezuolianzi2"; //2可做连子 + public static final String THREE_WANG_SUAN_XI = "suan_wang_suan_xi"; //3王算喜 + public static final String KEYI_DAI_2 = "keyi3dai2"; //允许3带2 + public static final String dan_sun_zi = "dansunzi"; //可以单顺子 + public static final String an_bao = "anbao"; //允许暗包 + public static final String xi_zai_shou_you_fen = "xizaishouyoufen"; //喜在手有分 + + //-------------------------------牌类型--------------------------------- + /* + * 单牌 + */ + public final static int TYPE_DANPAI = 1; + /** + * 对子 + */ + public final static int TYPE_DUIZI = 2; + /** + * 顺子 + */ + public final static int TYPE_SHUNZI = 3; + /** + * 连对 + */ + public final static int TYPE_LIANDUI = 4; + /** + * 3带2 + */ + public final static int TYPE_3_2 = 5; + /** + * 飞机 + */ + public final static int TYPE_FEIJI = 6; + /** + * 4带3 + */ + public final static int TYPE_4_3 = 7; + + /** + * 炸 + */ + public final static int TYPE_ZHA = 8; + + /** + * 4带2 + */ + public final static int TYPE_4_2 = 9; + + /** + * 五十K + */ + public final static int TYPE_5_10_K = 10; + + + //-------------------------------协议--------------------------------- + + public static final String GAME_EVT_MING_PAI = "2117"; + /** + * 发牌协议 + */ + public static final String GAME_EVT_PLAYER_DEAL = "2011"; + /** + * 出牌 + */ + public static final String GAME_DIS_CARD = "1013"; + /** + * 不出 + */ + public static final String GAME_DIS_PASS = "1014"; + /** + * + */ + public static final String GAME_PIAO = "1015"; + /** + * 出牌事件 + */ + public static final String GAME_EVT_DISCARD = "2021"; + /** + * 出牌提示事件 + */ + public static final String GAME_EVT_DISCARD_TIP = "2004"; + /** + * 转盘指向事件 + */ + public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "2016"; + /** + * pass事件 + */ + public static final String GAME_EVT_PASS = "2030"; + /** + * 更新喜分数 + */ + public static final String GAME_EVT_UPDATE_XI_SCORE = "2118"; + /** + * 更新抓分 + */ + public static final String GAME_EVT_UPDATE_ZHUA_SCORE = "2119"; + + /** + * 小结算 + */ + public static final String GAME_EVT_RESULT1 = "2007"; + + /** + * 飘鸟提示 + */ + public static final String GAME_EVT_PIAO_TIP = "2031"; + public static final String GAME_EVT_PIAO = "2032"; + + /** + * 出牌错误 + */ + public static final String GAME_EVT_PUT_ERROR = "2111"; + + /** + * 看分 + */ + public static final String GAME_KAN_FEN = "22031"; + + /** + * 看分返回 + */ + public static final String GAME_EVT_KAN_FEN = "22032"; + + /** + * 抢庄 + */ + public static final String GAME_NOTIFY_QIANG_ZHUANG = "22033"; + + /** + * 玩家抢庄 + */ + public static final String GAME_EVT_QIANG_ZHUANG = "22034"; + + /** + * 通知新的庄家 + */ + public static final String GAME_EVT_XIN_ZHUANG_JIA = "22035"; + + public static final int PUT_ERROR_MUST_OUT_MIN = 0; + public static final int PUT_ERROR_INVALID_TYPE = 1; + public static final int PUT_ERROR_MUST_OUT_MAX = 2; + public static final int PUT_ERROR_BOMB_CHAI =3; + + public static final String SETTLE_WIN_COUNT = "winnum"; + public static final String SETTLE_CHUNTIAN_COUNT = "springnum"; + public static final String SETTLE_BOMB_COUNT = "boomnum"; + public static final String SETTLE_MAX_SCORE = "maxscore"; +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXActionEvent.java b/game_pk_dazhadan/src/main/java/extend/pk/EXActionEvent.java new file mode 100644 index 0000000..b687a31 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXActionEvent.java @@ -0,0 +1,12 @@ +package extend.pk; + +import com.game.ActionEvent; + +public class EXActionEvent extends ActionEvent{ + + public static final String EVENT_DISCARD = "1013"; + public static final String EVENT_PASS = "1014"; + public static final String EVENT_PIAO= "1015"; + + public static final String EVENT_QIANG_ZHUANG= "1016"; +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXGameController.java b/game_pk_dazhadan/src/main/java/extend/pk/EXGameController.java new file mode 100644 index 0000000..de79b65 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXGameController.java @@ -0,0 +1,640 @@ +package extend.pk; + +import com.game.Constant; +import com.game.GameController; +import com.game.Global; +import com.game.data.Player; +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.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +/** + * + * + */ +public class EXGameController extends GameController { + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_DIS_CARD) + public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params); + } + + @ActionKey(Config.GAME_DIS_PASS) + public void RouterDisPass(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PASS, 0, params); + } + + @ActionKey(Config.GAME_PIAO) + public void RouterPiao(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PIAO, 0, params); + } + + @ActionKey(Config.GAME_KAN_FEN) + public void RouterKanFen(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().kanFen(player); + } + + @ActionKey(Config.GAME_EVT_QIANG_ZHUANG) + public void RouterQiangZhuang(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_QIANG_ZHUANG, 0, params); + } + + // 改变活动玩家 + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("index", activeSeat); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + public void sendPutError(EXPlayer owner,int code) { + ITObject param = new TObject(); + param.putInt("error", code); + owner.sendEvent(Config.GAME_EVT_PUT_ERROR, param); + } + + /** + * pass + * @param owner + */ + public void pass(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + if(room.lastDiscardSeat != 0 && room.lastDiscardSeat != owner.seat) { + EXPlayer lastPlayer = (EXPlayer)room.playerMapBySeat.get(room.lastDiscardSeat); + if (lastPlayer != null) + { + room.add510kScore(lastPlayer); + } + } + response.putInt("seat", owner.seat); + if (Global.loggerDebug) { + Global.logger.info(owner + " pass!"); + } + owner.pass = true; + owner.last_outcard = null; + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addPassCommand(owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_PASS, response); + } + + /** + * 票鸟提示 + * @param owner + */ + public void piaoTipEvent(EXPlayer owner,int reload) { + + ITObject response = new TObject(); + response.putInt("piao", owner.room.config.getInt(Config.ROOM_CONFIG_PIAO)); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_EVT_PIAO_TIP, response); + } + + + /** + * 抢庄提示 + * @param owner + */ + public void qiangZhuangTipEvent(EXPlayer owner,int reload) { + ITObject response = new TObject(); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_NOTIFY_QIANG_ZHUANG, response); + } + + /** + * 票鸟事件 + * @param owner + */ + public void piaoEvent(EXPlayer owner) { + if(owner.piao==-1)return; + + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("piao", owner.piao); + owner.room.broadCastToClient(0, Config.GAME_EVT_PIAO, param); + } + + /** + * 票鸟事件 + * @param owner + */ + public void qiangZhuangEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("banker_seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_XIN_ZHUANG_JIA, param); + } + + public void outCard(EXPlayer owner,CardGroup ct) { + EXRoom room = owner.getRoom(); + int curPaiFen = 0; + for(int i = 0; i < ct.card_list.size(); i++) + { + CardObj obj = ct.card_list.get(i); + if (obj.cardMod == 5) + { + room.out510KInhand.add(new CardObj(obj.card)); + curPaiFen += 5; + } + else if (obj.cardMod == 10 || obj.cardMod == 13) + { + room.out510KInhand.add(new CardObj(obj.card)); + curPaiFen += 10; + } + } + + room.curPaiFen += curPaiFen; + + if (ct.config.type == Config.TYPE_ZHA) + { + if (room.config.getBoolean(Config.WU_ZHANG_SUAN_XI)) + { + if (ct.card_list.size() >= 5) + { + room.addAllXiScore(owner, ct.card_list.size()*10); + } + } + else { + if (ct.card_list.size() >= 6) + { + room.addAllXiScore(owner, ct.card_list.size()*10); + } + } + } + + + ITObject response = new TObject(); + response.putInt("player", owner.seat); + response.putInt("pai_fen", room.curPaiFen); + response.putTObject("card_obj", ct.toObject(false)); + + owner.outCards.addAll(ct.card_list); + + room.lastDiscardSeat = owner.seat; + room.discard = ct; + owner.last_outcard = ct; + owner.pass = false; + if (Global.loggerDebug) { + Global.logger.info(owner + " out card:" + ct); + } + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addOutCardCommand(owner.seat, ct); + CardUtil.removeCard(owner.cardInhand, ct.card_list); + + response.putInt("remain", owner.cardInhand.size()); + room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + + public void dealCard(EXRoom owner) { + if (owner.targetCards.size() == 0) { + owner.card.init(); + } + + int maxDanPai = 0; + int maxDuizi = 0; + int maxSanZhang = 0; + boolean existWhite = false; + boolean existXingyunhao = false; + boolean existGeneral = false; + boolean existBlack = false; + double white_rate = 0; + + ArrayList tmpPlayerList = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmpPlayerList.add(player); + } + + Collections.shuffle(tmpPlayerList); + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + existXingyunhao = true; + } else { + if (player.black_white_status == 0) { + existGeneral = true; + } + else if (player.black_white_status == 1) { + existBlack = true; + } + else if (player.black_white_status == 2) { + existWhite = true; + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + white_rate = 100 - owner.white_value; + Global.logger.info("dealcards playerid:"+player.playerid+ " xingyuhao:"+player.is_white+" white_value:"+owner.white_value); + } + else { + continue; + } + + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + + Collections.sort(player.cardInhand); + + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 2) + { + white_rate = player.black_white_rate; + Global.logger.info("dealcards playerid:"+player.playerid+ " white player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && (existGeneral || existBlack)) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 0) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " general player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, 0, 0, 0); + + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && !existWhite && existBlack) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 1) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " black player:" + (player.black_white_rate+white_rate)); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite && !existGeneral) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, maxDanPai, maxDuizi, maxSanZhang); + } + + Collections.sort(player.cardInhand); + } + + Global.logger.info("sssss==>" + owner.supCards.size()); + if (owner.targetCards.size() > 0 && owner.adminSeat > 0 && owner.supCards.size() > 0) { + owner.card.cardList = owner.supCards.get(0); + } + + // 如果是首局,需要确定庄家 + if(owner.bankerSeat == 0) { + + int rule = Config.RULE_RANDOM; + if(owner.config.containsKey(Config.ROOM_CONFIG_RULE)) { + rule = owner.config.getInt(Config.ROOM_CONFIG_RULE); + } + + owner.bankerSeat = this.getBankerSeat(owner); + + this.sendPlayerDeal(owner); + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + if(player != null) { + + int len = player.cardInhand.size(); + if(len > 0) { + Random random = new Random(); + int rand_pos = random.nextInt(len); + + //this.sendMingPai(owner, player.cardInhand.get(rand_pos).card); + } + } + } + } + else + { + this.sendPlayerDeal(owner); + } + + } + + /** + * 发生随机牌 用于指示谁首先出牌 + * @param owner + */ + private void sendMingPai(EXRoom owner,int card) { + + ITObject param = new TObject(); + param.putInt("mingpai", card); + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + exPlayer.sendEvent(Config.GAME_EVT_MING_PAI, param); + }; + } + /** + * 发牌 + * @param owner + */ + private void sendPlayerDeal(EXRoom owner){ + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + ITObject param = new TObject(); + ITArray handCard = CardUtil.toTArray(exPlayer.cardInhand); + param.putTArray("cards", handCard); + param.putInt("bank_seat", exPlayer.room.bankerSeat); + param.putInt("round", owner.round); + if (Global.loggerDebug) { + Global.logger.info(owner + " deal card:"+exPlayer.cardInhand); + } + exPlayer.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + }; + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + + int rule = Config.RULE_RANDOM; + + //如果是兩人的情況 + if (owner.maxPlayers == 2) { + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + } else { + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(3) + 1; + } + } + return seat; + } + + public void discardTipEvent(EXPlayer owner) { + ITObject param = new TObject(); + boolean gen = (owner.getRoom().lastDiscardSeat != 0 &&owner.getRoom().lastDiscardSeat != owner.seat); + param.putInt("play", gen ? 1 : 0); + + if (!gen) + { + param.putInt("pass", 1); + } + else { + param.putInt("pass", 0); + } + + if(gen) { + param.putTObject("card_obj", owner.getRoom().discard.toObject(true)); + + } + // 如果可以不出 + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + } + + private ITObject getRoomResultData(EXRoom owner,boolean total) { + + ITObject mp = TObject.newInstance(); + + EXPlayer win = owner.win; + + ITArray info = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("you_seat", player.you_seat); + obj.putInt("score", player.score.total_score); + obj.putInt("winscore", player.score.round_score); + obj.putInt("zhuascore", player.zhuaScore); + obj.putInt("xiscore", player.xiScore); + obj.putInt("huascore", player.huaScore); + player.hp_info(obj); + obj.putInt("thisboomnum", player.boomnum); + obj.putInt("piao", player.piao); + obj.putTArray("cards", CardUtil.toTArray(player.cardInhand)); + obj.putBoolean("chuntian", player.chuntian); + + obj.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + obj.putTArray("outCards", CardUtil.toTArray(player.outCards)); + + if(total) { + obj.putInt("daniao", player.daniaoScore); + obj.putInt("award", player.bonusScore); + + obj.putInt("one_you", player.one_you); + obj.putInt("two_you", player.two_you); + obj.putInt("three_you", player.three_you); + obj.putInt("four_you", player.four_you); + + obj.putInt("xi_fen_count", player.xi_fen_count); + + if(owner.endType == Constant.END_TYPE_ENTRUST) { + obj.putInt("entrust", player.entrust ? 1 : 0); + } + obj.putTObject("settle_log", player.settleLog.toTObject()); + obj.putInt("total_score", player.score.total_score); + + } + info.addTObject(obj); + } + if(win != null) { + mp.putInt("winseat",win.seat); + } + else { + mp.putInt("winseat",0); + } + mp.putTArray("remaincards", CardUtil.toTArray(owner.card.cardList)); + mp.putTArray("info", info); + mp.putInt("xipai_score", owner.xi_pai_score); + return mp; + } + + public void roomResult(EXRoom owner) { + + ITObject result = getRoomResultData(owner,false); + result.putInt("type", 0); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + + /** + * 房间大结算 + * @param owner + * @param dissmiss + */ + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + + ITObject result = getRoomResultData(owner,true); + + long t = System.currentTimeMillis() / 1000; + result.putLong("time", t); + result.putInt("type", dissmiss?2:1); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXMainServer.java b/game_pk_dazhadan/src/main/java/extend/pk/EXMainServer.java new file mode 100644 index 0000000..f1acd53 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXMainServer.java @@ -0,0 +1,67 @@ +package extend.pk; + +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.room.state.RoomStartGameState; + +import extend.pk.player.state.EXPlayerDiscardState; +import extend.pk.player.state.EXPlayerPassState; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; +import extend.pk.player.state.EXPlayerQiangZhuangState; +import extend.pk.room.state.*; + +/** + * + * + */ +public class EXMainServer extends MainServer { + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + gameCtr = (EXGameController) Global.gameCtr; + registerState(); + } + + private final void registerState() { + + Global.registerState(RoomStartGameState.class, new EXRoomStartGameState()); + Global.registerState(EXRoomSetpState.class, new EXRoomSetpState()); + Global.registerState(EXRoomDealState.class, new EXRoomDealState()); + Global.registerState(EXRoomPiaoState.class, new EXRoomPiaoState()); + + Global.registerState(EXRoomQiangZhuangState.class, new EXRoomQiangZhuangState()); + + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerPassState.class, new EXPlayerPassState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + Global.registerState(EXPlayerQiangZhuangState.class, new EXPlayerQiangZhuangState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXPlayBack.java b/game_pk_dazhadan/src/main/java/extend/pk/EXPlayBack.java new file mode 100644 index 0000000..c885fb5 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXPlayBack.java @@ -0,0 +1,50 @@ +package extend.pk; + + +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; + +import extend.pk.uitl.CardUtil; + +public class EXPlayBack extends BasePlayBack{ + + public EXPlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + } + + protected ITObject getPlayerInfo(Player p) { + + EXPlayer player = (EXPlayer)p; + ITObject obj =super.getPlayerInfo(player); + ITArray cardInhand = CardUtil.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + obj.putInt("piao", player.piao); + + player.hp_info(obj); + return obj; + } + + public void addOutCardCommand(int seat, CardGroup ct) { + ITObject cmdData = ct.toObject(false); + addCommand("OutCard", seat, cmdData); + } + + public void addPassCommand(int seat) { + ITObject cmdData = TObject.newInstance(); + addCommand("pass", seat, cmdData); + } + + public void addNewRoundCommand() { + ITObject cmdData = TObject.newInstance(); + addCommand("newindex", 0, cmdData); + } + + public void addResultCommand(int seat,ITObject cmdData) { + addCommand("result", seat, cmdData); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXPlayer.java b/game_pk_dazhadan/src/main/java/extend/pk/EXPlayer.java new file mode 100644 index 0000000..6167fed --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXPlayer.java @@ -0,0 +1,145 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.List; + +import com.game.data.Player; +import com.game.data.Room; +import com.game.data.Score; +import com.taurus.core.entity.ITObject; + +import extend.pk.uitl.CardUtil; + + + +/** + * + * + */ +public class EXPlayer extends Player { + + /**默认action时间 20s*/ + public static final int DEFAULT_ACTION_TIME = 20000; + /**默认托管时间 1s*/ + public static final int DEFAULT_ENTRUST_TIME = 1000; + /** + * 默认准备时间 20s + */ + public static final int DEFAULT_READY_TIME = 20000; + + // 手牌 + public List cardInhand; + + //打出的牌 + public List outCards; + + public CardGroup last_outcard; + public boolean pass; + + // 放作弊场第一张牌是否关闭 + public int open = 0; + + /**春天 */ + public boolean chuntian; + + /**是否有红桃10*/ + public boolean isHaveRedTen; + + public SettleLog settleLog; + + public int boomnum = 0; + public int piao = -1; + public int daniaoScore = 0; + public int bonusScore = 0; + public int zhuaScore = 0; + public int xiScore = 0; + public int qiangZhuang = -1; + public int huaScore = 0; + public int one_you = 0; + public int two_you = 0; + public int three_you = 0; + public int four_you = 0; + public int xi_fen_count = 0; + public int you_seat = 0; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + cardInhand = new ArrayList<>(); + outCards = new ArrayList<>(); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_WIN_COUNT, 0); + settleLog.put(Config.SETTLE_CHUNTIAN_COUNT, 0); + settleLog.put(Config.SETTLE_BOMB_COUNT, 0); + settleLog.put(Config.SETTLE_MAX_SCORE, 0); + } + + protected Score newScore() { + return new EXScore(this); + } + + @Override + public ITObject getReloadInfo() { + ITObject playerData = super.getReloadInfo(); + playerData.putInt("card_size", this.cardInhand.size()); + playerData.putInt("piao", this.piao); + playerData.putInt("qiang_zhuang", this.qiangZhuang); + if(last_outcard!=null) { + playerData.putTObject("last_outcard", last_outcard.toObject(false)); + } + + if(this.room.isplaying == false) { + playerData.putTArray("cards", CardUtil.toTArray(this.cardInhand)); + + playerData.putTArray("handCards", CardUtil.toTArray(this.cardInhand)); + playerData.putTArray("outCards", CardUtil.toTArray(this.outCards)); + + playerData.putInt("score", score.total_score); + playerData.putInt("winscore", score.round_score); + playerData.putInt("zhuascore", this.zhuaScore); + playerData.putInt("xiscore", this.xiScore); + playerData.putInt("hua_score", this.huaScore); + playerData.putInt("thisboomnum", boomnum); + playerData.putInt("open", open); + } + return playerData; + } + + @Override + public ITObject getInfo() { + ITObject playerData = super.getInfo(); + playerData.putInt("score", score.total_score); + return playerData; + } + + + public void clear() { + super.clear(); + + } + + public void clearEx() { + + this.score.resetRound(); + this.cardInhand.clear(); + this.outCards.clear(); + this.last_outcard = null; + this.pass = false; + this.chuntian =false; + this.isHaveRedTen=false; + this.open = 0; + this.boomnum = 0; + this.piao = -1; + this.daniaoScore = 0; + this.zhuaScore = 0; + this.xiScore = 0; + this.huaScore = 0; + this.qiangZhuang = -1; + this.you_seat = 0; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXRoom.java b/game_pk_dazhadan/src/main/java/extend/pk/EXRoom.java new file mode 100644 index 0000000..9f5576b --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXRoom.java @@ -0,0 +1,383 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + + +import com.game.MainServer; +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.TArray; +import com.taurus.core.entity.TObject; + +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +public class EXRoom extends Room { + public RoomCard card; + + /**上次打牌的座位*/ + public int lastDiscardSeat; + + /**打出牌的集合 */ + public CardGroup discard; + public int curPaiFen; + + public EXPlayer win; + + public Map card_config_map; + + public int piaoCount = 0; + + public List> supCards; + public List targetCards; + public int adminSeat = 0; + + public int chooseover = 0; + + public List out510KInhand; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + out510KInhand = new ArrayList<>(); + card = new RoomCard(this, 23,maxPlayers); + card_config_map = new HashMap(); + card_config_map.put(CardConfig.DAN.type, CardConfig.DAN); + card_config_map.put(CardConfig.DUIZI.type, CardConfig.DUIZI); + card_config_map.put(CardConfig.LIANDUI.type, CardConfig.LIANDUI); + card_config_map.put(CardConfig.SHUNZI.type, CardConfig.SHUNZI); + card_config_map.put(CardConfig.ZHA.type, CardConfig.ZHA); + card_config_map.put(CardConfig.WUSHIK.type, CardConfig.WUSHIK); + + boolean sandai_2 = this.config.getBoolean(Config.KEYI_DAI_2); + if(sandai_2) { + card_config_map.put(CardConfig.SAN_2.type, CardConfig.SAN_2); + card_config_map.put(CardConfig.FEIJI.type, CardConfig.FEIJI); + } + + 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_XIPAI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIPAI, false); + } + + if (!this.config.containsKey(Config.KE_BAO_PAI)) + { + this.config.putBoolean(Config.KE_BAO_PAI, false); + } + if (!this.config.containsKey(Config.QU_DIAO_34)) + { + this.config.putBoolean(Config.QU_DIAO_34, false); + } + if (!this.config.containsKey(Config.XI_YA_SI_YOU_FEN)) + { + this.config.putBoolean(Config.XI_YA_SI_YOU_FEN, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIPAI, false); + } + if (!this.config.containsKey(Config.WU_ZHANG_SUAN_XI)) + { + this.config.putBoolean(Config.WU_ZHANG_SUAN_XI, false); + } + if (!this.config.containsKey(Config.KE_ZUO_LIAN_ZI_2)) + { + this.config.putBoolean(Config.KE_ZUO_LIAN_ZI_2, false); + } + if (!this.config.containsKey(Config.THREE_WANG_SUAN_XI)) + { + this.config.putBoolean(Config.THREE_WANG_SUAN_XI, false); + } + if (!this.config.containsKey(Config.KEYI_DAI_2)) + { + this.config.putBoolean(Config.KEYI_DAI_2, false); + } + if (!this.config.containsKey(Config.dan_sun_zi)) + { + this.config.putBoolean(Config.dan_sun_zi, false); + } + if (!this.config.containsKey(Config.an_bao)) + { + this.config.putBoolean(Config.an_bao, false); + } + if (!this.config.containsKey(Config.xi_zai_shou_you_fen)) + { + this.config.putBoolean(Config.xi_zai_shou_you_fen, false); + } + + this.isEntrust = true; + + this.supCards = new ArrayList<>(); + this.targetCards = new ArrayList<>(); + this.adminSeat = 0; + this.chooseover = 0; + } + + public void clear() { + super.clear(); + + } + + public void clearEx() { + this.activeSeat = 0; + this.discard = null; + this.lastDiscardSeat = 0; + this.win = null; + this.curPaiFen = 0; + this.out510KInhand.clear(); + } + + public ITObject getReloadInfo(Player player) { + ITObject data = super.getReloadInfo(player); + EXPlayer p = (EXPlayer) player; + + data.putTArray("hand_card", CardUtil.toTArray(p.cardInhand)); + + data.putTArray("handCards", CardUtil.toTArray(p.cardInhand)); + data.putTArray("outCards", CardUtil.toTArray(p.outCards)); + + data.putInt("open", p.open); + + data.putInt("last_outcard_seat", this.lastDiscardSeat); + + // 游戏结束 + if(this.isplaying == false) { + + if(this.win != null) { + data.putInt("winseat", this.win.seat); + } + else + { + data.putInt("winseat", 0); + } + if(this.card.getCount() > 0) { + data.putTArray("remaincards", CardUtil.toTArray(this.card.cardList)); + } + } + + return data; + } + + /** + * + * */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int)fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + // + + 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; + } + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void addAllXiScore(EXPlayer destPlayer, int score) { + TArray seatData=TArray.newInstance(); + destPlayer.xi_fen_count++; + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + ITObject seatListData = TObject.newInstance(); + if(fromPlayer != destPlayer) { + this.addScore(destPlayer, fromPlayer, score, EXScore.XI_FEN); + destPlayer.xiScore += score; + fromPlayer.xiScore -= score; + seatListData.putInt("xi_score", fromPlayer.xiScore); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + } + } + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + ITObject seatListData = TObject.newInstance(); + if(fromPlayer == destPlayer) { + seatListData.putInt("xi_score", destPlayer.xiScore); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + } + } + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_XI_SCORE, allData); + } + + public void kanFen(EXPlayer destPlayer) { + TObject allData=TObject.newInstance(); + allData.putTArray("pai_list", CardUtil.toTArray(this.out510KInhand)); + MainServer.instance.sendEvent(Config.GAME_EVT_KAN_FEN, allData, destPlayer.sender); + } + + /** + * 变更5_10_K积分 + * @param destPlayer + */ + public void add510kScore(EXPlayer destPlayer) { + TArray seatData=TArray.newInstance(); + destPlayer.zhuaScore += curPaiFen; + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + ITObject seatListData = TObject.newInstance(); + if(fromPlayer != destPlayer) { + //this.addScore(destPlayer, fromPlayer, curPaiFen, EXScore.ZHUA_FEN); + seatListData.putInt("zhua_score", fromPlayer.zhuaScore); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + }else{ + seatListData.putInt("zhua_score", destPlayer.zhuaScore); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + } + } + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_ZHUA_SCORE, allData); + this.curPaiFen = 0; + } + + /** + * 变更游戏积分 + * @param destPlayer + */ + public void addAllScore(EXPlayer destPlayer) { + + EXPlayer dp = (EXPlayer)destPlayer; + + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + if(fromPlayer != destPlayer) { + if (destPlayer.zhuaScore >= fromPlayer.zhuaScore) + { + destPlayer.huaScore += 80; + fromPlayer.huaScore -= 80; + addScore(destPlayer, fromPlayer, 80, EXScore.WIN); + } + else { + destPlayer.huaScore += 40; + fromPlayer.huaScore -= 40; + addScore(destPlayer, fromPlayer, 40, EXScore.WIN); + } + addScore(destPlayer, fromPlayer, destPlayer.zhuaScore-fromPlayer.zhuaScore, EXScore.WIN); + } + + if (fromPlayer.seat == destPlayer.seat) + { + fromPlayer.you_seat = 1; + fromPlayer.one_you++; + } + else { + if (destPlayer.getRoom().maxPlayers == 2) + { + fromPlayer.you_seat = 2; + fromPlayer.two_you++; + } + else { + if (fromPlayer.seat > destPlayer.seat) + { + fromPlayer.you_seat = ((fromPlayer.seat - destPlayer.seat) % destPlayer.getRoom().maxPlayers) + 1; + } + else { + fromPlayer.you_seat = ((fromPlayer.seat + destPlayer.getRoom().maxPlayers - destPlayer.seat)%destPlayer.getRoom().maxPlayers) + 1; + } + } + } + + if (fromPlayer.you_seat == 1) + { + fromPlayer.one_you++; + } + else if (fromPlayer.you_seat == 2) + { + fromPlayer.two_you++; + } + else if (fromPlayer.you_seat == 3) + { + fromPlayer.three_you++; + } + else if (fromPlayer.you_seat == 4) + { + fromPlayer.four_you++; + } + } + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + @Override + public void endGame() { + addAllScore(win); + + this.chooseover = 0; + + EXPlayBack pb = (EXPlayBack)this.playBackData; + + + ITObject pbResult = TObject.newInstance(); + + ITArray info = new TArray(); + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.round_score); + obj.putInt("xi_score", player.xiScore); + obj.putInt("zhua_score", player.zhuaScore); + obj.putInt("hua_score", player.huaScore); + obj.putBoolean("entrust", player.entrust); + info.addTObject(obj); + } + pbResult.putTArray("result", info); + + pb.addResultCommand(win.seat, pbResult); + + pb.addNewRoundCommand(); + super.endGame(); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/EXScore.java b/game_pk_dazhadan/src/main/java/extend/pk/EXScore.java new file mode 100644 index 0000000..0616135 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/EXScore.java @@ -0,0 +1,18 @@ +package extend.pk; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + public static final int XI_FEN = 2; + + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(XI_FEN, 0); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/RoomCard.java b/game_pk_dazhadan/src/main/java/extend/pk/RoomCard.java new file mode 100644 index 0000000..96fdb6b --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/RoomCard.java @@ -0,0 +1,784 @@ +package extend.pk; + +import com.game.Global; +import extend.pk.uitl.CardUtil; + +import java.util.*; + +public class RoomCard { + + public static final int HEART_TEN = 310; + public static final int CARD_A = 14; + public static final int CARD_2 = 15; + public static final int CARD_XIAOWANG = 516; + public static final int CARD_DAWAN = 617; + public static final int CARD_3 = 3; + public List cardList; + public List cardListTemp; + EXRoom room; + int num; + int maxPlayer; + Random rand = new Random(); + + int boomNumLimit = rand.nextInt(2) + 2; + int sangzhangNumLimit = rand.nextInt(5) + 10; + + int totalBoomNum = 0; + int totalSanZhangNum = 0; + + public RoomCard(EXRoom table,int num,int maxPlayer) { + this.cardList = new ArrayList(); + this.cardListTemp = new ArrayList(); + this.room = table; + this.num = num; + this.maxPlayer = maxPlayer; + } + + public void init() { + this.boomNumLimit = rand.nextInt(2) + 2; + this.sangzhangNumLimit = rand.nextInt(5) + 10; + + this.totalBoomNum = 0; + this.totalSanZhangNum = 0; + this.cardList.clear(); + this.initCard(); + int currentBoomNum = 0; + int currentSanZhangNum = 0; + Map result = new HashMap(); + do { + currentBoomNum = 0; + currentSanZhangNum = 0; + this.shuffle(); + for(int i = 0; i entry : result.entrySet()) { + if(entry.getValue() >= 4) { + currentBoomNum++; + } + else if(entry.getValue() == 3) { + currentSanZhangNum++; + } + } + } + } + }while((currentBoomNum + totalBoomNum > boomNumLimit) || (currentSanZhangNum + totalSanZhangNum > sangzhangNumLimit)); + } + + private void initCard() { + int pai_num = 2; + if (this.room.maxPlayers > 2) + { + pai_num = 4; + } + + for(int i = 0; i < pai_num; i++) + { + if (this.room.config.getBoolean(Config.QU_DIAO_34)) + { + for (int index = 5; index <= 15; index++) { + // 方片 + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + + this.cardList.add(new CardObj(CARD_XIAOWANG)); + this.cardList.add(new CardObj(CARD_DAWAN)); + + } + else { + for (int index = 3; index <= 15; index++) { + // 方片 + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + this.cardList.add(new CardObj(CARD_XIAOWANG)); + this.cardList.add(new CardObj(CARD_DAWAN)); + } + } + + + + rand.setSeed(System.currentTimeMillis()); + int len = this.cardList.size(); + for(int i = 0; i < len; i++) { + + int randpos = rand.nextInt(1000000000) % len; + CardObj cotemp = this.cardList.get(i); + + this.cardList.set(i, this.cardList.get(randpos)); + this.cardList.set(randpos,cotemp); + } + + Global.logger.info("RoomCard initCard(): "+this.cardList); + } + + private void shuffle() { + for(int i = 0; i < 100; i++) + { + Collections.shuffle(this.cardList); + } + Random rand = new Random(); + int len = this.cardList.size(); + + for(int i = 0; i < 10000; i++) { + rand.setSeed(System.currentTimeMillis()); + int start = rand.nextInt(len); + int end = rand.nextInt(len); + + CardObj co = this.cardList.get(start); + this.cardList.set(start, this.cardList.get(end)); + this.cardList.set(end, co); + } + } + + public CardObj pop() { + CardObj card = this.cardList.remove(0); + return card; + } + + public int getCount() { + return this.cardList.size(); + } + + public List deal0(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(415)); + dealCards.add(new CardObj(214)); + dealCards.add(new CardObj(314)); + dealCards.add(new CardObj(414)); + + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + } + + return dealCards; + } + + public List deal1(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + dealCards.add(new CardObj(303)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + } + + return dealCards; + } + + + public List deal2(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(205)); + dealCards.add(new CardObj(305)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(110)); + + } + else if(seat == 2) { + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + + //dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal3(int seat){ + + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(111)); + dealCards.add(new CardObj(112)); + dealCards.add(new CardObj(113)); + dealCards.add(new CardObj(114)); + dealCards.add(new CardObj(215)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal4(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(308)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(410)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal6(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(105)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(106)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(109)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List dealTest(int seat){ + + List dealCards = deal2(seat); + if(dealCards == null || dealCards.size() == 0) { + + dealCards = deal(); + } + + return dealCards; + } + + // 发牌 + public List deal(boolean room_white, boolean is_white, double room_rate, int white_black_status, double black_white_rate, double black_black_rate, int maxDanPai, int maxDuizi, int maxSanZhang) { + List dealCards = new ArrayList(); + shuffle(); + + double rand1 = Math.random() % 100 * 100; + for (int index = 0; index < this.num ; index++) { + if (room_white && is_white) + { + if (rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards xingyun card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (white_black_status == 2) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards white card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else if (white_black_status == 1) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards black card"); + } + } +; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, true, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, true, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (room_white && rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + /*if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + */ + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + } + } + } + shuffle(); + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + + boolean isGooodCard(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + if (isGooodCard2(card, dealCards, black, maxDanPai, maxDuizi, maxSanZhang)) { + return true; + } + + if (maxDanPai != 0) + { + if (card >= maxDanPai) + { + return true; + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 1)) { + if (card >= maxDuizi) + { + return true; + } + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 2)) { + if (card >= maxSanZhang) + { + return true; + } + } + } + + return false; + } + + boolean isGooodCard2(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + double rand = Math.random() % 100 * 100; + if (black) + { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 70) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 70) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 70) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 70) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 70) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 50) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 50) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 50) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 50) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 50) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + + + return false; + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < this.num ; index++) { + dealCards.add(this.pop()); + } + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/SettleLog.java b/game_pk_dazhadan/src/main/java/extend/pk/SettleLog.java new file mode 100644 index 0000000..eb6b8c6 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/SettleLog.java @@ -0,0 +1,44 @@ +package extend.pk; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..8ec6491 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java @@ -0,0 +1,263 @@ +package extend.pk.player.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.game.Global; +import com.game.Router; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import com.taurus.core.entity.TObject; +import extend.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.uitl.CardCheck; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +/** + * 等待玩家出牌状态 + * + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + // 设置防作弊场开牌的标志 + owner.open = 1; + + EXRoom room = owner.getRoom(); + + //如果最后一次的打牌的座位不等于零并且最后一次打牌的座位不等于自己 + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + if (owner.cardInhand.size() == 0) { + EXPlayer lastPlayer = (EXPlayer)room.playerMapBySeat.get(room.lastDiscardSeat); + if (lastPlayer != null) + { + room.add510kScore(lastPlayer); + } + this.over(owner); + return; + } + + CardGroup big_ct = CardCheck.genOutCard(owner.cardInhand, room.discard,room.config, false); + if(big_ct==null) { + owner.stateMachine.changeState(Global.getState(EXPlayerPassState.class)); + return; + } + } + else { + room.curPaiFen = 0; + if (owner.cardInhand.size() == 0) { + this.over(owner); + return; + } + } + EXMainServer.gameCtr.discardTipEvent(owner); + + owner.startActionTimer(); + } + + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.bankerSeat = owner.seat; + room.win = owner; + room.endGame(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + + ITObject netParam = (ITObject) param; + ITArray card_list = netParam.getTArray("card"); + ITArray all_card = netParam.getTArray("all_card"); + + if (all_card != null) + { + ArrayList temCardList = new ArrayList(); + for(int i=0;i< all_card.size();++i) { + temCardList.add(all_card.getInt(i)); + } + Collections.sort(temCardList); + + ArrayList temCardList2 = new ArrayList(); + for(int i=0;i< owner.cardInhand.size();++i) { + temCardList2.add(owner.cardInhand.get(i).card); + } + Collections.sort(temCardList2); + + if (!temCardList.equals(temCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + // 如果出的牌的个数为0 或者大于手牌的数目 则是非法的 + if (card_list.size() == 0 || card_list.size() > owner.cardInhand.size()) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + List list = CardUtil.toList(card_list); + + for(CardObj card : list) { + + boolean bNotExisted = false; + + for(CardObj handc : owner.cardInhand) { + if(card.card == handc.card) { + bNotExisted = true; + break; + } + } + + if(bNotExisted == false) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + CardGroup ct = CardCheck.getType(list, owner.room.config); + if(ct == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + //验证客户端发过来的类型 + if(!CardCheck.tryType(ct,owner.cardInhand.size(),owner.room.config)) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + doAction(owner,ct,false); + break; + + case EXActionEvent.EVENT_PASS: + + pass(owner); + + break; + case EXActionEvent.EVENT_OFFLINE: + owner.startActionTimer(); + break; + case EXActionEvent.EVENT_TIMER_AUTO: + case EXActionEvent.EVENT_ENTRUST: + + AutoOut(owner); + break; + } + } + + private void AutoOut(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + CardGroup big_ct = null; + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && room.discard.config.type ==Config.TYPE_DANPAI && playerNext.cardInhand.size() == 1) { + + Map> cardMap =CardUtil.getCardListMap(owner.cardInhand); + big_ct = CardCheck.selectDanpai(cardMap,room.discard,room.config,true); + }else { + big_ct = CardCheck.tryBig(owner.cardInhand, room.discard); + } + + if (big_ct != null) { + big_ct.card_list_mp = CardUtil.toTArray(big_ct.card_list); + doAction(owner,big_ct,true); + } else { + Global.logger.info("big_ct == null pass !!!!!!!!!!!!"); + pass(owner); + } + + }else { + + // 在托管或者自动出牌的时候 系统先出炸弹,如果炸弹没有 再出单张 + // 将来可以把这个函数做的能智能一些,不光可以出炸弹 也可以出顺子飞机等等 + CardGroup out_ct = CardCheck.autoOut(owner.cardInhand, owner.room.config); + if(out_ct == null) { + + out_ct = new CardGroup(); + List out_list = new ArrayList<>(); + out_ct.card_list = out_list; + out_ct.config = CardConfig.DAN; + out_ct.len = 1; + + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + out_list.add(owner.cardInhand.get(owner.cardInhand.size() -1)); + }else { + out_list.add(owner.cardInhand.get(0)); + } + } + + out_ct.card_list_mp = CardUtil.toTArray(out_ct.card_list); + out_ct.min_card = out_ct.card_list.get(0).cardMod; + + doAction(owner,out_ct,true); + } + } + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + private void doAction(EXPlayer owner,CardGroup ct,boolean skip) { + + EXRoom room = owner.getRoom(); + boolean outcard = true; + if(!skip) { + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + outcard = CardCheck.tryCompete(room.discard, ct,room.config); + } + } + if(!outcard) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + EXMainServer.gameCtr.outCard(owner,ct); + + this.toNextState(owner); + } + + +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPassState.java b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPassState.java new file mode 100644 index 0000000..7985073 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPassState.java @@ -0,0 +1,52 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; + +/** + * 等待玩家Pass状态 + * + * + */ +public class EXPlayerPassState extends StateBase { + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if(!owner.entrust) { + Timer passTimer = new Timer(1000, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + pass(owner); + } + }); + room.addTimer(passTimer); + }else { + pass(owner); + } + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d2ecadb --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,64 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; + +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; + + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.piaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piao = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + EXMainServer.gameCtr.piaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_PIAO)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerQiangZhuangState.java b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerQiangZhuangState.java new file mode 100644 index 0000000..66e8af7 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/player/state/EXPlayerQiangZhuangState.java @@ -0,0 +1,79 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; + +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.room.state.EXRoomSetpState; + +public class EXPlayerQiangZhuangState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + if (owner.qiangZhuang != -1) + { + owner.getRoom().activeSeat = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + return; + } + if(!owner.isEntrust()) { + EXMainServer.gameCtr.qiangZhuangTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.qiangZhuangTipEvent(owner,1); + owner.startActionTimer(); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.qiangZhuang = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + //EXMainServer.gameCtr.qiangZhuangEvent(owner); + + if (id == 0) + { + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_QIANG_ZHUANG, gid, null); + } + else if (id > 0) + { + owner.getRoom().activeSeat = 0; + owner.getRoom().bankerSeat = owner.seat; + EXMainServer.gameCtr.qiangZhuangEvent(owner); + owner.getRoom().stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_QIANG_ZHUANG)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("qiang_zhuang"); + _action(owner, id, gid); + } else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner, 0, gid); + } else if (cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} \ No newline at end of file diff --git a/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomDealState.java b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomDealState.java new file mode 100644 index 0000000..ff004f4 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomDealState.java @@ -0,0 +1,93 @@ +package extend.pk.room.state; + + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.pk.Config; +import extend.pk.EXMainServer; +import extend.pk.EXPlayBack; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 房间发牌状态 + * + * + */ +public class EXRoomDealState extends StateBase { + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 3000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //owner.card.init(); + if(owner.bankerSeat!=0&&!owner.playerMapBySeat.containsKey(owner.bankerSeat)) { + owner.bankerSeat = 0; + } + EXMainServer.gameCtr.dealCard(owner); + + owner.playBackData = new EXPlayBack(owner); + + if (owner.config.getBoolean(Config.KE_BAO_PAI)) + { + owner.stateMachine.changeState(Global.getState(EXRoomQiangZhuangState.class)); + } + else { + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomPiaoState.java b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..dbb1ce8 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomPiaoState.java @@ -0,0 +1,31 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.EXActionEvent; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO)) { + if(owner.piaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomQiangZhuangState.java b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomQiangZhuangState.java new file mode 100644 index 0000000..a204d5f --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomQiangZhuangState.java @@ -0,0 +1,28 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerQiangZhuangState; + +public class EXRoomQiangZhuangState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerQiangZhuangState.class)); + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomSetpState.java b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ce6843c --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomSetpState.java @@ -0,0 +1,35 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDiscardState; + +/** + * 房间转换座位 + * + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomStartGameState.java b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..665018e --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/room/state/EXRoomStartGameState.java @@ -0,0 +1,43 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.Config; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +/** + * 房间开始状态 + * + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.clearEx(); + } + owner.clearEx(); + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + if(owner.config.containsKey(Config.ROOM_CONFIG_PIAO) && owner.config.getInt(Config.ROOM_CONFIG_PIAO) != 0) { + owner.stateMachine.changeState(Global.getState(EXRoomPiaoState.class)); + } + else{ + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardCheck.java b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardCheck.java new file mode 100644 index 0000000..cfa8ed7 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardCheck.java @@ -0,0 +1,1149 @@ +package extend.pk.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; + +import extend.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.RoomCard; + + +/** + * + * + */ +public class CardCheck { + + /** + * 服务器跟牌判定 + * @param cardInhand + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup genOutCard(List cardInhand,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + + CardGroup cg = null; + + Map> cardMap =CardUtil.getCardListMap(cardInhand); + int handCardSize = cardInhand.size(); + // 如果有炸弹 并且玩家手上仅剩下炸弹 就不用找了 直接出牌就可以了 + cg = select5_10_k(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + + if (cg == null) + { + cg = selectZha(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + } + + // 如果别的玩家出的是一张单牌,则寻找一个合适的单牌,如果找不到就用炸弹,炸弹没有则过 + if(out.config.type == Config.TYPE_DANPAI) { + + CardGroup tempCg = selectDanpai(cardMap,out,roomConfig,nextBaodan); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是不能带牌的牌型(对子,顺子,连队)则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_DUIZI + || out.config.type == Config.TYPE_SHUNZI + || out.config.type == Config.TYPE_LIANDUI) { + + CardGroup tempCg = selectWithoutCardType(handCardSize,cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的三带牌型 ,则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_3_2) { + + boolean bLack = false; + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果别的玩家出的是带牌的飞机牌型,则寻找合适的牌型,如果找不到用则炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_FEIJI) { + + boolean bLack = false; + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果是四带二或者四带三 就不处理了,如果有炸弹,则玩家自己去选择是炸还是跟,如果没有炸弹 玩家也大不了,所以后面就不用判断了 + if(cg != null) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + return cg; + } + + /** + * 选择5_10_k + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup select5_10_k(Map> cardMap,CardGroup out,ITObject roomConfig) { + if(out.config.type == Config.TYPE_ZHA || out.config.type == Config.TYPE_5_10_K) { + return null; + } + + CardGroup cg = null; + + boolean has5 = false; + boolean has10 = false; + boolean hask = false; + + List listCard5 = cardMap.get(5); + if(listCard5 != null && listCard5.size() >= 1) { + has5 = true; + } + + List listCard10 = cardMap.get(10); + if(listCard10 != null && listCard10.size() >= 1) { + has10 = true; + } + + List listCard13 = cardMap.get(13); + if(listCard13 != null && listCard13.size() >= 1) { + hask = true; + } + + if (has5 && has10 && hask) + { + cg = new CardGroup(); + + cg.config = CardConfig.WUSHIK; + cg.min_card = 5; + cg.len = 3; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard5.get(0)); + cg.card_list.add(listCard10.get(0)); + cg.card_list.add(listCard13.get(0)); + } + + return cg; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectZha(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + + int minValue = 0; + if(out.config.type == Config.TYPE_ZHA) { + minValue = out.min_card; + for(Map.Entry> entry : cardMap.entrySet()) { + + if(entry.getValue().size() == out.len -1 + 4) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1 + entry.getValue().size()-4; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + else if (entry.getValue().size() > out.len -1 + 4) + { + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1 + entry.getValue().size()-4; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + else { + for(Map.Entry> entry : cardMap.entrySet()) { + + if(entry.getValue().size() >= 4) { + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(int i = 0; i < 4; i++) { + cg.card_list.add(entry.getValue().get(0)); + } + break; + } + } + } + + return cg; + } + + /** + * 选择单牌 + * @param cardMap + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup selectDanpai(Map> cardMap,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + int minValue = out.min_card + 1; + + for(int i = minValue; i <= 17; i++) { + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + + return cg; + } + + /** + * 选择不需要带牌的牌型 + * @param handCardSize + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectWithoutCardType(int handCardSize,Map> cardMap,CardGroup out,ITObject roomConfig) { + CardGroup cg = null; + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>17)) { + + int count =0; + + for(int i = min_card; i <= 17;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >=out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + private static CardGroup selectWithCardType(List cardInhand, + Map> cardMap, + CardGroup out, + ITObject roomConfig, + boolean bLack) { + + CardGroup cg = null; + + int handCardSize = cardInhand.size(); + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>17)) { + + int count =0; + + for(int i = min_card; i <= 17;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >= out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + int sd = out.config.repeat_num * len + out.config.with_card_num * len; + + if(bLack == false && handCardSize < sd) { + return cg; + } + + // 新建一个临时的列表,来保存剩余的牌 + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + // 如果剩余的牌有炸弹,则需要把剩余牌中的炸弹对应的牌从临时列表中剔除,以确定是否有足够的单牌 + // 如果因为剔除的原因,最后牌型不能做成,那就提示他有炸弹出就可以了 + Map> reservedCardMap = CardUtil.getCardListMap(tem_list); + int duiNum = 0; + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num >= 4) { + CardUtil.removeCard(tem_list, entry.getValue()); + } + + if(num >= 2) { + duiNum++; + } + } + + // 如果手牌数多于牌型的基本要求 + if(handCardSize >= sd) { + + if(tem_list.size() < out.config.with_card_num * len) { + return cg; + } + + for(int m = 0; m < out.config.with_card_num * len; m++) { + card_list.add(tem_list.get(m)); + } + } + else { + card_list.addAll(tem_list); + } + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + /** + * 得到所出牌的牌型 + * @param cardOut + * @param roomConfig + * @return + */ + public static CardGroup getType(List cardOut,ITObject roomConfig) { + + CardGroup cg = autoOutLastHand(cardOut,roomConfig,true); + return cg; + } + + /** + * + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOutLastHand(List cardInhand,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + int len = cardInhand.size(); + if(len == 1) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DAN; + cg.min_card = cardInhand.get(0).cardMod; + cg.len = 1; + } + else if(len == 2) { + cg = checkTwo(cardMap); + } + else if(len == 3) { + + cg = checkThree(cardMap,roomConfig); + } + else if(len == 4) { + + cg = checkFour(cardMap,roomConfig); + } + else if(len == 5) { + cg = checkFive(cardMap,roomConfig); + } + else{ + if (cg == null) { + cg = checkShunzi(len,cardMap,roomConfig); + if(cg == null) { + cg = checkLiandui(len,cardMap,roomConfig); + if(cg == null) { + cg = checkFeiji(len,cardMap,roomConfig,bSpecial); + if(cg == null) { + cg = checkZhaDan(len,cardMap,roomConfig); + } + } + } + } + } + + if(cg != null) { + + for(CardObj cardObj : cardInhand) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + private static int getMaxCardNum(Map cardMap) { + int maxNum = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue() > maxNum) { + maxNum = entry.getValue(); + } + } + + return maxNum; + } + + private static CardGroup checkTwo(Map cardMap) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DUIZI; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + return cg; + } + + private static CardGroup checkThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + boolean has5 = false; + boolean has10 = false; + boolean hasK = false; + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 1 && entry.getKey() == 5) { + has5 = true; + } + else if(entry.getValue() == 1 && entry.getKey() == 10) { + has10 = true; + } + else if(entry.getValue() == 1 && entry.getKey() == 13) { + hasK = true; + } + else { + break; + } + } + + if (has5 && has10 && hasK) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.WUSHIK; + cg.min_card = 5; + cg.len = 3; + } + return cg; + } + + private static CardGroup checkFour(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + if(minCard != 0 && maxCard != 0 && minCard + 1 == maxCard && entry.getKey() != RoomCard.CARD_DAWAN && entry.getKey() != RoomCard.CARD_XIAOWANG) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = 2; + } + } + } + return cg; + } + + private static CardGroup checkFive(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3 || entry.getValue() == 4) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + break; + } + else if (entry.getValue() == 5) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 2; + } + else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2 && entry.getKey() != RoomCard.CARD_DAWAN && entry.getKey() != RoomCard.CARD_XIAOWANG) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 5 && minCard != 0 && maxCard != 0 && minCard + 4 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 5; + } + } + } + + return cg; + } + + private static CardGroup checkShunzi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2 && + entry.getKey() != RoomCard.CARD_DAWAN && entry.getKey() != RoomCard.CARD_XIAOWANG) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkZhaDan(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + + if (entry.getValue() == len) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1 + (len-4); + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkFeiji(int len,Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int[] cardThreeCount = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0}; + + int num2 = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + // 如果有炸弹 则不允许自动出牌 + if(bSpecial == false && (entry.getValue() >= 4)) { + return cg; + } + + if(entry.getValue() >= 3) { + cardThreeCount[entry.getKey()] = 1; + } + else if(entry.getValue() == 2) { + num2++; + } + } + + int left = 0; + int right = 0; + + for(int i = 4; i < cardThreeCount.length; i++) { + + if(left == 0) { + + if(cardThreeCount[i] == 1 && cardThreeCount[i - 1] == 1) { + left = i - 1; + right = i; + } + } + else { + // 如果有连续的继续寻找 + if(cardThreeCount[i] == 1 && right + 1 == i) { + + right = i; + } + else + { + left = 0; + right = 0; + } + } + // 判断出来一个顺子,就判定一下是否可以全部出 + if(left != 0 && right != 0) { + + int threeCount = right - left + 1; + int sl = threeCount * 5; + + if(true) { + + if(len <= sl) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + }else { + + int withMin = threeCount * 4; + if(len == withMin || num2 == threeCount || len == threeCount * 3) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + } + + } + } + + return cg; + } + + + private static CardGroup checkLiandui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2 && entry.getKey() != RoomCard.CARD_DAWAN && entry.getKey() != RoomCard.CARD_XIAOWANG) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + return cg; + } + + /** + * 自动出牌 + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOut(List cardInhand,ITObject roomConfig) { + + CardGroup cg = null; + + // 寻找炸弹 + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() >= 4) { + + cg = new CardGroup(); + List out_list = new ArrayList<>(); + + cg.card_list = out_list; + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1 + (entry.getValue()-4); + + for(CardObj cardObj :cardInhand) { + + if(cardObj.cardMod == entry.getKey()) { + out_list.add(cardObj); + } + } + } + } + + return cg; + } + + + /** + * 验证牌型 + * @param ct + * @param left_count + * @return + */ + public static boolean tryType(CardGroup ct,int left_count,ITObject roomConfig) { + List cardInhand = ct.card_list; + int size = cardInhand.size(); + CardConfig config = ct.config; + if(size config.max_card_num) { + return false; + } + int len = ct.len; + + if(len cardMap =CardUtil.getCardNumMap(cardInhand); + if(!cardMap.containsKey(ct.min_card)) { + return false; + } + if(cardMap.get(ct.min_card) < config.repeat_num) { + return false; + } + return true; + } + else if (ct.config.type == Config.TYPE_5_10_K) + { + Map cardMap =CardUtil.getCardNumMap(cardInhand); + if(!cardMap.containsKey(5)) { + return false; + } + if(!cardMap.containsKey(10)) { + return false; + } + if(!cardMap.containsKey(13)) { + return false; + } + return true; + } + + //if(ct.config.type != Config.TYPE_3_2 && ct.config.type != Config.TYPE_FEIJI) { + if(true) { + + // 如果牌型可以带牌 并且手牌的剩余数等于出牌的数目(全出了) + if(config.with_card_num > 0 && size == left_count) { + // 牌太少了 出牌太多了 + if(size < len*config.repeat_num || size > tem_size) { + return false; + } + // 如果带的牌不够 + if(size < tem_size) { + return false; + } + } + //没有带牌 没有全出 + else { + if(tem_size!=size) { + return false; + } + } + } + + int min_card = ct.min_card; + int max_card = min_card+len -1; + if(len>1&&max_card>15) { + return false; + } + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(int i=min_card;i<=max_card;++i) { + if(!cardMap.containsKey(i)) { + return false; + } + if(cardMap.get(i) < config.repeat_num) { + return false; + } + } + return true; + } + + + + /** + * 比牌大小 + * @param banker + * @param other + * @return + */ + public final static boolean tryCompete(CardGroup banker, CardGroup other,ITObject roomConfig) { + int bankerCradType = banker.config.type; + int otherCradType = other.config.type; + + if(bankerCradType !=Config.TYPE_ZHA && bankerCradType !=Config.TYPE_5_10_K && otherCradType == Config.TYPE_5_10_K) { + return true; + } + if(bankerCradType !=Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) { + return true; + } + if(bankerCradType != otherCradType) { + return false; + } + + if(otherCradType == Config.TYPE_ZHA) + { + if(other.len > banker.len) { + return true; + } + else if(other.len == banker.len) { + if(other.min_card > banker.min_card) { + return true; + } + } + else if (other.len == banker.len) + { + return false; + } + } + else if(otherCradType == Config.TYPE_5_10_K) + { + return false; + } + else { + if(other.min_card > banker.min_card) { + if(other.len == banker.len) { + return true; + } + else + { + return false; + } + } + } + + return false; + } + + + public final static CardGroup tryBig(List cardInhand,CardGroup other) { + + List card_list = new ArrayList(); + int size = cardInhand.size(); + CardConfig config = other.config; + Map> cardMap = null; + int len = other.len; + + if(size >= len*config.repeat_num) { + + int min_card = other.min_card + 1;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + + int max_card = min_card+len -1; //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + + if(!(len>1&&max_card>14)) {//长度如果大于一并且最大的牌 + + int count =0; + cardMap = CardUtil.getCardListMap(cardInhand); + int max = len>1?14:15; + for(int i=min_card;i<=max;++i) { + + List list =cardMap.get(i); + + if(cardMap.containsKey(i)&&list.size() >=config.repeat_num) { + + //不出炸牌 + if(other.config.type !=Config.TYPE_ZHA && list.size()>=4) { + count=0; + card_list.clear(); + continue; + } + + for(int k=0;k0) { + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + //不把炸牌带出去 + int rcard_size = 0; + rcard: + for(int k=0;k tem_list1 = cardMap.get(card); + if(tem_list1.size()>=4) { + CardUtil.removeCard(tem_list, tem_list1); + rcard_size += 4; + break rcard; + } + } + int with_card_size = config.with_card_num * len; + if(rcard_size == 0) { + with_card_size = tem_list.size()=4) { + if(cardMap==null) { + cardMap = CardUtil.getCardListMap(cardInhand); + } + + for (Entry> entry : cardMap.entrySet()) { + int card = entry.getKey(); + List list = entry.getValue(); + if(list.size() >=4) { + CardGroup ct = new CardGroup(); + ct.config = CardConfig.ZHA; + ct.card_list = list; + ct.len = 1; + ct.min_card = card; + return ct; + } + } + } + return null; + } + + public static boolean checkStartSpring(List cardInhand) { + + boolean bRet = false; + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + if(cardMap.getOrDefault(RoomCard.CARD_3, 0) == 4) { + + bRet = true; + } + else if(cardMap.getOrDefault(RoomCard.CARD_2, 0) == 1 && cardMap.getOrDefault(RoomCard.CARD_A, 0) == 3){ + + bRet = true; + } + + + return bRet; + } + + + public static void main(String[] args) { + + + + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardConfig.java b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardConfig.java new file mode 100644 index 0000000..b235557 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardConfig.java @@ -0,0 +1,38 @@ +package extend.pk.uitl; + +import extend.pk.Config; + +public enum CardConfig { + DAN( "单牌", Config.TYPE_DANPAI, 1, 1, 1, 1, 0), + DUIZI( "对子", Config.TYPE_DUIZI, 1, 2, 2, 2, 0), + SHUNZI( "顺子", Config.TYPE_SHUNZI, 5, 1, 5, 12, 0), + LIANDUI( "连对", Config.TYPE_LIANDUI, 2, 2, 4, 16, 0), + SAN_2( "三带二", Config.TYPE_3_2, 1, 3, 3, 5, 2), + FEIJI( "飞机", Config.TYPE_FEIJI, 2, 3, 6, 12, 2), + ZHA( "炸弹", Config.TYPE_ZHA, 1, 4, 4, 16, 0), + WUSHIK( "五十K", Config.TYPE_5_10_K, 3, 1, 3, 3, 0); + + public final int type; + public final String name; + public final int min_len; + public final int repeat_num; + public final int min_card_num; + public final int max_card_num; + public final int with_card_num; + + + private CardConfig(String name,int type,int min_len,int repeat_num,int min_card_num,int max_card_num,int with_card_num) { + this.name = name; + this.type = type; + + this.min_len = min_len; + this.repeat_num = repeat_num; + this.min_card_num = min_card_num; + this.max_card_num = max_card_num; + this.with_card_num = with_card_num; + } + + public String toString() { + return this.name; + } +} diff --git a/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardUtil.java b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardUtil.java new file mode 100644 index 0000000..632e961 --- /dev/null +++ b/game_pk_dazhadan/src/main/java/extend/pk/uitl/CardUtil.java @@ -0,0 +1,377 @@ +package extend.pk.uitl; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.pk.CardObj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CardUtil { + + + /** + * list to TArray + * + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (CardObj card : list) { + result.addInt(card.card); + } + return result; + } + + public static final CardObj getCard(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.cardMod == eventCard) { + return card; + } + } + return null; + } + + public static final CardObj getCard1(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.card == eventCard) { + return card; + } + } + return null; + } + + /** + * 检测牌数量 + * + * @param eventCard + * @param cardList + * @param num + * @return + */ + public static final boolean checkCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result == num) + return true; + } + } + return false; + } + + public static final boolean checkGoodCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result >= num) + return true; + } + } + return false; + } + + public static final boolean checkShunZi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + } + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkSevenShunzi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + + if (result >= 6) + { + return true; + } + return false; + } + + public static final boolean checkFenJi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+1, cardList, 3)) + { + result++; + } + if (checkGoodCard(eventCard-1, cardList, 3)) + { + result++; + } + } + + if (result >= 2) + { + return true; + } + return false; + } + + public static final boolean checkFourDui(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 1)) + { + result++; + } + + if (checkGoodCard(eventCard+1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 2)) + { + result++; + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 2)) + { + result++; + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkQPai(int eventCard, List cardList) { + int result = 0; + if (eventCard >= 12) + { + result++; + for (CardObj card : cardList) { + if (card.cardMod >= 12) { + result++; + } + } + } + + if (result >= 5) + { + return true; + } + return false; + } + + /** + * TArray to list + * @param list + * @return + */ + public static final List toList(ITArray list) { + List tem = new ArrayList(); + for(int i=0;i getCardNumMap(List cardList) { + Map result = new HashMap(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + return result; + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final void getCardNumMap(Map result,List cardList) { + result.clear(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + public static final void getCardNumMap(Map result,List cardList, CardObj tempCard) { + result.clear(); + result.put(tempCard.cardMod, 1); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final Map> getCardListMap(List cardList) { + Map> result = new HashMap>(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + List list = new ArrayList(); + list.add(card); + result.put(card.cardMod, list); + } else { + List list = result.get(card.cardMod); + list.add(card); + } + } + return result; + } + + static public void removeCard(List cardList, List cards) { + for (int i = 0; i < cards.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).card ==cards.get(i).card) { + cardList.remove(j); + break; + } + } + } + } +} diff --git a/game_pk_dazhadan/src/test/java/game_pk_dazhadan/Main.java b/game_pk_dazhadan/src/test/java/game_pk_dazhadan/Main.java new file mode 100644 index 0000000..d43d08b --- /dev/null +++ b/game_pk_dazhadan/src/test/java/game_pk_dazhadan/Main.java @@ -0,0 +1,9 @@ +package game_pk_dazhadan; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_pk_doudizhu/config/game-config.xml b/game_pk_doudizhu/config/game-config.xml new file mode 100644 index 0000000..ea7c41c --- /dev/null +++ b/game_pk_doudizhu/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 127.0.0.1 + 0.0.0.0 + 8365 + 8965 + 65 + true + \ No newline at end of file diff --git a/game_pk_doudizhu/config/log4j.properties b/game_pk_doudizhu/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_pk_doudizhu/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_pk_doudizhu/config/taurus-core.xml b/game_pk_doudizhu/config/taurus-core.xml new file mode 100644 index 0000000..2219d52 --- /dev/null +++ b/game_pk_doudizhu/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_doudizhu/config/taurus-permanent.xml b/game_pk_doudizhu/config/taurus-permanent.xml new file mode 100644 index 0000000..31220cb --- /dev/null +++ b/game_pk_doudizhu/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - test + extend.extend.pk.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_pk_doudizhu/pom.xml b/game_pk_doudizhu/pom.xml new file mode 100644 index 0000000..193a6ba --- /dev/null +++ b/game_pk_doudizhu/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_pk_doudizhu + 1.0.0 + jar + + game_pk_doudizhu + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_pk_doudizhu + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_pk_doudizhu/src/main/java/extend/pk/CardGroup.java b/game_pk_doudizhu/src/main/java/extend/pk/CardGroup.java new file mode 100644 index 0000000..fed67c9 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/CardGroup.java @@ -0,0 +1,44 @@ +package extend.pk; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.pk.uitl.CardConfig; + +import java.util.List; + +public class CardGroup { + /** + * 当前type + */ + public CardConfig config; + + public int min_card; + /** + * 长度 + */ + public int len = 1; + + public List card_list; + + public ITArray card_list_mp; + + public ITObject toObject(boolean card_size) { + ITObject obj = TObject.newInstance(); + if (card_size) { + obj.putInt("card_size", card_list.size()); + } else { + obj.putTArray("card_list", card_list_mp); + } + + obj.putInt("type", config.type); + obj.putInt("min_card", min_card); + obj.putInt("len", len); + return obj; + } + + public String toString() { + return "{type:" + config + " min_card:" + min_card + " len:" + len + " list:" + card_list + "}"; + } + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/CardObj.java b/game_pk_doudizhu/src/main/java/extend/pk/CardObj.java new file mode 100644 index 0000000..bc2d762 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/CardObj.java @@ -0,0 +1,21 @@ +package extend.pk; + +public class CardObj implements Comparable{ + public int card; + public int cardMod; + + public CardObj(int card) { + this.card = card; + this.cardMod = card % 100; + } + + @Override + public int compareTo(CardObj paramT) { + return cardMod == paramT.cardMod ? 0 : cardMod < paramT.cardMod ? -1 : 1; + } + + @Override + public String toString() { + return card + ""; + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/Config.java b/game_pk_doudizhu/src/main/java/extend/pk/Config.java new file mode 100644 index 0000000..483dca8 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/Config.java @@ -0,0 +1,202 @@ +package extend.pk; + +public class Config { + + public static final int XIPAI_SCORE = 10; + + //-------------------------------玩法配置--------------------------------- + /** + * 玩法 单QKA2 去掉234 + */ + public static final String ROOM_CONFIG_SELECTDIQU = "selectDiqu"; + + + /** + * 有大必大 + */ + public static final String ROOM_CONFIG_YOUDABIDA = "youdabida"; + + + /** + * 报单必大 + */ + public static final String ROOM_CONFIG_BAODANBIDA = "baodanbida"; + + /** + * 三带二 + */ + public static final String ROOM_CONFIG_SANDAIER = "sandaier"; + + /** + * 四带一 + */ + public static final String ROOM_CONFIG_SIDAIYI = "sidaiyi"; + + + /** + * 反春 + */ + public static final String ROOM_CONFIG_FANCHUN = "fanchun"; + + /** + * 杀春翻倍 + */ + public static final String ROOM_CONFIG_SHACHUNFANBEI= "shachunfanbei"; + + /** + * 自然春翻倍 + */ + public static final String ROOM_CONFIG_ZIRANCHUNFANBEI = "ziranchunfanbei"; + + + /** + * 4个A自然春 + */ + public static final String ROOM_CONFIG_SIGEAZIRANCHUN = "sigeAziranchun"; + + + + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + //-------------------------------牌类型--------------------------------- + /** + * 单牌 + */ + public final static int TYPE_DANPAI = 1; + /** + * 对子 + */ + public final static int TYPE_DUIZI = 2; + /** + * 顺子 + */ + public final static int TYPE_SHUNZI = 3; + /** + * 连对 + */ + public final static int TYPE_LIANDUI = 4; + + + /** + * 3带2 + */ + public final static int TYPE_3_2 = 5; + /** + * 飞机 + */ + public final static int TYPE_FEIJI = 6; + + + /** + * 炸 + */ + public final static int TYPE_ZHA = 8; + + /** + * 4带1 + */ + public final static int TYPE_4_1 = 9; + + + /** + * 三条 + */ + public final static int TYPE_3_0 = 10; + + /** + * 拖拉机 + * 连三对,或者4对 + */ + public final static int TYPE_TUOLAJI = 11; + + public final static int TYPE_WUDUI = 12; + + + //-------------------------------协议--------------------------------- + + public static final String GAME_EVT_MING_PAI = "2117"; + /** + * 发牌协议 + */ + public static final String GAME_EVT_PLAYER_DEAL = "2011"; + /** + * 出牌 + */ + public static final String GAME_DIS_CARD = "1013"; + + /** + * 不出 + */ + public static final String GAME_DIS_PASS = "1014"; + + /** + * 出牌事件 + */ + public static final String GAME_EVT_DISCARD = "2021"; + /** + * 出牌提示事件 + */ + public static final String GAME_EVT_DISCARD_TIP = "2004"; + + /** + * 转盘指向事件 + */ + public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "2016"; + + /** + * pass事件 + */ + public static final String GAME_EVT_PASS = "2030"; + + /** + * 更新炸弹分数 + */ + public static final String GAME_EVT_UPDATE_BOM_SCORE = "2118"; + + /** + * 小结算 + */ + public static final String GAME_EVT_RESULT1 = "2007"; + + + /** + * 出牌错误 + */ + public static final String GAME_EVT_PUT_ERROR = "2111"; + + + /** + * 报春 + */ + public static final String GAME_NOTIFY_BAO_CHUN = "22033"; + + public static final String GAME_EVT_USER_BAO_CHUN_REQ = "22034"; + + public static final String GAME_EVT_ALERT_TongYi_BAO_CHUN = "22035"; + + public static final String GAME_EVT_USER_BAO_CHUN_RSP = "22036"; + + + /** + * 通知新的最后报春成功 + */ + public static final String GAME_EVT_BAO_CHUN_JIA = "22037"; + + /** + * 玩家抢报春 + */ + public static final int PUT_ERROR_MUST_OUT_MIN = 0; + public static final int PUT_ERROR_INVALID_TYPE = 1; + public static final int PUT_ERROR_MUST_OUT_MAX = 2; + public static final int PUT_ERROR_BOMB_CHAI =3; + + public static final String SETTLE_WIN_COUNT = "winnum"; + public static final String SETTLE_CHUNTIAN_COUNT = "springnum"; + + public static final String SETTLE_CTSTATUS = "springstatus"; + public static final String SETTLE_BOMB_COUNT = "boomnum"; + public static final String SETTLE_MAX_SCORE = "maxscore"; +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXActionEvent.java b/game_pk_doudizhu/src/main/java/extend/pk/EXActionEvent.java new file mode 100644 index 0000000..cc3f369 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXActionEvent.java @@ -0,0 +1,14 @@ +package extend.pk; + +import com.game.ActionEvent; + +public class EXActionEvent extends ActionEvent{ + + public static final String EVENT_DISCARD = "1013"; + public static final String EVENT_PASS = "1014"; + + //public static final String EVENT_PIAO= "1015"; + public static final String EVENT_BAO_CHUN= "22034"; + public static final String EVENT_TONGYI_BAO_CHUN= "22036"; + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXGameController.java b/game_pk_doudizhu/src/main/java/extend/pk/EXGameController.java new file mode 100644 index 0000000..bbf44cd --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXGameController.java @@ -0,0 +1,576 @@ +package extend.pk; + +import com.game.Constant; +import com.game.GameController; +import com.game.Global; +import com.game.data.Player; +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.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +/** + * + * + */ +public class EXGameController extends GameController { + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_DIS_CARD) + public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params); + } + + @ActionKey(Config.GAME_DIS_PASS) + public void RouterDisPass(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PASS, 0, params); + } + + + @ActionKey(Config.GAME_EVT_USER_BAO_CHUN_REQ) + public void RouterBaoChun(Session sender,ITObject params,int gid,Player owner) { + Global.logger.info("RouterBaoChun"); + owner.stateMachine.execute(EXActionEvent.EVENT_BAO_CHUN, 0, params); + } + + @ActionKey(Config.GAME_EVT_USER_BAO_CHUN_RSP) + public void RouterQiangBaoChun(Session sender,ITObject params,int gid,Player owner) { + Global.logger.info("RouterQiangBaoChun:"+owner.playerid); + owner.stateMachine.execute(EXActionEvent.EVENT_TONGYI_BAO_CHUN, 0, params); + } + + // 改变活动玩家 + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("index", activeSeat); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + public void sendPutError(EXPlayer owner,int code) { + ITObject param = new TObject(); + param.putInt("error", code); + owner.sendEvent(Config.GAME_EVT_PUT_ERROR, param); + } + + /** + * pass + * @param owner + */ + public void pass(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + if (Global.loggerDebug) { + Global.logger.info(owner + " pass!"); + } + owner.pass = true; + owner.last_outcard = null; + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addPassCommand(owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_PASS, response); + } + + + + public void outCard(EXPlayer owner,CardGroup ct) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("player", owner.seat); + response.putTObject("card_obj", ct.toObject(false)); + + owner.outCards.addAll(ct.card_list); + + room.lastDiscardSeat = owner.seat; + room.discard = ct; + owner.last_outcard = ct; + owner.pass = false; + room.firstCard = 0; + if (Global.loggerDebug) { + Global.logger.info(owner + " out card:" + ct); + } + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addOutCardCommand(owner.seat, ct); + CardUtil.removeCard(owner.cardInhand, ct.card_list); + + response.putInt("remain", owner.cardInhand.size()); + room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + + public void dealCard(EXRoom owner) { + if (owner.targetCards.size() == 0) { + Global.logger.info("dealcards"); + owner.card.init(); + } + + int maxDanPai = 0; + int maxDuizi = 0; + int maxSanZhang = 0; + boolean existWhite = false; + boolean existXingyunhao = false; + boolean existGeneral = false; + boolean existBlack = false; + double white_rate = 0; + + ArrayList tmpPlayerList = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmpPlayerList.add(player); + } + + Collections.shuffle(tmpPlayerList); + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + existXingyunhao = true; + } else { + if (player.black_white_status == 0) { + existGeneral = true; + } + else if (player.black_white_status == 1) { + existBlack = true; + } + else if (player.black_white_status == 2) { + existWhite = true; + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + white_rate = 100 - owner.white_value; + Global.logger.info("dealcards playerid:"+player.playerid+ " xingyuhao:"+player.is_white+" white_value:"+owner.white_value); + } + else { + continue; + } + + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value,player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + //player.cardInhand = owner.card.deal0(player.seat); + + + Collections.sort(player.cardInhand); + + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 2) + { + white_rate = player.black_white_rate; + Global.logger.info("dealcards playerid:"+player.playerid+ " white player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && (existGeneral || existBlack)) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 0) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " general player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value,player.black_white_status, white_rate, white_rate, 0, 0, 0); + //player.cardInhand = owner.card.deal0(player.seat); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, maxDanPai, maxDuizi, maxSanZhang); + + } + + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && !existWhite && existBlack) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) + { + maxDanPai = card; + } + + if (num == 2) + { + if (card > maxDuizi) + { + maxDuizi = card; + } + } + + if (num == 3) + { + if (card > maxSanZhang) + { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 1) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " black player:" + (player.black_white_rate+white_rate)); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite && !existGeneral) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, 0, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, maxDanPai, maxDuizi, maxSanZhang); + } + + + + Collections.sort(player.cardInhand); + } + + Global.logger.info("sssss==>" + owner.supCards.size()); + if (owner.targetCards.size() > 0 && owner.adminSeat > 0 && owner.supCards.size() > 0) { + owner.card.cardList = owner.supCards.get(0); + } + + // 如果是首局,需要确定庄家 + if(owner.bankerSeat == 0) { + owner.bankerSeat = this.getBankerSeat(owner); + this.sendPlayerDeal(owner); + } + else + { + // owner.bankerSeat = this.getBankerSeat(owner); + this.sendPlayerDeal(owner); + } + + } + + /** + * 报春提示 + * @param owner + */ + public void baoChunTipEvent(EXPlayer owner,int reload) { + ITObject response = new TObject(); + response.putInt("baochun", reload); + owner.sendEvent(Config.GAME_NOTIFY_BAO_CHUN, response); + } + + public void baoChunEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("banker_seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_BAO_CHUN_JIA, param); + } + + /** + * 同意报春提示 + * @param owner + */ + public void tongYiBaoChunTipEvent(EXPlayer owner,int reload){ + ITObject response = new TObject(); + response.putInt("tongyibaochun", reload); + owner.sendEvent(Config.GAME_EVT_ALERT_TongYi_BAO_CHUN, response); + } + + /** + * 发生随机牌 用于指示谁首先出牌 + * @param owner + */ + private void sendMingPai(EXRoom owner,int card) { + + ITObject param = new TObject(); + param.putInt("mingpai", card); + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + exPlayer.sendEvent(Config.GAME_EVT_MING_PAI, param); + }; + } + /** + * 发牌 + * @param owner + */ + private void sendPlayerDeal(EXRoom owner){ + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + ITObject param = new TObject(); + ITArray handCard = CardUtil.toTArray(exPlayer.cardInhand); + param.putTArray("cards", handCard); + param.putInt("bank_seat", exPlayer.room.bankerSeat); + param.putInt("round", owner.round); + if (Global.loggerDebug) { + Global.logger.info(owner + " deal card:"+exPlayer.cardInhand); + } + exPlayer.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + }; + } + + private int getBankerSeatByCard(EXRoom owner) { + for (int index = 3; index <= 13; index++) { + for(int color = 4; color >= 1; color--) { + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (CardObj card : player.cardInhand) { + if (card.card == color *100 + index) { + owner.firstCard = card.card; + return player.seat; + } + } + } + } + } + return 0; + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + //如果是兩人的情況 + Random random = new Random(); + seat = random.nextInt(owner.maxPlayers)+1; + return seat; + } + + + + public void discardTipEvent(EXPlayer owner) { + ITObject param = new TObject(); + boolean gen = (owner.getRoom().lastDiscardSeat != 0 &&owner.getRoom().lastDiscardSeat != owner.seat); + param.putInt("play", gen ? 1 : 0); + if(gen) { + param.putTObject("card_obj", owner.getRoom().discard.toObject(true)); + + } + // 如果可以不出 + + + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + } + + private ITObject getRoomResultData(EXRoom owner,boolean total) { + + ITObject mp = TObject.newInstance(); + + EXPlayer win = owner.win; + boolean checkfc = false;//检测是否是反春 + boolean checkct = false;//检测是否是春天 + ITArray info = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.total_score); + obj.putInt("winscore", player.score.round_score); + player.hp_info(obj); + obj.putInt("thisboomnum", player.boomnum); + + obj.putTArray("cards", CardUtil.toTArray(player.cardInhand)); + obj.putBoolean("chuntian", player.chuntian); + + obj.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + obj.putTArray("outCards", CardUtil.toTArray(player.outCards)); + + if(total) { + obj.putInt("award", player.bonusScore); + + if(owner.endType == Constant.END_TYPE_ENTRUST) { + obj.putInt("entrust", player.entrust ? 1 : 0); + } + obj.putTObject("settle_log", player.settleLog.toTObject()); + obj.putInt("total_score", player.score.total_score); + + } + info.addTObject(obj); + Global.logger.info("bankerSeat: "+owner.bankerSeat); + Global.logger.info("EXPlayer discard:3,{}"+player.seat+"|"+player.dis_times+"|"+player.playerid); + if ((player.seat == owner.bankerSeat)&&(player.dis_times==1)){ + checkfc = true; + } + if((player.seat!=owner.bankerSeat)&&(player.dis_times==0)){ + checkct = true; + } + } + if(win != null) { + mp.putInt("winseat",win.seat); + } + else { + mp.putInt("winseat",0); + } + if(owner.baochunSeat!=0){ + if (owner.shachunSeat==0){ + mp.putInt("chuntianstatus",1); + }else { + mp.putInt("chuntianstatus",2); + } + }else if(checkct){ + mp.putInt("chuntianstatus",1); + }else { + mp.putInt("chuntianstatus", 0); + } + + if (owner.ziranchunover==1){ + mp.putInt("chuntianstatus",1); + } + if (checkfc&&owner.baochunSeat==0){ + mp.putInt("chuntianstatus",3); + } + owner.bankerSeat = win.seat; + + //mp.putTArray("remaincards", CardUtil.toTArray(owner.card.cardList)); + mp.putTArray("remaincards", CardUtil.toTArray(new ArrayList<>())); + mp.putTArray("info", info); + mp.putInt("xipai_score", owner.xi_pai_score); + return mp; + } + + public void roomResult(EXRoom owner) { + + ITObject result = getRoomResultData(owner,false); + result.putInt("type", 0); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + + /** + * 房间大结算 + * @param owner + * @param dissmiss + */ + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + + ITObject result = getRoomResultData(owner,true); + + long t = System.currentTimeMillis() / 1000; + result.putLong("time", t); + result.putInt("type", dissmiss?2:1); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXMainServer.java b/game_pk_doudizhu/src/main/java/extend/pk/EXMainServer.java new file mode 100644 index 0000000..4c8705c --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXMainServer.java @@ -0,0 +1,64 @@ +package extend.pk; + +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.room.state.RoomStartGameState; +import extend.pk.player.state.*; +import extend.pk.room.state.*; + +import java.util.Map; + +/** + * + * + */ +public class EXMainServer extends MainServer { + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + gameCtr = (EXGameController) Global.gameCtr; + registerState(); + } + + private final void registerState() { + + Global.registerState(RoomStartGameState.class, new EXRoomStartGameState()); + Global.registerState(EXRoomSetpState.class, new EXRoomSetpState()); + Global.registerState(EXRoomDealState.class, new EXRoomDealState()); + Global.registerState(EXRoomPiaoState.class, new EXRoomPiaoState()); + Global.registerState(EXRoomBaoChunState.class, new EXRoomBaoChunState()); + + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerPassState.class, new EXPlayerPassState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + + Global.registerState(EXPlayerBaoChunState.class, new EXPlayerBaoChunState()); + Global.registerState(EXPlayerTongYiBaoChunState.class, new EXPlayerTongYiBaoChunState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXPlayBack.java b/game_pk_doudizhu/src/main/java/extend/pk/EXPlayBack.java new file mode 100644 index 0000000..9b4020a --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXPlayBack.java @@ -0,0 +1,48 @@ +package extend.pk; + + +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; +import extend.pk.uitl.CardUtil; + +public class EXPlayBack extends BasePlayBack{ + + public EXPlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + } + + protected ITObject getPlayerInfo(Player p) { + + EXPlayer player = (EXPlayer)p; + ITObject obj =super.getPlayerInfo(player); + ITArray cardInhand = CardUtil.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + + player.hp_info(obj); + return obj; + } + + public void addOutCardCommand(int seat, CardGroup ct) { + ITObject cmdData = ct.toObject(false); + addCommand("OutCard", seat, cmdData); + } + + public void addPassCommand(int seat) { + ITObject cmdData = TObject.newInstance(); + addCommand("pass", seat, cmdData); + } + + public void addNewRoundCommand() { + ITObject cmdData = TObject.newInstance(); + addCommand("newindex", 0, cmdData); + } + + public void addResultCommand(int seat,ITObject cmdData) { + addCommand("result", seat, cmdData); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXPlayer.java b/game_pk_doudizhu/src/main/java/extend/pk/EXPlayer.java new file mode 100644 index 0000000..5c12a28 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXPlayer.java @@ -0,0 +1,129 @@ +package extend.pk; + +import com.game.data.Player; +import com.game.data.Room; +import com.game.data.Score; +import com.taurus.core.entity.ITObject; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.List; + + + +/** + * + * + */ +public class EXPlayer extends Player { + + /**默认action时间 20s*/ + public static final int DEFAULT_ACTION_TIME = 20000; + /**默认托管时间 1s*/ + public static final int DEFAULT_ENTRUST_TIME = 1000; + /** + * 默认准备时间 20s + */ + public static final int DEFAULT_READY_TIME = 20000; + + // 手牌 + public List cardInhand; + + //打出的牌 + public List outCards; + + public CardGroup last_outcard; + public boolean pass; + + // 放作弊场第一张牌是否关闭 + public int open = 0; + + /**春天 */ + public boolean chuntian; + + public SettleLog settleLog; + + public int boomnum = 0; + + public int baochun = -1; + + public int bonusScore = 0; + public int awardScore = 0; + + public int ziranchun = 0; + + public int dis_times = 0;//出牌次数 + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + cardInhand = new ArrayList<>(); + outCards = new ArrayList<>(); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_WIN_COUNT, 1); + settleLog.put(Config.SETTLE_CHUNTIAN_COUNT, 1); + settleLog.put(Config.SETTLE_CTSTATUS, 1); + settleLog.put(Config.SETTLE_BOMB_COUNT, 0); + settleLog.put(Config.SETTLE_MAX_SCORE, 20); + } + + protected Score newScore() { + return new EXScore(this); + } + + @Override + public ITObject getReloadInfo() { + ITObject playerData = super.getReloadInfo(); + playerData.putInt("card_size", this.cardInhand.size()); + if(last_outcard!=null) { + playerData.putTObject("last_outcard", last_outcard.toObject(false)); + } + + if(this.room.isplaying == false) { + playerData.putTArray("cards", CardUtil.toTArray(this.cardInhand)); + + playerData.putTArray("handCards", CardUtil.toTArray(this.cardInhand)); + playerData.putTArray("outCards", CardUtil.toTArray(this.outCards)); + + playerData.putInt("score", score.total_score); + playerData.putInt("winscore", score.round_score); + playerData.putInt("thisboomnum", boomnum); + playerData.putInt("open", open); + } + return playerData; + } + + @Override + public ITObject getInfo() { + ITObject playerData = super.getInfo(); + playerData.putInt("score", score.total_score); + return playerData; + } + + + public void clear() { + super.clear(); + + } + + public void clearEx() { + + this.score.resetRound(); + this.cardInhand.clear(); + this.outCards.clear(); + this.last_outcard = null; + this.pass = false; + this.chuntian =false; + + this.open = 0; + this.boomnum = 0; + this.baochun = -1; + this.ziranchun = 0; + this.dis_times = 0; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXRoom.java b/game_pk_doudizhu/src/main/java/extend/pk/EXRoom.java new file mode 100644 index 0000000..d2b0a40 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXRoom.java @@ -0,0 +1,322 @@ +package extend.pk; + +import com.game.Global; +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.TArray; +import com.taurus.core.entity.TObject; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class EXRoom extends Room { + public RoomCard card; + + /**上次打牌的座位*/ + public int lastDiscardSeat; + + /**打出牌的集合 */ + public CardGroup discard; + + public EXPlayer win; + + public int firstCard = 0; + + public Map card_config_map; + + public int piaoCount = 0; + + public List> supCards; + public List targetCards; + public int adminSeat = 0; + + public int baochunstate = -1; + + public int baochunSeat = 0; + + public int shachunSeat = 0; + + public int chooseover = 0; + + public int ziranchunover = 0 ; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this,10,maxPlayers,this.config.getInt(Config.ROOM_CONFIG_SELECTDIQU)); + card_config_map = new HashMap(); + card_config_map.put(CardConfig.DAN.type, CardConfig.DAN); + card_config_map.put(CardConfig.DUIZI.type, CardConfig.DUIZI); + card_config_map.put(CardConfig.LIANDUI.type, CardConfig.LIANDUI); + card_config_map.put(CardConfig.SHUNZI.type, CardConfig.SHUNZI); + card_config_map.put(CardConfig.ZHA.type, CardConfig.ZHA); + card_config_map.put(CardConfig.FEIJI.type, CardConfig.FEIJI); + card_config_map.put(CardConfig.SAN_2.type, CardConfig.SAN_2); + card_config_map.put(CardConfig.SI_1.type, CardConfig.SI_1); + card_config_map.put(CardConfig.TUOLAJI.type, CardConfig.TUOLAJI); + card_config_map.put(CardConfig.SANTIAO.type, CardConfig.SANTIAO); + + 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); + } + + this.isEntrust = true; + this.supCards = new ArrayList<>(); + this.targetCards = new ArrayList<>(); + this.adminSeat = 0; + this.chooseover = 0; + } + + public void clear() { + super.clear(); + } + + public void clearEx() { + this.activeSeat = 0; + this.discard = null; + this.lastDiscardSeat = 0; + this.win = null; + this.firstCard = 0; + this.baochunSeat = 0; + this.baochunstate = -1; + this.shachunSeat = 0; + this.ziranchunover = 0; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = super.getReloadInfo(player); + EXPlayer p = (EXPlayer) player; + + data.putTArray("hand_card", CardUtil.toTArray(p.cardInhand)); + + data.putTArray("handCards", CardUtil.toTArray(p.cardInhand)); + data.putTArray("outCards", CardUtil.toTArray(p.outCards)); + + data.putInt("open", p.open); + + data.putInt("last_outcard_seat", this.lastDiscardSeat); + + // 游戏结束 + if(this.isplaying == false) { + + if(this.win != null) { + data.putInt("winseat", this.win.seat); + } + else + { + data.putInt("winseat", 0); + } + if(this.card.getCount() > 0) { + data.putTArray("remaincards", CardUtil.toTArray(this.card.cardList)); + } + } + + return data; + } + + /** + * + * */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } + + public void addScore(Player destPlayer, Player fromPlayer, int score, int type) { + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int)fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + // + + 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; + } + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void addAllBombScore(EXPlayer destPlayer) { + + destPlayer.settleLog.add(Config.SETTLE_BOMB_COUNT); + destPlayer.boomnum++; + + TArray seatData=TArray.newInstance(); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + ITObject seatListData = TObject.newInstance(); + /*if(fromPlayer != destPlayer) { + // this.addScore(destPlayer, fromPlayer, 10, EXScore.ZHA); + seatListData.putInt("bom_score", -10); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + }else{ + seatListData.putInt("bom_score", 20); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + }*/ + } + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_BOM_SCORE, allData); + } + + /** + * 变更游戏积分 + * @param destPlayer + */ + public void addAllScore(Player destPlayer) { + + EXPlayer dp = (EXPlayer)destPlayer; + EXRoom room = dp.getRoom(); + boolean bSpring = false; + Global.logger.info("room.shachunSeat:"+room.shachunSeat); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer)entry.getValue(); + if(fromPlayer != destPlayer) { + + if(fromPlayer.cardInhand.size()>0) { + + int size = fromPlayer.cardInhand.size(); + int score = size; + + if (size==10){ + score = 20; + } + if (room.shachunSeat!=0){ + score = 20; + } + if (dp.ziranchun==1){ + score = 40; + } + if ((fromPlayer.seat == room.bankerSeat)&&(fromPlayer.dis_times==1)){ + score = 20; + } + Global.logger.info("fromPlayer:"+fromPlayer.playerid+"room.shachunSeat:"+room.shachunSeat); + Global.logger.info("score:"+score); + this.addScore(destPlayer, fromPlayer, score, EXScore.WIN); + } + } + } + + // 设置玩家的当初最大分数 + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + + if(destPlayer == player) { + player.settleLog.add(Config.SETTLE_WIN_COUNT); + } + + if(player.score.round_score > player.settleLog.get(Config.SETTLE_MAX_SCORE)) { + player.settleLog.put(Config.SETTLE_MAX_SCORE, player.score.round_score); + } + } + // 增加玩家春天的个数 + if(bSpring) { + dp.settleLog.add(Config.SETTLE_CHUNTIAN_COUNT); + } + + if(totalType()) { + + + int maxTotalScore = 0; + int maxTotalCount = 0; + + for (Entry entry : this.playerMapBySeat.entrySet()) { + + Player player = entry.getValue(); + + if(player.score.total_score > maxTotalScore) { + + maxTotalScore = player.score.total_score; + maxTotalCount = 1; + } + else if(player.score.total_score == maxTotalScore && maxTotalScore > 0) { + + maxTotalCount++; + } + } + + // 如果存在大赢家 + if(maxTotalScore > 0 && maxTotalCount > 0) { + + for (Entry entry : this.playerMapBySeat.entrySet()) { + + EXPlayer player = (EXPlayer)entry.getValue(); + + } + } + + } + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + @Override + public void endGame() { + addAllScore(win); + + this.chooseover = 0; + + EXPlayBack pb = (EXPlayBack)this.playBackData; + + Global.logger.error("EXRoom: endGame"); + ITObject pbResult = TObject.newInstance(); + + ITArray info = new TArray(); + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.round_score); + obj.putBoolean("entrust", player.entrust); + info.addTObject(obj); + } + pbResult.putTArray("result", info); + Global.logger.error("pbResult:"+pbResult); + pb.addResultCommand(win.seat, pbResult); + + pb.addNewRoundCommand(); + + Global.logger.error("end maxRound:"+this.maxRound); + Global.logger.error("end game:"+this.round); + super.endGame(); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/EXScore.java b/game_pk_doudizhu/src/main/java/extend/pk/EXScore.java new file mode 100644 index 0000000..fc4343f --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/EXScore.java @@ -0,0 +1,18 @@ +package extend.pk; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + public static final int ZHA = 2; + + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(ZHA, 0); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/RoomCard.java b/game_pk_doudizhu/src/main/java/extend/pk/RoomCard.java new file mode 100644 index 0000000..b791ae3 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/RoomCard.java @@ -0,0 +1,779 @@ +package extend.pk; + +import com.game.Global; +import extend.pk.uitl.CardUtil; + +import java.util.*; + +public class RoomCard { + + public static final int HEART_TEN = 310; + public static final int CARD_A = 14; + public static final int CARD_2 = 15; + public static final int CARD_3 = 3; + public List cardList; + public List cardListTemp; + EXRoom room; + int num; + int maxPlayer; + int selectDiqu; + Random rand = new Random(); + + int boomNumLimit = rand.nextInt(2) + 2; + int sangzhangNumLimit = rand.nextInt(5) + 10; + + int totalBoomNum = 0; + int totalSanZhangNum = 0; + + public RoomCard(EXRoom table,int num,int maxPlayer,int selectDiqu) { + Global.logger.info("RoomCard"); + this.cardList = new ArrayList(); + this.cardListTemp = new ArrayList(); + this.room = table; + this.num = num; + this.maxPlayer = maxPlayer; + this.selectDiqu = selectDiqu; + Global.logger.info("RoomCard:"); + } + + public void init() { + Global.logger.info("dealcards init:"); + this.boomNumLimit = rand.nextInt(2) + 2; + + this.sangzhangNumLimit = rand.nextInt(5) + 10; + + this.totalBoomNum = 0; + this.totalSanZhangNum = 0; + this.cardList.clear(); + Global.logger.info("dealcards init:"+this.boomNumLimit); + this.initCard(); + int currentBoomNum = 0; + int currentSanZhangNum = 0; + + Map result = new HashMap(); + do { + currentBoomNum = 0; + currentSanZhangNum = 0; + this.shuffle(); + for(int i = 0; i entry : result.entrySet()) { + if(entry.getValue() >= 4) { + currentBoomNum++; + } + else if(entry.getValue() == 3) { + currentSanZhangNum++; + } + } + } + } + }while((currentBoomNum + totalBoomNum > boomNumLimit) || (currentSanZhangNum + totalSanZhangNum > sangzhangNumLimit)); + } + + private void initCard() { + for (int index = 3; index <= 15; index++) { + // 方片 + + if(selectDiqu==0){ + if (index<12){ + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + }else{ + this.cardList.add(new CardObj(400 + index)); + } + + }else{ + if (index>4&&index!=15){ + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + } + } + + + + + rand.setSeed(System.currentTimeMillis()); + int len = this.cardList.size(); + for(int i = 0; i < len; i++) { + + int randpos = rand.nextInt(1000000000) % len; + CardObj cotemp = this.cardList.get(i); + + this.cardList.set(i, this.cardList.get(randpos)); + this.cardList.set(randpos,cotemp); + } + + Global.logger.info("RoomCard initCard(): "+this.cardList+"selectDiqu:"+selectDiqu); + } + + private void shuffle() { + for(int i = 0; i < 100; i++) + { + Collections.shuffle(this.cardList); + } + Random rand = new Random(); + int len = this.cardList.size(); + + for(int i = 0; i < 10000; i++) { + rand.setSeed(System.currentTimeMillis()); + int start = rand.nextInt(len); + int end = rand.nextInt(len); + + CardObj co = this.cardList.get(start); + this.cardList.set(start, this.cardList.get(end)); + this.cardList.set(end, co); + } + } + + public CardObj pop() { + CardObj card = this.cardList.remove(0); + return card; + } + + public int getCount() { + return this.cardList.size(); + } + + public List deal0(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(313)); + dealCards.add(new CardObj(311)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(208)); + + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(411)); + dealCards.add(new CardObj(311)); + + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(304)); + dealCards.add(new CardObj(303)); + } + + return dealCards; + } + + public List deal1(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + dealCards.add(new CardObj(303)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + } + + return dealCards; + } + + + public List deal2(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(205)); + dealCards.add(new CardObj(305)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(110)); + + } + else if(seat == 2) { + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + + //dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal3(int seat){ + + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(111)); + dealCards.add(new CardObj(112)); + dealCards.add(new CardObj(113)); + dealCards.add(new CardObj(114)); + dealCards.add(new CardObj(215)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal4(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(308)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(410)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal6(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(105)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(106)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(109)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List dealTest(int seat){ + + List dealCards = deal2(seat); + if(dealCards == null || dealCards.size() == 0) { + + dealCards = deal(); + } + + return dealCards; + } + + // 发牌 + public List deal(boolean room_white, boolean is_white, double room_rate, int white_black_status, double black_white_rate, double black_black_rate, int maxDanPai, int maxDuizi, int maxSanZhang) { + List dealCards = new ArrayList(); + + shuffle(); + + double rand1 = Math.random() % 100 * 100; + for (int index = 0; index < this.num ; index++) { + if (room_white && is_white) + { + if (rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards xingyun card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (white_black_status == 2) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards white card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else if (white_black_status == 1) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards black card"); + } + } +; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, true, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, true, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (room_white && rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + } + } + } + shuffle(); + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + + boolean isGooodCard(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + if (isGooodCard2(card, dealCards, black, maxDanPai, maxDuizi, maxSanZhang)) { + return true; + } + + if (maxDanPai != 0) + { + if (card >= maxDanPai) + { + return true; + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 1)) { + if (card >= maxDuizi) + { + return true; + } + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 2)) { + if (card >= maxSanZhang) + { + return true; + } + } + } + + return false; + } + + boolean isGooodCard2(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + double rand = Math.random() % 100 * 100; + if (black) + { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 70) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 70) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 70) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 70) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 70) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 50) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 50) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 50) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 50) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 50) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + + + return false; + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < this.num ; index++) { + dealCards.add(this.pop()); + } + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/SettleLog.java b/game_pk_doudizhu/src/main/java/extend/pk/SettleLog.java new file mode 100644 index 0000000..86b78c6 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/SettleLog.java @@ -0,0 +1,44 @@ +package extend.pk; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java new file mode 100644 index 0000000..95575da --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerBaoChunState.java @@ -0,0 +1,149 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.pk.*; + + +import java.util.Map; + + +/** + * + */ +public class EXPlayerBaoChunState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + Global.logger.error("EXPlayerBaoChunState enter"); + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.baoChunTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + + EXMainServer.gameCtr.baoChunTipEvent(owner,1); + + owner.startActionTimer(); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + + + + + private void _action(EXPlayer owner,int id,int gid) { + owner.baochun = id; + EXRoom room = owner.getRoom(); + + int tmp = 0; + if (id==0){ + //不报春 + }else { + //获得报春最近的 + if(room.baochunSeat==0){ + room.baochunSeat = owner.seat; + }else{ + if(room.bankerSeat==room.maxPlayers){ + if((room.bankerSeat-room.baochunSeat)>(room.bankerSeat-owner.seat)){ + room.baochunSeat = owner.seat; + } + }else{ + if((room.baochunSeat-room.bankerSeat)<(owner.seat-room.bankerSeat)){ + room.baochunSeat = owner.seat; + } + } + } + } + Global.logger.info("EXRoom room maxPlayers:"+ room.maxPlayers); + Global.logger.info("EXRoom room bankerSeat:"+ room.bankerSeat); + Global.logger.info("EXRoom room activeSeat:"+ room.activeSeat); + Global.logger.info("Player room nextSeat:"+ owner.nextSeat); + + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat!=room.bankerSeat){ + Global.logger.info("baochun Player id:"+ player.playerid); + if (player.baochun==-1){ + tmp = -1; + } + } + } + // + + //owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Global.logger.error("EXPlayerBaoChunState id:"+id); + if (tmp==0){ + //全部选择完 + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + if (room.baochunSeat>0){ + //有人报春,庄家是否抢? + Global.logger.info("EXPlayerBaoChunState baochunSeat:"+room.baochunSeat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerTongYiBaoChunState.class)); + }else{ + //无人报春,庄家先出 + Global.logger.info("EXPlayerBaoChunState 开牌:"+room.baochunSeat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + + private void _tyaction(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + if (id==0){ + //庄家自己报春, + room.baochunSeat = room.bankerSeat; + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + }else { + //报春者报春 + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat==room.baochunSeat){ + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + Global.logger.error("EXPlayerBaoChunState cmd: "+cmd); + if (cmd.equals(EXActionEvent.EVENT_BAO_CHUN)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("baochun"); + _action(owner, id, gid); + }else if(cmd.equals(EXActionEvent.EVENT_TONGYI_BAO_CHUN)){ + ITObject netParam = (ITObject) param; + int id = netParam.getInt("tongyi"); + _tyaction(owner, id, gid); + }else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner, 0, gid); + } else if (cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} \ No newline at end of file diff --git a/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..fa16aa6 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java @@ -0,0 +1,380 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.Router; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import extend.pk.*; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.uitl.CardCheck; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * 等待玩家出牌状态 + * + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + // 设置防作弊场开牌的标志 + owner.open = 1; + + EXRoom room = owner.getRoom(); + + //如果最后一次打牌的座位等于自己 并且牌型是炸弹 + if(room.lastDiscardSeat == owner.seat&&room.discard.config == CardConfig.ZHA) { + + room.addAllBombScore(owner);//炸弹玩家增加积分 + } + + //如果最后一次的打牌的座位不等于零并且最后一次打牌的座位不等于自己 + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + boolean bNextBaodan = false; + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + bNextBaodan = true; + } + CardGroup big_ct = CardCheck.genOutCard(owner.cardInhand, room.discard,room.config,bNextBaodan); + if(big_ct==null) { + Global.logger.error("big_ct: pass state"); + owner.stateMachine.changeState(Global.getState(EXPlayerPassState.class)); + return; + } + else { + + if(big_ct.config.type == Config.TYPE_ZHA ) { + // 如果能出完,就自动出完 + if(big_ct.card_list.size() == owner.cardInhand.size()) { + + doAction(owner,big_ct,true); + return; + } + } + else { + + boolean bContainZha = false; + + + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = cardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + bContainZha = true; + } + + + } + + if(big_ct.card_list.size() == owner.cardInhand.size() && bContainZha == false) { + doAction(owner,big_ct,true); + return; + } + } + } + } + else { + + // 自动出牌 + CardGroup auto_ct = CardCheck.autoOutLastHand(owner.cardInhand, room.config,false); + if(auto_ct != null) { + doAction(owner,auto_ct,true); + return; + } + } + EXMainServer.gameCtr.discardTipEvent(owner); + + owner.startActionTimer(); + } + + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.win = owner; + room.baochunstate = -1; + Global.logger.error("EXPlayerDiscard: over"); + room.endGame(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + + ITObject netParam = (ITObject) param; + ITArray card_list = netParam.getTArray("card"); + ITArray all_card = netParam.getTArray("all_card"); + + if (all_card != null) + { + ArrayList temCardList = new ArrayList(); + for(int i=0;i< all_card.size();++i) { + temCardList.add(all_card.getInt(i)); + } + Collections.sort(temCardList); + + ArrayList temCardList2 = new ArrayList(); + for(int i=0;i< owner.cardInhand.size();++i) { + temCardList2.add(owner.cardInhand.get(i).card); + } + Collections.sort(temCardList2); + + if (!temCardList.equals(temCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + Global.logger.info("EXPlayer discard:"); + // 如果出的牌的个数为0 或者大于手牌的数目 则是非法的 + if (card_list.size() == 0 || card_list.size() > owner.cardInhand.size()) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + List list = CardUtil.toList(card_list); + + + for(CardObj card : list) { + + boolean bNotExisted = false; + + for(CardObj handc : owner.cardInhand) { + if(card.card == handc.card) { + bNotExisted = true; + break; + } + } + + if(bNotExisted == false) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + if(owner.getRoom().firstCard != 0 && CardUtil.getCard1(owner.getRoom().firstCard, list) == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MIN); + return; + } + + CardGroup ct = CardCheck.getType(list, owner.room.config); + + if (ct == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + + + Global.logger.info("EXPlayer discard:2"); + //验证客户端发过来的类型 + if(!CardCheck.tryType(ct,owner.cardInhand.size(),owner.room.config)) { + + // tryType 判断3条a判断不出来, 所以 + if(!(ct.config.type == Config.TYPE_ZHA && + card_list.size() == 3 )) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + + //判断是否用A,2 + owner.dis_times = owner.dis_times + 1; + + Global.logger.info("EXPlayer discard:3,{}"+owner.dis_times); + doAction(owner,ct,false); + break; + + case EXActionEvent.EVENT_PASS: + pass(owner); + + break; + case EXActionEvent.EVENT_OFFLINE: + owner.startActionTimer(); + break; + case EXActionEvent.EVENT_TIMER_AUTO: + case EXActionEvent.EVENT_ENTRUST: + + AutoOut(owner); + break; + } + } + + private void AutoOut(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + CardGroup big_ct = null; + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && room.discard.config.type ==Config.TYPE_DANPAI && playerNext.cardInhand.size() == 1) { + + Map> cardMap =CardUtil.getCardListMap(owner.cardInhand); + big_ct = CardCheck.selectDanpai(cardMap,room.discard,room.config,true); + }else { + big_ct = CardCheck.tryBig(owner.cardInhand, room.discard); + } + + if (big_ct != null) { + big_ct.card_list_mp = CardUtil.toTArray(big_ct.card_list); + doAction(owner,big_ct,true); + } else { + Global.logger.info("big_ct == null pass !!!!!!!!!!!!"); + pass(owner); + } + + }else { + + // 在托管或者自动出牌的时候 系统先出炸弹,如果炸弹没有 再出单张 + // 将来可以把这个函数做的能智能一些,不光可以出炸弹 也可以出顺子飞机等等 + CardGroup out_ct = CardCheck.autoOut(owner.cardInhand, owner.room.config); + if(out_ct == null) { + + out_ct = new CardGroup(); + List out_list = new ArrayList<>(); + out_ct.card_list = out_list; + out_ct.config = CardConfig.DAN; + out_ct.len = 1; + + if(room.firstCard != 0) { + CardObj co = CardUtil.getCard1(room.firstCard, owner.cardInhand); + out_list.add(co); + } + else + { + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + out_list.add(owner.cardInhand.get(owner.cardInhand.size() -1)); + }else { + out_list.add(owner.cardInhand.get(0)); + } + } + } + + out_ct.card_list_mp = CardUtil.toTArray(out_ct.card_list); + out_ct.min_card = out_ct.card_list.get(0).cardMod; + + doAction(owner,out_ct,true); + } + } + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + private void doAction(EXPlayer owner,CardGroup ct,boolean skip) { + + EXRoom room = owner.getRoom(); + + boolean outcard = true; + + if(ct.config.type==Config.TYPE_SHUNZI){ + + boolean cf = false; + List cardOut = ct.card_list; + for (int i = 0; i< cardOut.size(); i++){ + if (cardOut.get(i).cardMod==2){ + cardOut.get(i).card = cardOut.get(i).card+13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod+13; + cf = true; + } + if (cardOut.get(i).cardMod==1){ + cardOut.get(i).card = cardOut.get(i).card+13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod+13; + cf = true; + } + } + if(cf){ + ct.card_list = cardOut; + ct.card_list_mp = CardUtil.toTArray(cardOut); + } + } + + if(!skip) { + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + outcard = CardCheck.tryCompete(room.discard, ct,room.config); + } + + // 如果玩家的下家只有一张牌,玩家出单张必须是最大的 + if(outcard && ct.config.type == Config.TYPE_DANPAI) { + + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && playerNext.cardInhand.size() == 1) { + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Integer number : cardMap.keySet()) { + + if(ct.min_card < number) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MAX); + return; + } + } + } + } + } + if(!outcard) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + + EXMainServer.gameCtr.outCard(owner,ct); + + if (room.baochunSeat!=0&&owner.seat!=room.baochunSeat){ + room.shachunSeat = owner.seat; + this.over(owner); + return; + } + + if (owner.cardInhand.size() == 0) { + this.over(owner); + return; + } else { + this.toNextState(owner); + } + } + + +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPassState.java b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPassState.java new file mode 100644 index 0000000..176aef1 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPassState.java @@ -0,0 +1,51 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; + +/** + * 等待玩家Pass状态 + * + * + */ +public class EXPlayerPassState extends StateBase { + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if(!owner.entrust) { + Timer passTimer = new Timer(1000, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + pass(owner); + } + }); + room.addTimer(passTimer); + }else { + pass(owner); + } + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..4df7620 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,52 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import extend.pk.EXPlayer; + + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java new file mode 100644 index 0000000..49f703e --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/player/state/EXPlayerTongYiBaoChunState.java @@ -0,0 +1,83 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map; + + +/** + * + */ +public class EXPlayerTongYiBaoChunState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + Global.logger.error("EXPlayerTongYiBaoChunState enter"); + + if(!owner.isEntrust()) { + EXMainServer.gameCtr.tongYiBaoChunTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + + EXMainServer.gameCtr.tongYiBaoChunTipEvent(owner,1); + + owner.startActionTimer(); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + private void _tyaction(EXPlayer owner,int id,int gid) { + EXRoom room = owner.getRoom(); + if (id==0){ + //庄家自己报春, + room.baochunSeat = room.bankerSeat; + EXPlayer zjplayer = (EXPlayer) room.playerMapBySeat.get(room.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(room, zjplayer.seat); + zjplayer.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + }else { + //报春者报春 + for (Map.Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if(player.seat==room.baochunSeat){ + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + } + // owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + Global.logger.error("EXPlayerTongYiBaoChunState cmd: "+cmd); + if(cmd.equals(EXActionEvent.EVENT_TONGYI_BAO_CHUN)){ + ITObject netParam = (ITObject) param; + int id = netParam.getInt("tongyi"); + _tyaction(owner, id, gid); + } else if (cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} \ No newline at end of file diff --git a/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java new file mode 100644 index 0000000..497a1f4 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomBaoChunState.java @@ -0,0 +1,52 @@ +package extend.pk.room.state; + +import com.game.Global; + +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerBaoChunState; +import extend.pk.uitl.CardCheck; + +import java.util.Map; + + +public class EXRoomBaoChunState extends StateBase { + + @Override + public void enter(EXRoom owner) { + Global.logger.error("EXRoomBaoChunState enter"); + + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + + //检测是否自然春: + Boolean ziRanChun = CardCheck.CheckZiRanChun(player.cardInhand,owner.config); + if (ziRanChun){ + //自然春,不用报春直接倒牌 + player.ziranchun = 1; + owner.ziranchunover = 1; + this.over(player); + return; + } + + + if (owner.bankerSeat!=player.seat){ + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerBaoChunState.class)); + } + } + + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + room.win = owner; + room.baochunstate = -1; + Global.logger.error("EXPlayerDiscard: over"); + room.endGame(); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomDealState.java b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomDealState.java new file mode 100644 index 0000000..1da958d --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomDealState.java @@ -0,0 +1,89 @@ +package extend.pk.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.permanent.TPServer; +import extend.pk.*; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 房间发牌状态 + * + * + */ +public class EXRoomDealState extends StateBase { + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 3000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //owner.card.init(); + if(owner.bankerSeat!=0&&!owner.playerMapBySeat.containsKey(owner.bankerSeat)) { + owner.bankerSeat = 0; + } + EXMainServer.gameCtr.dealCard(owner); + + owner.playBackData = new EXPlayBack(owner); + + Global.logger.error("deal room tonextstate"); + //定庄家 + + if(owner.baochunstate<0){ + owner.stateMachine.changeState(Global.getState(EXRoomBaoChunState.class)); + } + // owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomPiaoState.java b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..c0e797b --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomPiaoState.java @@ -0,0 +1,25 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; + +import java.util.Map.Entry; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomSetpState.java b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..531cdcf --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomSetpState.java @@ -0,0 +1,36 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDiscardState; + +/** + * 房间转换座位 + * + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + + + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomStartGameState.java b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..2c5cae6 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/room/state/EXRoomStartGameState.java @@ -0,0 +1,38 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +import java.util.Map.Entry; + +/** + * 房间开始状态 + * + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.clearEx(); + } + owner.clearEx(); + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardCheck.java b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardCheck.java new file mode 100644 index 0000000..e07c502 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardCheck.java @@ -0,0 +1,1440 @@ +package extend.pk.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +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.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.RoomCard; + + +/** + * + * + */ +public class CardCheck { + + /** + * 服务器跟牌判定 + * @param cardInhand + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup genOutCard(List cardInhand,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + + CardGroup cg = null; + //Global.logger.info("genoutcard:"+cardInhand+",out:"+out); + Map> cardMap =CardUtil.getCardListMap(cardInhand); + int handCardSize = cardInhand.size(); + // 如果有炸弹 并且玩家手上仅剩下炸弹 就不用找了 直接出牌就可以了 + cg = selectZha(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + //如果有推土机 就不用找了 直接出牌就可以了 + if (out.config.type!=Config.TYPE_ZHA){ + CardGroup tempCg = selectTuolaji(cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是一张单牌,则寻找一个合适的单牌,如果找不到就用炸弹,炸弹没有则过 + if(out.config.type == Config.TYPE_DANPAI) { + + CardGroup tempCg = selectDanpai(cardMap,out,roomConfig,nextBaodan); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是不能带牌的牌型(对子,顺子,连队)则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_DUIZI + || out.config.type == Config.TYPE_SHUNZI + || out.config.type == Config.TYPE_LIANDUI) { + + CardGroup tempCg = selectWithoutCardType(handCardSize,cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的三带牌型 ,则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_3_2) { + + boolean bLack = false; + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的飞机牌型,则寻找合适的牌型,如果找不到用则炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_FEIJI) { + + boolean bLack = false; + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果是四带二或者四带三 就不处理了,如果有炸弹,则玩家自己去选择是炸还是跟,如果没有炸弹 玩家也大不了,所以后面就不用判断了 + if(cg != null) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + return cg; + } + + public static Boolean CheckZiRanChun(List cardInhand,ITObject roomConfig){ + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + System.out.println(cardMap); + + int len = cardInhand.size(); + + cg = checkFeiji(len,cardMap,roomConfig,false); + if (cg!=null){ + return true; + } + + cg = checkShunzi(len,cardMap,roomConfig); + if (cg!=null){ + return true; + } + + //检查5对 + cg = checkWudui(len,cardMap,roomConfig); + System.out.println(cg); + if (cg!=null){ + return true; + } + return false; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectZha(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + + boolean bThreeA = false; + + int minValue = 0; + if(out.config.type == Config.TYPE_ZHA) { + minValue = out.min_card; + } + + for(Map.Entry> entry : cardMap.entrySet()) { + + if(entry.getValue().size() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA && entry.getValue().size() == 3)) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + + return cg; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectTuolaji(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + int minValue = 0; + if(out.config.type == Config.TYPE_TUOLAJI) { + minValue = out.min_card; + } + + int minCard = 0; + int maxCard = 0; + int count = 0; + int len = 3; + System.out.println("mimvalue:"+minValue); + System.out.println(cardMap); + ArrayList temp = new ArrayList<>(); + ArrayList ctp = new ArrayList<>(); + for(Map.Entry> entry : cardMap.entrySet()) { + System.out.println(entry.getValue()); + if(entry.getValue().size() >= 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + count++; + ctp.add(entry.getKey()); + temp.addAll(entry.getValue()); + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + if (count>=3){ + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + break; + } + } + + } + + + } + if(count>len){ + //如果对子大于3对 + if (((int) ctp.get(2)==(int)ctp.get(1)+1)&&((int) ctp.get(1)-(int) ctp.get(0)==1)){ + //也是拖拉机 + + temp.remove(temp.size()-1); + temp.remove(temp.size()-1); + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + } + + if (((int) ctp.get(3)==(int)ctp.get(2)+1)&&((int) ctp.get(2)-(int) ctp.get(1)==1)){ + //也是拖拉机 + temp.remove(0); + temp.remove(0); + cg = new CardGroup(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = 1; + cg.card_list = temp; + } + + } + + if(cg==null){ + return null; + } + if(minValue>=cg.min_card){ + return null; + } + + return cg; + } + + /** + * 选择单牌 + * @param cardMap + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup selectDanpai(Map> cardMap,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + int minValue = out.min_card + 1; + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + if(!nextBaodan) { + + for(int i = minValue; i <= 15; i++) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3 ))) { + + } + else { + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + else + { + for(int i = 15; i >= minValue; i--) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3))) { + + } + else { + + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + + return cg; + } + + /** + * 选择不需要带牌的牌型 + * @param handCardSize + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectWithoutCardType(int handCardSize,Map> cardMap,CardGroup out,ITObject roomConfig) { + CardGroup cg = null; + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>14)) { + + int count =0; + + for(int i = min_card; i <= 14;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >=out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + private static CardGroup selectWithCardType(List cardInhand, + Map> cardMap, + CardGroup out, + ITObject roomConfig, + boolean bLack) { + + CardGroup cg = null; + + int handCardSize = cardInhand.size(); + + boolean bDemolition = false; + + + boolean bThreeA = false; + + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>15)) { + + int count =0; + + for(int i = min_card; i <= 15;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >= out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + int sd = out.config.repeat_num * len + out.config.with_card_num * len; + + + + if(bLack == false && handCardSize < sd) { + + return cg; + } + + + // 新建一个临时的列表,来保存剩余的牌 + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + // 如果剩余的牌有炸弹,则需要把剩余牌中的炸弹对应的牌从临时列表中剔除,以确定是否有足够的单牌 + // 如果因为剔除的原因,最后牌型不能做成,那就提示他有炸弹出就可以了 + Map> reservedCardMap = CardUtil.getCardListMap(tem_list); + int duiNum = 0; + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num == 4 || (entry.getKey() == RoomCard.CARD_A && bThreeA && num == 3)) { + + CardUtil.removeCard(tem_list, entry.getValue()); + } + + if(num >= 2) { + duiNum++; + } + } + + + + + // 如果手牌数多于牌型的基本要求 + if(handCardSize >= sd) { + + if(tem_list.size() < out.config.with_card_num * len) { + return cg; + } + + for(int m = 0; m < out.config.with_card_num * len; m++) { + card_list.add(tem_list.get(m)); + } + } + else { + + card_list.addAll(tem_list); + } + + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + /** + * 得到所出牌的牌型 + * @param cardOut + * @param roomConfig + * @return + */ + public static CardGroup getType(List cardOut,ITObject roomConfig) { + + CardGroup cg = autoOutLastHand(cardOut,roomConfig,true); + System.out.println(cg); + if(cg==null){ + boolean cf = false; + for (int i = 0; i< cardOut.size(); i++){ + if (cardOut.get(i).cardMod==15){ + cardOut.get(i).card = cardOut.get(i).card-13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod-13; + cf = true; + } + if (cardOut.get(i).cardMod==14){ + cardOut.get(i).card = cardOut.get(i).card-13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod-13; + cf = true; + } + } + if (cf){ + cg = autoOutLastHand(cardOut, roomConfig,true ); + } + } + + if(cg == null) { + int len = cardOut.size(); + int sidai = roomConfig.getInt(Config.ROOM_CONFIG_SIDAIYI); + // 看看所处的牌是否 4带2 或者4带3 + if((len == 5 && sidai == 1)) { + + Map cardMap =CardUtil.getCardNumMap(cardOut); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + + cg.config = CardConfig.SI_1; + + + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj : cardOut) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + } + } + } +// Global.logger.info("getType:{}"+cg); + return cg; + } + + /** + * + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOutLastHand(List cardInhand,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + int len = cardInhand.size(); +// Global.logger.info("autoOutLastHand len:"+len); + if(len == 1) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DAN; + cg.min_card = cardInhand.get(0).cardMod; + cg.len = 1; + } + else if(len == 2) { + cg = checkTwo(cardMap); + } + else if(len == 3) { + cg = checkThree(cardMap,roomConfig); + } + else if(len == 4) { + cg = checkFour(cardMap,roomConfig); + } + else if(len == 5) { + cg = checkFive(cardMap,roomConfig,bSpecial); + }else{ + if (cg == null) { + cg = checkShunzi(len,cardMap,roomConfig); + if(cg == null&&len%2==0) { + cg = checkTuoLaJi(len,cardMap,roomConfig); + if(cg == null) { + + cg = checkFeiji(len,cardMap,roomConfig,bSpecial); + } + } + } + } + + if(cg != null) { + + for(CardObj cardObj : cardInhand) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + private static int getMaxCardNum(Map cardMap) { + int maxNum = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue() > maxNum) { + maxNum = entry.getValue(); + } + } + + return maxNum; + } + + public static boolean isConfig4_2_and_4_3(ITObject roomConfig) { + + return false; + + } + + private static CardGroup checkTwo(Map cardMap) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DUIZI; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + return cg; + } + + private static CardGroup checkThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SANTIAO; + cg.min_card = entry.getKey(); + cg.len = 3; + }else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 3 && minCard != 0 && maxCard != 0 && minCard + 2 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 3; + } + } + } + return cg; + } + + private static CardGroup checkFour(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + }else if(entry.getValue() == 3) { + + /*boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + }*/ + + if(entry.getKey() == RoomCard.CARD_A ) { + return cg; + } + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + if(minCard != 0 && maxCard != 0 && minCard + 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = 2; + } + }else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2){ + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 4 && minCard != 0 && maxCard != 0 && minCard + 3 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 4; + } + } + } + return cg; + } + + private static CardGroup checkFive(Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_1; + cg.min_card = entry.getKey(); + cg.len = 1; + + }else if(entry.getValue() == 3 /*|| (entry.getValue() == 4 && bSpecial == true)*/) { + + if(entry.getValue() != 4 && cardMap.size() >= 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + } + else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 5 && minCard != 0 && maxCard != 0 && minCard + 4 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 5; + } + } + } + + return cg; + } + + private static CardGroup checkShunzi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkLiandui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + return cg; + } + + private static CardGroup checkWudui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue()==4){ + count=count+2; + }else if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + count++; + } + else + { + break; + } + } + if (count==5){ + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.WUDUI; + cg.min_card = minCard; + cg.len = 10; + + return cg; + } + return cg; + } + + private static CardGroup checkFeiji(int len,Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int[] cardThreeCount = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0}; + System.out.println("cardM:"+cardMap); + boolean bThreeA = false; + + int num2 = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + // 如果有炸弹 则不允许自动出牌 + if(bSpecial == false && (entry.getValue() == 4 || (entry.getKey() == RoomCard.CARD_A && entry.getValue() == 3 && bThreeA == true))) { + return cg; + } + + if(entry.getValue() >= 3) { + cardThreeCount[entry.getKey()] = 1; + } + else if(entry.getValue() == 2) { + num2++; + } + } + + + int left = 0; + int right = 0; + + for(int i = 4; i < cardThreeCount.length; i++) { + if(left == 0) { + + if(cardThreeCount[i] == 1 && cardThreeCount[i - 1] == 1) { + left = i - 1; + right = i; + } + } + else { + // 如果有连续的继续寻找 + if(cardThreeCount[i] == 1 && right + 1 == i) { + + right = i; + } + else + { + left = 0; + right = 0; + } + } + // 判断出来一个顺子,就判定一下是否可以全部出 + if(left != 0 && right != 0) { + + int threeCount = right - left + 1; + int sl = threeCount * 5; + + if(len <= sl) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + + + } + } + + return cg; + } + + /** + * 拖拉机 + */ + private static CardGroup checkTuoLaJi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.TUOLAJI; + cg.min_card = minCard; + cg.len = count; + } + } + } + + return cg; + } + + /** + * 自动出牌 + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOut(List cardInhand,ITObject roomConfig) { + + CardGroup cg = null; + + //支持3A炸弹 + boolean bThreeA = false; + + + // 寻找炸弹 + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA == true && entry.getValue() == 3)) { + + cg = new CardGroup(); + List out_list = new ArrayList<>(); + + cg.card_list = out_list; + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj :cardInhand) { + + if(cardObj.cardMod == entry.getKey()) { + out_list.add(cardObj); + } + } + } + } + + return cg; + } + + + /** + * 验证牌型 + * @param ct + * @param left_count + * @return + */ + public static boolean tryType(CardGroup ct,int left_count,ITObject roomConfig) { + List cardInhand = ct.card_list; + int size = cardInhand.size(); + CardConfig config = ct.config; + + if(size < config.min_card_num || size > config.max_card_num) { + return false; + } + int len = ct.len; + if(len 0 && size == left_count) { + + // 牌太少了 出牌太多了 + if(size < len * config.repeat_num || size > tem_size) { + return false; + } + // 如果带的牌不够 + if(size < tem_size) { + if(ct.config.type == Config.TYPE_3_2) { + + } + // 如果是飞机 + else if(ct.config.type == Config.TYPE_FEIJI) { + + } + } + + } + //没有带牌 没有全出 + else { + if(tem_size!=size) { + return false; + } + } + } + + if (config.type == Config.TYPE_3_0){ + //三 + return true; + } + + if (config.type == Config.TYPE_3_2){ + if(config.with_card_num==2){ + return true; + } + } + + if (config.type == Config.TYPE_TUOLAJI){ + return true; + } + + + int min_card = ct.min_card; + int max_card = min_card+len -1; + + if(len>1&&max_card>15) { + return false; + } + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + for(int i=min_card;i<=max_card;++i) { + if(!cardMap.containsKey(i)) { + return false; + } + if(cardMap.get(i) < config.repeat_num) { + return false; + } + } + return true; + } + + + + /** + * 比牌大小 + * @param banker + * @param other + * @return + */ + public final static boolean tryCompete(CardGroup banker, CardGroup other,ITObject roomConfig) { + int bankerCradType = banker.config.type; + int otherCradType = other.config.type; + + if(bankerCradType != Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) { + return true; + } + if(bankerCradType!= Config.TYPE_ZHA&&bankerCradType!=Config.TYPE_TUOLAJI && otherCradType == Config.TYPE_TUOLAJI){ + return true; + } + + if(bankerCradType != otherCradType) { + return false; + } + + if(other.min_card > banker.min_card) { + if(otherCradType == Config.TYPE_ZHA) { + return true; + } + else + { + + if(other.len == banker.len) { + + if(otherCradType == Config.TYPE_3_2 || otherCradType == Config.TYPE_FEIJI) { + + } + + return true; + } + else + { + return false; + } + } + } + + return false; + } + + + public final static CardGroup tryBig(List cardInhand,CardGroup other) { + + List card_list = new ArrayList(); + int size = cardInhand.size(); + CardConfig config = other.config; + Map> cardMap = null; + int len = other.len; + + if(size >= len*config.repeat_num) { + + int min_card = other.min_card + 1;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + + int max_card = min_card+len -1; //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + + if(!(len>1&&max_card>14)) {//长度如果大于一并且最大的牌 + + int count =0; + cardMap = CardUtil.getCardListMap(cardInhand); + int max = 15; + for(int i=min_card;i<=max;++i) { + + List list =cardMap.get(i); + + if(cardMap.containsKey(i)&&list.size() >=config.repeat_num) { + + //不出炸牌 + if(other.config.type !=Config.TYPE_ZHA && list.size()>=4) { + count=0; + card_list.clear(); + continue; + } + + for(int k=0;k0) { + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + //不把炸牌带出去 + int rcard_size = 0; + rcard: + for(int k=0;k tem_list1 = cardMap.get(card); + if(tem_list1.size()>=4) { + CardUtil.removeCard(tem_list, tem_list1); + rcard_size += 4; + break rcard; + } + } + int with_card_size = config.with_card_num * len; + if(rcard_size == 0) { + with_card_size = tem_list.size()=4) { + if(cardMap==null) { + cardMap = CardUtil.getCardListMap(cardInhand); + } + + for (Entry> entry : cardMap.entrySet()) { + int card = entry.getKey(); + List list = entry.getValue(); + if(list.size() >=4) { + CardGroup ct = new CardGroup(); + ct.config = CardConfig.ZHA; + ct.card_list = list; + ct.len = 1; + ct.min_card = card; + return ct; + } + } + } + return null; + } + + public static boolean checkStartSpring(List cardInhand) { + + boolean bRet = false; + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + if(cardMap.getOrDefault(RoomCard.CARD_3, 0) == 4) { + + bRet = true; + } + else if(cardMap.getOrDefault(RoomCard.CARD_2, 0) == 1 && cardMap.getOrDefault(RoomCard.CARD_A, 0) == 3){ + + bRet = true; + } + + + return bRet; + } + + + public static void main(String[] args) { + + ITObject test = new TObject(); + ITArray card_list = new TArray(); + ITArray card_list2 = new TArray(); + + card_list.addInt(206); + card_list.addInt(207); + card_list.addInt(308); + + + + card_list2.addInt(115); + + card_list2.addInt(214); + card_list2.addInt(213); + card_list2.addInt(203); + card_list2.addInt(210); + card_list2.addInt(209); + card_list2.addInt(307); + //card_list.addInt(207); + test.putInt("sidaiyi",0); + + List tlist2 = CardUtil.toList(card_list2); + List tlist = CardUtil.toList(card_list); + CardGroup ct = CardCheck.getType(tlist, test ); + //System.out.println(ct); + //System.out.println(CheckZiRanChun(tlist,test)); + /* + if(ct.config.type==Config.TYPE_SHUNZI&&ct.config.type==Config.TYPE_LIANDUI&&ct.config.type==Config.TYPE_TUOLAJI) { + boolean cf = false; + List cardOut = ct.card_list; + for (int i = 0; i < cardOut.size(); i++) { + if (cardOut.get(i).cardMod == 1) { + cardOut.get(i).card = cardOut.get(i).card + 13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod + 13; + cf = true; + } + if (cardOut.get(i).cardMod == 2) { + cardOut.get(i).card = cardOut.get(i).card + 13; + cardOut.get(i).cardMod = cardOut.get(i).cardMod + 13; + cf = true; + } + } + if (cf) { + ct.card_list = cardOut; + } + }*/ + //ct.card_list = tlist; + //System.out.println(ct); + if (ct!=null){ + Boolean a = CardCheck.tryType(ct,4,test); + System.out.println("DO:"+a); + } + + if(ct!=null){ + CardGroup ct2 = CardCheck.genOutCard(tlist2, ct,test,false); + System.out.println("A:"+ct2); + } + // CardCheck.tryBig(); + //CardGroup ct = CardCheck.getType(list, owner.room.config); + + + + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardConfig.java b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardConfig.java new file mode 100644 index 0000000..4d6e7f6 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardConfig.java @@ -0,0 +1,44 @@ +package extend.pk.uitl; + +import extend.pk.Config; + +public enum CardConfig { + DAN( "单牌", Config.TYPE_DANPAI, 1, 1, 1, 1, 0), + DUIZI( "对子", Config.TYPE_DUIZI, 1, 2, 2, 2, 0), + SHUNZI( "顺子", Config.TYPE_SHUNZI, 3, 1, 3, 10, 0), + LIANDUI( "姐妹对", Config.TYPE_LIANDUI, 2, 2, 4, 10, 0), + SAN_2( "三带二", Config.TYPE_3_2, 1, 3, 3, 5, 2), + FEIJI( "飞机", Config.TYPE_FEIJI, 2, 3, 6, 10, 4), + SI_1( "四带一", Config.TYPE_4_1, 1, 4, 5, 5, 1), + SANTIAO( "三条", Config.TYPE_3_0, 3, 1, 3, 3, 0), + + TUOLAJI( "拖拉机", Config.TYPE_TUOLAJI, 3, 2, 6, 10, 0), + + WUDUI( "五小对", Config.TYPE_WUDUI, 10, 1, 10, 10, 0), + + ZHA( "炸弹", Config.TYPE_ZHA, 1, 4, 4, 4, 0); + + public final int type; + public final String name; + public final int min_len; + public final int repeat_num; + public final int min_card_num; + public final int max_card_num; + public final int with_card_num; + + + private CardConfig(String name,int type,int min_len,int repeat_num,int min_card_num,int max_card_num,int with_card_num) { + this.name = name; + this.type = type; + + this.min_len = min_len; + this.repeat_num = repeat_num; + this.min_card_num = min_card_num; + this.max_card_num = max_card_num; + this.with_card_num = with_card_num; + } + + public String toString() { + return this.name; + } +} diff --git a/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardUtil.java b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardUtil.java new file mode 100644 index 0000000..632e961 --- /dev/null +++ b/game_pk_doudizhu/src/main/java/extend/pk/uitl/CardUtil.java @@ -0,0 +1,377 @@ +package extend.pk.uitl; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.pk.CardObj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CardUtil { + + + /** + * list to TArray + * + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (CardObj card : list) { + result.addInt(card.card); + } + return result; + } + + public static final CardObj getCard(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.cardMod == eventCard) { + return card; + } + } + return null; + } + + public static final CardObj getCard1(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.card == eventCard) { + return card; + } + } + return null; + } + + /** + * 检测牌数量 + * + * @param eventCard + * @param cardList + * @param num + * @return + */ + public static final boolean checkCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result == num) + return true; + } + } + return false; + } + + public static final boolean checkGoodCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result >= num) + return true; + } + } + return false; + } + + public static final boolean checkShunZi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + } + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkSevenShunzi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + + if (result >= 6) + { + return true; + } + return false; + } + + public static final boolean checkFenJi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+1, cardList, 3)) + { + result++; + } + if (checkGoodCard(eventCard-1, cardList, 3)) + { + result++; + } + } + + if (result >= 2) + { + return true; + } + return false; + } + + public static final boolean checkFourDui(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 1)) + { + result++; + } + + if (checkGoodCard(eventCard+1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 2)) + { + result++; + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 2)) + { + result++; + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkQPai(int eventCard, List cardList) { + int result = 0; + if (eventCard >= 12) + { + result++; + for (CardObj card : cardList) { + if (card.cardMod >= 12) { + result++; + } + } + } + + if (result >= 5) + { + return true; + } + return false; + } + + /** + * TArray to list + * @param list + * @return + */ + public static final List toList(ITArray list) { + List tem = new ArrayList(); + for(int i=0;i getCardNumMap(List cardList) { + Map result = new HashMap(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + return result; + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final void getCardNumMap(Map result,List cardList) { + result.clear(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + public static final void getCardNumMap(Map result,List cardList, CardObj tempCard) { + result.clear(); + result.put(tempCard.cardMod, 1); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final Map> getCardListMap(List cardList) { + Map> result = new HashMap>(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + List list = new ArrayList(); + list.add(card); + result.put(card.cardMod, list); + } else { + List list = result.get(card.cardMod); + list.add(card); + } + } + return result; + } + + static public void removeCard(List cardList, List cards) { + for (int i = 0; i < cards.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).card ==cards.get(i).card) { + cardList.remove(j); + break; + } + } + } + } +} diff --git a/game_pk_doudizhu/src/test/java/game_pk_doudizhu/Main.java b/game_pk_doudizhu/src/test/java/game_pk_doudizhu/Main.java new file mode 100644 index 0000000..e5f03e2 --- /dev/null +++ b/game_pk_doudizhu/src/test/java/game_pk_doudizhu/Main.java @@ -0,0 +1,9 @@ +package game_pk_doudizhu; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_pk_paodekuai/.idea/compiler.xml b/game_pk_paodekuai/.idea/compiler.xml new file mode 100644 index 0000000..da870f6 --- /dev/null +++ b/game_pk_paodekuai/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/.idea/encodings.xml b/game_pk_paodekuai/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_pk_paodekuai/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/.idea/jarRepositories.xml b/game_pk_paodekuai/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_pk_paodekuai/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/.idea/misc.xml b/game_pk_paodekuai/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_pk_paodekuai/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/.idea/uiDesigner.xml b/game_pk_paodekuai/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/game_pk_paodekuai/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/.idea/vcs.xml b/game_pk_paodekuai/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/game_pk_paodekuai/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/config/game-config.xml b/game_pk_paodekuai/config/game-config.xml new file mode 100644 index 0000000..c4a5ea8 --- /dev/null +++ b/game_pk_paodekuai/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.3.9 + 192.168.3.9 + 6842 + 8830 + 66 + true + \ No newline at end of file diff --git a/game_pk_paodekuai/config/log4j.properties b/game_pk_paodekuai/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_pk_paodekuai/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_pk_paodekuai/config/taurus-core.xml b/game_pk_paodekuai/config/taurus-core.xml new file mode 100644 index 0000000..1f91b10 --- /dev/null +++ b/game_pk_paodekuai/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_paodekuai/config/taurus-permanent.xml b/game_pk_paodekuai/config/taurus-permanent.xml new file mode 100644 index 0000000..16a48e7 --- /dev/null +++ b/game_pk_paodekuai/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - test + extend.pk.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_pk_paodekuai/pom.xml b/game_pk_paodekuai/pom.xml new file mode 100644 index 0000000..4b63da7 --- /dev/null +++ b/game_pk_paodekuai/pom.xml @@ -0,0 +1,94 @@ + + 4.0.0 + + com.pk.game_pk_paodekuai + game_pk_paodekuai + 1.0.0 + jar + + game_pk_paodekuai + http://maven.apache.org + + + UTF-8 + + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_paodekuai_puke + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_pk_paodekuai/src/main/java/extend/pk/CardGroup.java b/game_pk_paodekuai/src/main/java/extend/pk/CardGroup.java new file mode 100644 index 0000000..fc7ee92 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/CardGroup.java @@ -0,0 +1,45 @@ +package extend.pk; + +import java.util.List; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.pk.uitl.CardConfig; + +public class CardGroup { + /** + * 当前type + */ + public CardConfig config; + + public int min_card; + /** + * 长度 + */ + public int len = 1; + + public List card_list; + + public ITArray card_list_mp; + + public ITObject toObject(boolean card_size) { + ITObject obj = TObject.newInstance(); + if (card_size) { + obj.putInt("card_size", card_list.size()); + } else { + obj.putTArray("card_list", card_list_mp); + } + + obj.putInt("type", config.type); + obj.putInt("min_card", min_card); + obj.putInt("len", len); + return obj; + } + + public String toString() { + return "{type:" + config + " min_card:" + min_card + " len:" + len + " list:" + card_list + "}"; + } + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/CardObj.java b/game_pk_paodekuai/src/main/java/extend/pk/CardObj.java new file mode 100644 index 0000000..bc2d762 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/CardObj.java @@ -0,0 +1,21 @@ +package extend.pk; + +public class CardObj implements Comparable{ + public int card; + public int cardMod; + + public CardObj(int card) { + this.card = card; + this.cardMod = card % 100; + } + + @Override + public int compareTo(CardObj paramT) { + return cardMod == paramT.cardMod ? 0 : cardMod < paramT.cardMod ? -1 : 1; + } + + @Override + public String toString() { + return card + ""; + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/Config.java b/game_pk_paodekuai/src/main/java/extend/pk/Config.java new file mode 100644 index 0000000..fdcfa66 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/Config.java @@ -0,0 +1,213 @@ +package extend.pk; + +public class Config { + public static final String GAME_DANIAO = "daniao";//打鸟 0不打,1:10,2:20,3:50 + + public static final int XIPAI_SCORE = 10; + + /** + * 玩家的初始手牌数 + */ + public static final String ROOM_CONFIG_CARDNUM = "leaf"; + + /** + * 炸弹带的规则 + */ + public static final String ROOM_CONFIG_SIDAI = "fourBeltThree"; + + public static final String ROOM_CONFIG_SIDAI_2 = "fourDaiTwo"; + public static final String ROOM_CONFIG_SIDAI_3 = "fourDaiThree"; + + /** + * 首局出牌规则 + */ + public static final String ROOM_CONFIG_RULE = "rule"; + + /** + * 第一局系统随机选一张先出,随后赢家先出 + */ + public static final int RULE_RANDOM = 2; + /** + * 第一局黑桃3先出,随后赢家先出 + */ + public static final int RULE_HEITAO3 = 1; + + /** + * 炸弹不能拆 + */ + public static final String ROOM_CONFIG_DEMOLITION = "demolition"; + /** + * 可不必出 + */ + public static final String ROOM_CONFIG_WILL_BE_OUT = "willBeOut"; + + /** + * 3条a是否是炸弹 + */ + public static final String ROOM_CONFIG_THREE_A = "threeA"; + + /** + * 红桃10分翻倍 + */ + public static final String ROOM_CONFIG_HEARTTEN = "heartten"; + + /** + * 飞机少带可接完 + */ + public static final String ROOM_CONFIG_PLANE_LACK = "planelack"; + + /** + * 三张少带可接完 + */ + public static final String ROOM_CONFIG_THREE_LACK = "threelack"; + + /** + * 4个3333 或者 2 AAA 算春天 + */ + public static final String ROOM_CONFIG_MINBOOM = "minboom"; + + /** + * 自动托管功能 + */ + public static final String ROOM_CONFIG_AUTO_TUOGUAN = "autotuoguan"; + + + + /** + * 飘分玩法 + */ + public static final String ROOM_CONFIG_PIAO = "piao"; + + public static final String GAME_NIAO = "831"; + + public static final String GAME_EVT_DANIAO_TIP = "832"; + + public static final String GAME_EVT_DANIAO = "833";//action + + /** + * 三带 飞机带 + */ + public static final String ROOM_CONFIG_SANDAIDAN = "sandaidan"; + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + //-------------------------------牌类型--------------------------------- + /** + * 单牌 + */ + public final static int TYPE_DANPAI = 1; + /** + * 对子 + */ + public final static int TYPE_DUIZI = 2; + /** + * 顺子 + */ + public final static int TYPE_SHUNZI = 3; + /** + * 连对 + */ + public final static int TYPE_LIANDUI = 4; + /** + * 3带2 + */ + public final static int TYPE_3_2 = 5; + /** + * 飞机 + */ + public final static int TYPE_FEIJI = 6; + /** + * 4带3 + */ + public final static int TYPE_4_3 = 7; + + /** + * 炸 + */ + public final static int TYPE_ZHA = 8; + + /** + * 4带2 + */ + public final static int TYPE_4_2 = 9; + + + //-------------------------------协议--------------------------------- + + public static final String GAME_EVT_MING_PAI = "2117"; + /** + * 打鸟协议 + */ + public static final String GAME_PLAYER_DANIAO = "2012"; + + /** + * 打鸟协议 + */ + public static final String GAME_PLAYER_DANIAO_TIP = "2042"; + + /** + * 出牌 + */ + public static final String GAME_DIS_CARD = "1013"; + /** + * 不出 + */ + public static final String GAME_DIS_PASS = "1014"; + /** + * + */ + public static final String GAME_PIAO = "1015"; + /** + * 出牌事件 + */ + public static final String GAME_EVT_DISCARD = "2021"; + /** + * 出牌提示事件 + */ + public static final String GAME_EVT_DISCARD_TIP = "2004"; + /** + * 转盘指向事件 + */ + public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "2016"; + /** + * pass事件 + */ + public static final String GAME_EVT_PASS = "2030"; + /** + * 更新炸弹分数 + */ + public static final String GAME_EVT_UPDATE_BOM_SCORE = "2118"; + + /** + * 小结算 + */ + public static final String GAME_EVT_RESULT1 = "2007"; + + /** + * 飘鸟提示 + */ + public static final String GAME_EVT_PIAO_TIP = "2031"; + public static final String GAME_EVT_PIAO = "2032"; + + /** + * 出牌错误 + */ + public static final String GAME_EVT_PUT_ERROR = "2111"; + + /** + * 发牌协议 + */ + public static final String GAME_EVT_PLAYER_DEAL = "2011"; + + public static final int PUT_ERROR_MUST_OUT_MIN = 0; + public static final int PUT_ERROR_INVALID_TYPE = 1; + public static final int PUT_ERROR_MUST_OUT_MAX = 2; + public static final int PUT_ERROR_BOMB_CHAI =3; + + public static final String SETTLE_WIN_COUNT = "winnum"; + public static final String SETTLE_CHUNTIAN_COUNT = "springnum"; + public static final String SETTLE_BOMB_COUNT = "boomnum"; + public static final String SETTLE_MAX_SCORE = "maxscore"; +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXActionEvent.java b/game_pk_paodekuai/src/main/java/extend/pk/EXActionEvent.java new file mode 100644 index 0000000..75b47c0 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXActionEvent.java @@ -0,0 +1,12 @@ +package extend.pk; + +import com.game.ActionEvent; + +public class EXActionEvent extends ActionEvent{ + + public static final String EVENT_DISCARD = "1013"; + public static final String EVENT_PASS = "1014"; + public static final String EVENT_PIAO= "1015"; + public static final String EVENT_DA_NIAO = "da_niao"; + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXGameController.java b/game_pk_paodekuai/src/main/java/extend/pk/EXGameController.java new file mode 100644 index 0000000..f897e51 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXGameController.java @@ -0,0 +1,623 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + +import com.game.Constant; +import com.game.GameController; +import com.game.Global; +import com.game.data.Player; +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.pk.uitl.CardUtil; + +/** + * + * + */ +public class EXGameController extends GameController { + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_DIS_CARD) + public void RouterDisCard(Session sender, ITObject params, int gid, Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params); + } + + @ActionKey(Config.GAME_DIS_PASS) + public void RouterDisPass(Session sender, ITObject params, int gid, Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PASS, 0, params); + + } + + @ActionKey(Config.GAME_NIAO) + public void RouterDaniao(Session sender, ITObject params, int gid, Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DA_NIAO, 0, params); + + } + + /** + * @param owner + */ + public void daNiaoTipEvent(EXPlayer owner, int reload) { + ITObject response = new TObject(); + response.putInt("niao", owner.room.config.getInt(Config.GAME_DANIAO)); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_EVT_DANIAO_TIP, response); +// ITObject param = new TObject(); +// param.putInt("seat", owner.seat); +// owner.room.broadCastToClient(0, Config.GAME_PLAYER_DANIAO_TIP, param); + + } + + /** + * @param owner 打鸟事件 + */ + public void daNiaoEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("niao", owner.niaoValue); + param.putInt("daNiao", owner.daNiao); + + owner.room.broadCastToClient(0, Config.GAME_EVT_DANIAO, param); + } + + @ActionKey(Config.GAME_PIAO) + public void RouterPiao(Session sender, ITObject params, int gid, Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PIAO, 0, params); + } + + // 改变活动玩家 + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("index", activeSeat); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + public void sendPutError(EXPlayer owner, int code) { + ITObject param = new TObject(); + param.putInt("error", code); + owner.sendEvent(Config.GAME_EVT_PUT_ERROR, param); + } + + /** + * pass + * + * @param owner + */ + public void pass(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + if (Global.loggerDebug) { + Global.logger.info(owner + " pass!"); + } + owner.pass = true; + owner.last_outcard = null; + EXPlayBack pb = (EXPlayBack) room.playBackData; + pb.addPassCommand(owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_PASS, response); + } + + /** + * 票鸟提示 + * + * @param owner + */ + public void piaoTipEvent(EXPlayer owner, int reload) { + + ITObject response = new TObject(); + response.putInt("piao", owner.room.config.getInt(Config.ROOM_CONFIG_PIAO)); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_EVT_PIAO_TIP, response); + } + + /** + * 票鸟事件 + * + * @param owner + */ + public void piaoEvent(EXPlayer owner) { + if (owner.piao == -1) + return; + + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("piao", owner.piao); + owner.room.broadCastToClient(0, Config.GAME_EVT_PIAO, param); + } + + public void outCard(EXPlayer owner, CardGroup ct) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("player", owner.seat); + response.putTObject("card_obj", ct.toObject(false)); + + owner.outCards.addAll(ct.card_list); + + room.lastDiscardSeat = owner.seat; + room.discard = ct; + owner.last_outcard = ct; + owner.pass = false; + room.firstCard = 0; + if (Global.loggerDebug) { + Global.logger.info(owner + " out card:" + ct); + } + EXPlayBack pb = (EXPlayBack) room.playBackData; + pb.addOutCardCommand(owner.seat, ct); + CardUtil.removeCard(owner.cardInhand, ct.card_list); + + response.putInt("remain", owner.cardInhand.size()); + room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + + } + + public void dealCard(EXRoom owner) { + if (owner.targetCards.size() == 0) { + owner.card.init(); + } + + int maxDanPai = 0; + int maxDuizi = 0; + int maxSanZhang = 0; + boolean existWhite = false; + boolean existXingyunhao = false; + boolean existGeneral = false; + boolean existBlack = false; + double white_rate = 0; + + + ArrayList tmpPlayerList = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmpPlayerList.add(player); + } + + Collections.shuffle(tmpPlayerList); + + + for (int i = 0; i < tmpPlayerList.size(); i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + existXingyunhao = true; + } else { + if (player.black_white_status == 0) { + existGeneral = true; + } else if (player.black_white_status == 1) { + existBlack = true; + } else if (player.black_white_status == 2) { + existWhite = true; + } + } + } + + for (int i = 0; i < tmpPlayerList.size(); i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + white_rate = 100 - owner.white_value; + Global.logger.info("dealcards playerid:" + player.playerid + " xingyuhao:" + player.is_white + + " white_value:" + owner.white_value); + } else { + continue; + } + + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + + + Collections.sort(player.cardInhand); + + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry card_entry : playermap.entrySet()) { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) { + maxDanPai = card; + } + + if (num == 2) { + if (card > maxDuizi) { + maxDuizi = card; + } + } + + if (num == 3) { + if (card > maxSanZhang) { + maxSanZhang = card; + } + } + } + } + + for (int i = 0; i < tmpPlayerList.size(); i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + continue; + } else { + if (player.black_white_status == 2) { + white_rate = player.black_white_rate; + Global.logger + .info("dealcards playerid:" + player.playerid + " white player:" + player.black_white_rate); + } else { + continue; + } + } + + if (!existXingyunhao) { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0, 0); + } else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, maxDanPai, + maxDuizi, maxSanZhang); + + } + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && (existGeneral || existBlack)) { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry card_entry : playermap.entrySet()) { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) { + maxDanPai = card; + } + + if (num == 2) { + if (card > maxDuizi) { + maxDuizi = card; + } + } + + if (num == 3) { + if (card > maxSanZhang) { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0; i < tmpPlayerList.size(); i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + continue; + } else { + if (player.black_white_status == 0) { + Global.logger.info( + "dealcards playerid:" + player.playerid + " general player:" + player.black_white_rate); + } else { + continue; + } + } + + + // 指定牌型 +// player.cardInhand = owner.card.deal1(player.seat); + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, maxDanPai, maxDuizi, maxSanZhang); + + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && !existWhite && existBlack) { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry card_entry : playermap.entrySet()) { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (card > maxDanPai) { + maxDanPai = card; + } + + if (num == 2) { + if (card > maxDuizi) { + maxDuizi = card; + } + } + + if (num == 3) { + if (card > maxSanZhang) { + maxSanZhang = card; + } + } + } + } + } + + for (int i = 0; i < tmpPlayerList.size(); i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + continue; + } else { + if (player.black_white_status == 1) { + Global.logger.info("dealcards playerid:" + player.playerid + " black player:" + + (player.black_white_rate + white_rate)); + } else { + continue; + } + } + + if (!existXingyunhao && !existWhite && !existGeneral) { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate + white_rate, + player.black_white_rate + white_rate, 0, 0, 0); + } else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate + white_rate, + player.black_white_rate + white_rate, maxDanPai, maxDuizi, maxSanZhang); + } + + Collections.sort(player.cardInhand); + } + + Global.logger.info("sssss==>" + owner.supCards.size()); + if (owner.targetCards.size() > 0 && owner.adminSeat > 0 && owner.supCards.size() > 0) { + owner.card.cardList = owner.supCards.get(0); + } + + /*for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + }*/ + + // 如果是首局,需要确定庄家 + + + if (owner.bankerSeat == 0) { + + int rule = Config.RULE_RANDOM; + if (owner.config.containsKey(Config.ROOM_CONFIG_RULE)) { + rule = owner.config.getInt(Config.ROOM_CONFIG_RULE); + } + + owner.bankerSeat = this.getBankerSeat(owner); + + this.sendPlayerDeal(owner); + // 如果是随机确定庄家 + if (rule == Config.RULE_RANDOM) { + + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + if (player != null) { + + int len = player.cardInhand.size(); + if (len > 0) { + Random random = new Random(); + int rand_pos = random.nextInt(len); + + this.sendMingPai(owner, player.cardInhand.get(rand_pos).card); + } + } + } + } else { + this.sendPlayerDeal(owner); + } + + } + + /** + * 发生随机牌 用于指示谁首先出牌 + * + * @param owner + */ + private void sendMingPai(EXRoom owner, int card) { + + ITObject param = new TObject(); + param.putInt("mingpai", card); + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + + EXPlayer exPlayer = (EXPlayer) entry.getValue(); + exPlayer.sendEvent(Config.GAME_EVT_MING_PAI, param); + } + ; + } + + /** + * 发牌 + * + * @param owner + */ + private void sendPlayerDeal(EXRoom owner) { + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer exPlayer = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + ITArray handCard = CardUtil.toTArray(exPlayer.cardInhand); + param.putTArray("cards", handCard); + param.putInt("bank_seat", exPlayer.room.bankerSeat); + param.putInt("round", owner.round); + if (Global.loggerDebug) { + Global.logger.info(owner + " deal card:" + exPlayer.cardInhand); + } + exPlayer.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + } + ; + } + + private int getBankerSeatByCard(EXRoom owner) { + for (int index = 3; index <= 13; index++) { + for (int color = 4; color >= 1; color--) { + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (CardObj card : player.cardInhand) { + if (card.card == color * 100 + index) { + owner.firstCard = card.card; + return player.seat; + } + } + } + } + } + return 0; + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + + int rule = Config.RULE_RANDOM; + if (owner.config.containsKey(Config.ROOM_CONFIG_RULE)) { + rule = owner.config.getInt(Config.ROOM_CONFIG_RULE); + } + // 如果是兩人的情況 + if (owner.maxPlayers == 2) { + + // 如果是随机确定庄家 + if (rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + // 如果是黑桃3先出 + else { + seat = getBankerSeatByCard(owner); + + // 如果黑桃3 不在任何一个玩家手里 则随机确定一个庄家 + if (seat == 0) { + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + } + } else { + // 如果是随机确定庄家 + if (rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(3) + 1; + } + // 如果是黑桃3先出 + else { + seat = getBankerSeatByCard(owner); + + } + } + return seat; + } + + public void discardTipEvent(EXPlayer owner) { + ITObject param = new TObject(); + boolean gen = (owner.getRoom().lastDiscardSeat != 0 && owner.getRoom().lastDiscardSeat != owner.seat); + param.putInt("play", gen ? 1 : 0); + if (gen) { + param.putTObject("card_obj", owner.getRoom().discard.toObject(true)); + + } + // 如果可以不出 + + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + + } + + private ITObject getRoomResultData(EXRoom owner, boolean total) { + + ITObject mp = TObject.newInstance(); + + EXPlayer win = owner.win; + + ITArray info = new TArray(); + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + + obj.putInt("score", player.score.total_score); + obj.putInt("winscore", player.score.round_score); + float winCardScore = player.winCardScore * player.getRoom().hpData.getInt("times"); + obj.putFloat("winCardScore", winCardScore / 100); +// Global.logger.info("结算后:player.room.upper_limit_hp:" + player.room.upper_limit_hp); +// Global.logger.info("结算后:winCardScore:" + winCardScore); +// +// if (winCardScore > player.room.upper_limit_hp) { +// obj.putInt("winCardScore", ((int) player.room.upper_limit_hp)/1000); +// } else if (winCardScore < 0 && Math.abs(winCardScore) > player.room.upper_limit_hp) { +// obj.putInt("winCardScore", (0 - (int) player.room.upper_limit_hp)/1000); +// } else { +// obj.putInt("winCardScore", winCardScore/ 1000); +// } + + player.winCardScore = 0; + player.hp_info(obj); + obj.putInt("thisboomnum", player.boomnum); + obj.putInt("piao", player.piao); + obj.putTArray("cards", CardUtil.toTArray(player.cardInhand)); + obj.putBoolean("chuntian", player.chuntian); + + obj.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + obj.putTArray("outCards", CardUtil.toTArray(player.outCards)); + + if (total) { + if (player.score.total_score > 0) { + obj.putInt("daniao", player.getRoom().daNiaoScore * player.getRoom().hpData.getInt("times") / 100); + } else if (player.score.total_score < 0) { + obj.putInt("daniao", + 0 - player.getRoom().daNiaoScore * player.getRoom().hpData.getInt("times") / 100); + } else { + obj.putInt("daniao", 0); + + } + + obj.putInt("award", player.bonusScore); + + if (owner.endType == Constant.END_TYPE_ENTRUST) { + obj.putInt("entrust", player.entrust ? 1 : 0); + } + obj.putTObject("settle_log", player.settleLog.toTObject()); + obj.putInt("total_score", player.score.total_score); + + } + info.addTObject(obj); + } + + if (win != null) { + mp.putInt("winseat", win.seat); + } else { + mp.putInt("winseat", 0); + } + mp.putTArray("remaincards", CardUtil.toTArray(owner.card.cardList)); + mp.putTArray("info", info); + mp.putFloat("xipai_score", Float.parseFloat(owner.xi_pai_score + "") / 100); +// mp.putFloat("xipai_score", owner.xi_pai_score/1000); + + return mp; + } + + + + public void roomResult(EXRoom owner) { + + ITObject result = getRoomResultData(owner, false); + result.putInt("type", 0); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + + /** + * 房间大结算 + * + * @param owner + * @param dissmiss + */ + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + + ITObject result = getRoomResultData(owner, true); + + long t = System.currentTimeMillis() / 1000; + result.putLong("time", t); + result.putInt("type", dissmiss ? 2 : 1); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXMainServer.java b/game_pk_paodekuai/src/main/java/extend/pk/EXMainServer.java new file mode 100644 index 0000000..414dd1c --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXMainServer.java @@ -0,0 +1,70 @@ +package extend.pk; + +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.room.state.RoomStartGameState; + +import extend.pk.player.state.EXPlayerDaNiaoTipState; +import extend.pk.player.state.EXPlayerDiscardState; +import extend.pk.player.state.EXPlayerPassState; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; +import extend.pk.room.state.EXRoomDaNiaoState; +import extend.pk.room.state.EXRoomDealState; +import extend.pk.room.state.EXRoomPiaoState; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.room.state.EXRoomStartGameState; + +/** + * + * + */ +public class EXMainServer extends MainServer { + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + gameCtr = (EXGameController) Global.gameCtr; + registerState(); + } + + private final void registerState() { + + Global.registerState(RoomStartGameState.class, new EXRoomStartGameState()); + Global.registerState(EXRoomSetpState.class, new EXRoomSetpState()); + Global.registerState(EXRoomDealState.class, new EXRoomDealState()); + Global.registerState(EXRoomPiaoState.class, new EXRoomPiaoState()); + + Global.registerState(EXRoomDaNiaoState.class, new EXRoomDaNiaoState()); + Global.registerState(EXPlayerDaNiaoTipState.class, new EXPlayerDaNiaoTipState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerPassState.class, new EXPlayerPassState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXPlayBack.java b/game_pk_paodekuai/src/main/java/extend/pk/EXPlayBack.java new file mode 100644 index 0000000..c885fb5 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXPlayBack.java @@ -0,0 +1,50 @@ +package extend.pk; + + +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; + +import extend.pk.uitl.CardUtil; + +public class EXPlayBack extends BasePlayBack{ + + public EXPlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + } + + protected ITObject getPlayerInfo(Player p) { + + EXPlayer player = (EXPlayer)p; + ITObject obj =super.getPlayerInfo(player); + ITArray cardInhand = CardUtil.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + obj.putInt("piao", player.piao); + + player.hp_info(obj); + return obj; + } + + public void addOutCardCommand(int seat, CardGroup ct) { + ITObject cmdData = ct.toObject(false); + addCommand("OutCard", seat, cmdData); + } + + public void addPassCommand(int seat) { + ITObject cmdData = TObject.newInstance(); + addCommand("pass", seat, cmdData); + } + + public void addNewRoundCommand() { + ITObject cmdData = TObject.newInstance(); + addCommand("newindex", 0, cmdData); + } + + public void addResultCommand(int seat,ITObject cmdData) { + addCommand("result", seat, cmdData); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXPlayer.java b/game_pk_paodekuai/src/main/java/extend/pk/EXPlayer.java new file mode 100644 index 0000000..3479259 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXPlayer.java @@ -0,0 +1,143 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.List; + +import com.game.Global; +import com.game.data.Player; +import com.game.data.Room; +import com.game.data.Score; +import com.taurus.core.entity.ITObject; + +import extend.pk.uitl.CardUtil; + +/** + * + * + */ +public class EXPlayer extends Player { + + /** 默认action时间 20s */ + public static final int DEFAULT_ACTION_TIME = 20000; + /** 默认托管时间 1s */ + public static final int DEFAULT_ENTRUST_TIME = 1000; + /** + * 默认准备时间 20s + */ + public static final int DEFAULT_READY_TIME = 20000; + + // 手牌 + public List cardInhand; + + // 打出的牌 + public List outCards; + + public CardGroup last_outcard; + public boolean pass; + + // 放作弊场第一张牌是否关闭 + public int open = 0; + + /** 春天 */ + public boolean chuntian; + + /** 是否有红桃10 */ + public boolean isHaveRedTen; + + /** 是否打鸟 */ + public int daNiao = 0; + + public int niaoValue = 0; + + public SettleLog settleLog; + + public int boomnum = 0; + public int piao = -1; + public int daniaoScore = 0; + public int bonusScore = 0; + public int awardScore = 0; + public int winCardScore = 0; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + cardInhand = new ArrayList<>(); + outCards = new ArrayList<>(); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_WIN_COUNT, 0); + settleLog.put(Config.SETTLE_CHUNTIAN_COUNT, 0); + settleLog.put(Config.SETTLE_BOMB_COUNT, 0); + settleLog.put(Config.SETTLE_MAX_SCORE, 0); + } + + protected Score newScore() { + return new EXScore(this); + } + + @Override + public ITObject getReloadInfo(boolean self) { + ITObject playerData = super.getReloadInfo(self); + playerData.putInt("card_size", this.cardInhand.size()); + playerData.putInt("piao", this.piao); + if (last_outcard != null) { + playerData.putTObject("last_outcard", last_outcard.toObject(false)); + } + +// if (this.room.isplaying == false) { + if (self) { + playerData.putTArray("handCards", CardUtil.toTArray(this.cardInhand)); + playerData.putTArray("cards", CardUtil.toTArray(this.cardInhand)); + + } else { + Global.logger.info("self:"+self); + Global.logger.info("this:"+this.playerid); + playerData.putTArray("handCards", CardUtil.toTArray(this.outCards)); + playerData.putTArray("cards", CardUtil.toTArray(this.outCards)); + + } + + playerData.putTArray("outCards", CardUtil.toTArray(this.outCards)); + + playerData.putInt("score", score.total_score); + playerData.putInt("winscore", score.round_score); + playerData.putInt("thisboomnum", boomnum); + playerData.putInt("open", open); + playerData.putInt("daNiao", this.daNiao); + playerData.putInt("niao", this.niaoValue); + +// } + return playerData; + } + + @Override + public ITObject getInfo() { + ITObject playerData = super.getInfo(); + playerData.putInt("score", score.total_score); + return playerData; + } + + public void clear() { + super.clear(); + + } + + public void clearEx() { + + this.score.resetRound(); + this.cardInhand.clear(); + this.outCards.clear(); + this.last_outcard = null; + this.pass = false; + this.chuntian = false; + this.isHaveRedTen = false; + this.open = 0; + this.boomnum = 0; + this.piao = -1; + this.daniaoScore = 0; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXRoom.java b/game_pk_paodekuai/src/main/java/extend/pk/EXRoom.java new file mode 100644 index 0000000..7a936a4 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXRoom.java @@ -0,0 +1,424 @@ +package extend.pk; + +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.data.Player; +import com.game.data.Room; +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.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +public class EXRoom extends Room { + public RoomCard card; + + /** 上次打牌的座位 */ + public int lastDiscardSeat; + + /** 打出牌的集合 */ + public CardGroup discard; + + public EXPlayer win; + + public int firstCard = 0; + + public Map card_config_map; + + public int piaoCount = 0; + + public List> supCards; + public List targetCards; + public int adminSeat = 0; + + public int chooseover = 0; + + public int daNiaoCount = 0; + + public boolean isDaniao = true; + + public int daNiaoScore = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + + card = new RoomCard(this, this.config.getInt(Config.ROOM_CONFIG_CARDNUM) == 1 ? 15 : 16, maxPlayers); + card_config_map = new HashMap(); + card_config_map.put(CardConfig.DAN.type, CardConfig.DAN); + card_config_map.put(CardConfig.DUIZI.type, CardConfig.DUIZI); + card_config_map.put(CardConfig.LIANDUI.type, CardConfig.LIANDUI); + card_config_map.put(CardConfig.SHUNZI.type, CardConfig.SHUNZI); + card_config_map.put(CardConfig.ZHA.type, CardConfig.ZHA); + card_config_map.put(CardConfig.FEIJI.type, CardConfig.FEIJI); + card_config_map.put(CardConfig.SAN_2.type, CardConfig.SAN_2); + + boolean sidai_2 = this.config.getBoolean(Config.ROOM_CONFIG_SIDAI_2); + boolean sidai_3 = this.config.getBoolean(Config.ROOM_CONFIG_SIDAI_3); + if (sidai_2) { + card_config_map.put(CardConfig.SI_2.type, CardConfig.SI_2); + } + if (sidai_3) { + card_config_map.put(CardConfig.SI_3.type, CardConfig.SI_3); + } + + 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); + } + + this.isEntrust = true; + + this.supCards = new ArrayList<>(); + this.targetCards = new ArrayList<>(); + this.adminSeat = 0; + this.chooseover = 0; + } + + public void clear() { + super.clear(); + + } + + public void clearEx() { + this.activeSeat = 0; + this.discard = null; + this.lastDiscardSeat = 0; + this.win = null; + this.firstCard = 0; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = super.getReloadInfo(player); + EXPlayer p = (EXPlayer) player; + + data.putTArray("hand_card", CardUtil.toTArray(p.cardInhand)); + data.putTArray("handCards", CardUtil.toTArray(p.cardInhand)); + data.putTArray("outCards", CardUtil.toTArray(p.outCards)); + + data.putInt("open", p.open); + + data.putInt("last_outcard_seat", this.lastDiscardSeat); + + // 游戏结束 + if (this.isplaying == false) { + + if (this.win != null) { + data.putInt("winseat", this.win.seat); + } else { + data.putInt("winseat", 0); + } + if (this.card.getCount() > 0) { + data.putTArray("remaincards", CardUtil.toTArray(this.card.cardList)); + } + } + + return data; + } + + /** + * + * */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + //return Math.round(score / this.hpData.getInt("times")); + return score/this.hpData.getInt("times"); + } + } + return score; + } + + + + public void addScore(Player destPlayer, Player fromPlayer, int score, int type) { + + //// + //System.out.println("fromPlayer.hp.cur_hp"+fromPlayer.hp.cur_hp); + if (multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int) fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + // System.out.println("score:"+score); + // + EXPlayer destEXPlayer = (EXPlayer) destPlayer; + EXPlayer fromEXPlayer = (EXPlayer) fromPlayer; + + if (type == EXScore.WIN || type == EXScore.ZHA) { + destEXPlayer.winCardScore += score; + fromEXPlayer.winCardScore -= score; + } + + + + 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); + //if (type!=EXScore.DANIAO){ + destPlayer.score.round_score += score; + fromPlayer.score.round_score -= score; + // } + destPlayer.score.total_score += score; + fromPlayer.score.total_score -= score; + +// // 重新设置房间最低分数 +// fromPlayer.room.upper_limit_hp -= score; +// destPlayer.room.upper_limit_hp += score; + } + + /** + * 变更炸弹积分 + * + * @param destPlayer + */ + public void addAllBombScore(EXPlayer destPlayer) { + + destPlayer.settleLog.add(Config.SETTLE_BOMB_COUNT); + destPlayer.boomnum++; + + TArray seatData = TArray.newInstance(); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + ITObject seatListData = TObject.newInstance(); + if (fromPlayer != destPlayer) { + this.addScore(destPlayer, fromPlayer, 10, EXScore.ZHA); + seatListData.putInt("bom_score", -10); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + } else { + seatListData.putInt("bom_score", 20); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + } + } + TObject allData = TObject.newInstance(); + allData.putTArray("gold_list", seatData); + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_BOM_SCORE, allData); + } + + + + /** + * 变更游戏积分 + * + * @param destPlayer + */ + public void addAllScore(Player destPlayer) { + + EXPlayer dp = (EXPlayer) destPlayer; + //System.out.println("addallscore"); + boolean bSpring = false; + int score_total = 0; + + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer != destPlayer) { + + if (fromPlayer.cardInhand.size() > 1) { + + int size = fromPlayer.cardInhand.size(); + int score = size; + + if (size == (this.config.getInt(Config.ROOM_CONFIG_CARDNUM) == 1 ? 15 : 16)) { + fromPlayer.chuntian = true; + score = size * 2; + bSpring = true; + } + + if (fromPlayer.isHaveRedTen || dp.isHaveRedTen) { + score = score * 2; + } + + if (dp.piao > 0) { + score += dp.piao; + } + + if (fromPlayer.piao > 0) { + score += fromPlayer.piao; + } + + this.addScore(destPlayer, fromPlayer, score, EXScore.WIN); + score_total = score * 100; + } + } + + } + +// for (Entry entry : this.playerMapByPlaying.entrySet()) { +// EXPlayer fromPlayer = (EXPlayer) entry.getValue(); +// int cur_hp = (int) fromPlayer.hp.cur_hp; +// +// if (fromPlayer != destPlayer) { +// cur_hp = cur_hp - score_total; +// } else { +// cur_hp = cur_hp + score_total; +// } +// // 重置最高输赢分数 +// if (fromPlayer.room.upper_limit_hp == 0 || fromPlayer.room.upper_limit_hp > cur_hp) { +// fromPlayer.room.upper_limit_hp = cur_hp; +// } +// Global.logger.info(fromPlayer.playerid + "当局赢分上限:" + fromPlayer.room.upper_limit_hp); +// +// } + + // 设置玩家的当初最大分数 + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + + if (destPlayer == player) { + player.settleLog.add(Config.SETTLE_WIN_COUNT); + } + + if (player.score.round_score > player.settleLog.get(Config.SETTLE_MAX_SCORE)) { + player.settleLog.put(Config.SETTLE_MAX_SCORE, player.score.round_score); + } + } + // 增加玩家春天的个数 + if (bSpring) { + dp.settleLog.add(Config.SETTLE_CHUNTIAN_COUNT); + } + + Global.logger.info("当局赢分上限:" + destPlayer.room.upper_limit_hp); + + if (false) { + + if (config.containsKey(Config.GAME_DANIAO) && config.getInt(Config.GAME_DANIAO) > 0) { + + EXPlayer winNiao = null; + + for (Entry entry : dp.getRoom().playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.score.total_score > 0) { + winNiao = player; + } + } + if (winNiao != null) { + for (Entry entry1 : dp.getRoom().playerMapBySeat.entrySet()) { + + EXPlayer lostPlayer = (EXPlayer) entry1.getValue(); + if (winNiao.playerid == lostPlayer.playerid) { + continue; + } else { + Global.logger.info(lostPlayer.playerid + ":lostScore-player.daniaoScore:" + + winNiao.getRoom().daNiaoScore); + dp.getRoom().addScore(winNiao, lostPlayer, winNiao.getRoom().daNiaoScore, EXScore.DANIAO); + Global.logger.info(lostPlayer.playerid + ":" + lostPlayer.score.total_score); + + } + } + Global.logger + .info(winNiao.playerid + ":addScore-player.daniaoScore:" + winNiao.getRoom().daNiaoScore); + + } + + } + } + } + + @Override + protected void roomResult() { + //小结算 + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + //强行退出 + for (Entry entry1 : this.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry1.getValue(); + //System.out.println("player:"+player.playerid+"|"+player.hp.total_hp); + //充值打鸟分 + player.score.round_score = 0; + + } + + tuiChuScore(); + boolean settlement = this.redisUpdateHp(); + //for (Entry entry1 : this.playerMapBySeat.entrySet()) { + // EXPlayer player = (EXPlayer) entry1.getValue(); + //System.out.println("2player:"+player.playerid+"|"+player.hp.total_hp); + // } + super.saveMilitaryTotal(dissmiss); + //for (Entry entry1 : this.playerMapBySeat.entrySet()) { + //EXPlayer player = (EXPlayer) entry1.getValue(); + //System.out.println("3player:"+player.playerid+"|"+player.hp.total_hp); + //} + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public void tuiChuScore(){ + //获取获胜 + if (config.containsKey(Config.GAME_DANIAO) && config.getInt(Config.GAME_DANIAO) > 0) { + + EXPlayer winNiao = null; + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.score.total_score > 0) { + winNiao = player; + } + } + if (winNiao != null) { + for (Entry entry1 : this.playerMapBySeat.entrySet()) { + + EXPlayer lostPlayer = (EXPlayer) entry1.getValue(); + if (winNiao.playerid == lostPlayer.playerid) { + continue; + } else { + Global.logger.info(lostPlayer.playerid + ":lostScore-player.daniaoScore:" + winNiao.getRoom().daNiaoScore); + this.addScore(winNiao, lostPlayer, this.daNiaoScore, EXScore.DANIAO); + Global.logger.info(lostPlayer.playerid + ":" + lostPlayer.score.total_score); + } + } + Global.logger + .info(winNiao.playerid + ":addScore-player.daniaoScore:" + winNiao.getRoom().daNiaoScore); + + } + + } + } + + @Override + public void endGame() { + //System.out.println("endGame"); + addAllScore(win); + + this.chooseover = 0; + + EXPlayBack pb = (EXPlayBack) this.playBackData; + + ITObject pbResult = TObject.newInstance(); + + ITArray info = new TArray(); + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.round_score); + obj.putInt("daniao", 0); + obj.putInt("winCardScore", player.winCardScore); + obj.putBoolean("entrust", player.entrust); + info.addTObject(obj); + } + pbResult.putTArray("result", info); + Global.logger.error("pbResult:" + pbResult); + pb.addResultCommand(win.seat, pbResult); + + pb.addNewRoundCommand(); + super.endGame(); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/EXScore.java b/game_pk_paodekuai/src/main/java/extend/pk/EXScore.java new file mode 100644 index 0000000..e40a7a5 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/EXScore.java @@ -0,0 +1,19 @@ +package extend.pk; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + public static final int ZHA = 2; + public static final int DANIAO = 3; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(ZHA, 0); + this.round_log.put(DANIAO, 0); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/RoomCard.java b/game_pk_paodekuai/src/main/java/extend/pk/RoomCard.java new file mode 100644 index 0000000..d7b0910 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/RoomCard.java @@ -0,0 +1,779 @@ +package extend.pk; + +import com.game.Global; +import extend.pk.uitl.CardUtil; + +import java.util.*; + +public class RoomCard { + + public static final int HEART_TEN = 310; + public static final int CARD_A = 14; + public static final int CARD_2 = 15; + public static final int CARD_3 = 3; + public List cardList; + public List cardListTemp; + EXRoom room; + int num; + int maxPlayer; + Random rand = new Random(); + + int boomNumLimit = rand.nextInt(2) + 2; + int sangzhangNumLimit = rand.nextInt(5) + 10; + + int totalBoomNum = 0; + int totalSanZhangNum = 0; + + public RoomCard(EXRoom table,int num,int maxPlayer) { + this.cardList = new ArrayList(); + this.cardListTemp = new ArrayList(); + this.room = table; + this.num = num; + this.maxPlayer = maxPlayer; + } + + public void init() { + this.boomNumLimit = rand.nextInt(2) + 2; + this.sangzhangNumLimit = rand.nextInt(5) + 10; + + this.totalBoomNum = 0; + this.totalSanZhangNum = 0; + this.cardList.clear(); + this.initCard(); + int currentBoomNum = 0; + int currentSanZhangNum = 0; + Map result = new HashMap(); + do { + currentBoomNum = 0; + currentSanZhangNum = 0; + this.shuffle(); + for(int i = 0; i entry : result.entrySet()) { + if(entry.getValue() >= 4) { + currentBoomNum++; + } + else if(entry.getValue() == 3) { + currentSanZhangNum++; + } + } + } + } + }while((currentBoomNum + totalBoomNum > boomNumLimit) || (currentSanZhangNum + totalSanZhangNum > sangzhangNumLimit)); + } + + private void initCard() { + for (int index = 3; index <= 13; index++) { + + if(!(index == 13 && this.num == 15)) { + // 方片 + this.cardList.add(new CardObj(100 + index)); + } + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + + + if(this.num == 16) { + this.cardList.add(new CardObj(214)); + this.cardList.add(new CardObj(314)); + this.cardList.add(new CardObj(414)); + + this.cardList.add(new CardObj(415)); + } + else { + this.cardList.add(new CardObj(214)); + this.cardList.add(new CardObj(415)); + } + + + rand.setSeed(System.currentTimeMillis()); + int len = this.cardList.size(); + for(int i = 0; i < len; i++) { + + int randpos = rand.nextInt(1000000000) % len; + CardObj cotemp = this.cardList.get(i); + + this.cardList.set(i, this.cardList.get(randpos)); + this.cardList.set(randpos,cotemp); + } + + Global.logger.info("RoomCard initCard(): "+this.cardList); + } + + private void shuffle() { + for(int i = 0; i < 100; i++) + { + Collections.shuffle(this.cardList); + } + Random rand = new Random(); + int len = this.cardList.size(); + + for(int i = 0; i < 10000; i++) { + rand.setSeed(System.currentTimeMillis()); + int start = rand.nextInt(len); + int end = rand.nextInt(len); + + CardObj co = this.cardList.get(start); + this.cardList.set(start, this.cardList.get(end)); + this.cardList.set(end, co); + } + } + + public CardObj pop() { + CardObj card = this.cardList.remove(0); + return card; + } + + public int getCount() { + return this.cardList.size(); + } + + public List deal0(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(415)); + dealCards.add(new CardObj(214)); + dealCards.add(new CardObj(314)); + dealCards.add(new CardObj(414)); + + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + } + + return dealCards; + } + + public List deal1(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + dealCards.add(new CardObj(303)); + dealCards.add(new CardObj(405)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + dealCards.add(new CardObj(304)); + dealCards.add(new CardObj(404)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(111)); + dealCards.add(new CardObj(211)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(406)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(407)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(209)); + + dealCards.add(new CardObj(112)); + dealCards.add(new CardObj(212)); + dealCards.add(new CardObj(312)); + dealCards.add(new CardObj(412)); + + dealCards.add(new CardObj(113)); + dealCards.add(new CardObj(213)); + } + + return dealCards; + } + + + public List deal2(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(205)); + dealCards.add(new CardObj(305)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(110)); + + } + else if(seat == 2) { + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + + //dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal3(int seat){ + + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(111)); + dealCards.add(new CardObj(112)); + dealCards.add(new CardObj(113)); + dealCards.add(new CardObj(114)); + dealCards.add(new CardObj(215)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal4(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(207)); + dealCards.add(new CardObj(307)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(208)); + dealCards.add(new CardObj(308)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(209)); + dealCards.add(new CardObj(309)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(210)); + dealCards.add(new CardObj(310)); + dealCards.add(new CardObj(410)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List deal6(int seat){ + List dealCards = new ArrayList(); + + if(seat == 1) { + dealCards.add(new CardObj(103)); + dealCards.add(new CardObj(203)); + + dealCards.add(new CardObj(104)); + dealCards.add(new CardObj(204)); + + dealCards.add(new CardObj(105)); + dealCards.add(new CardObj(105)); + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(106)); + + dealCards.add(new CardObj(107)); + dealCards.add(new CardObj(107)); + + dealCards.add(new CardObj(108)); + dealCards.add(new CardObj(108)); + + dealCards.add(new CardObj(109)); + dealCards.add(new CardObj(109)); + + dealCards.add(new CardObj(110)); + dealCards.add(new CardObj(110)); + } + else if(seat == 2) { + + dealCards.add(new CardObj(106)); + dealCards.add(new CardObj(206)); + dealCards.add(new CardObj(306)); + + dealCards.add(new CardObj(107)); + } + + return dealCards; + } + + public List dealTest(int seat){ + + List dealCards = deal2(seat); + if(dealCards == null || dealCards.size() == 0) { + + dealCards = deal(); + } + + return dealCards; + } + + // 发牌 + public List deal(boolean room_white, boolean is_white, double room_rate, int white_black_status, double black_white_rate, double black_black_rate, int maxDanPai, int maxDuizi, int maxSanZhang) { + List dealCards = new ArrayList(); + shuffle(); + + double rand1 = Math.random() % 100 * 100; + for (int index = 0; index < this.num ; index++) { + if (room_white && is_white) + { + if (rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards xingyun card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (white_black_status == 2) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards white card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else if (white_black_status == 1) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards black card"); + } + } +; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, true, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, true, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (room_white && rand1 > room_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxDanPai == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, maxDanPai, maxDuizi, maxSanZhang)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, 0, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + } + } + } + shuffle(); + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + + boolean isGooodCard(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + if (isGooodCard2(card, dealCards, black, maxDanPai, maxDuizi, maxSanZhang)) { + return true; + } + + if (maxDanPai != 0) + { + if (card >= maxDanPai) + { + return true; + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 1)) { + if (card >= maxDuizi) + { + return true; + } + } + } + + if (maxDanPai != 0) + { + if (CardUtil.checkGoodCard(card, dealCards, 2)) { + if (card >= maxSanZhang) + { + return true; + } + } + } + + return false; + } + + boolean isGooodCard2(int card, List dealCards, boolean black, int maxDanPai, int maxDuizi, int maxSanZhang) + { + double rand = Math.random() % 100 * 100; + if (black) + { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 70) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 70) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 70) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 70) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 70) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, 3) && rand < 50) { + Global.logger.info("remove zhadan"); + return true; + } + + if (CardUtil.checkFenJi(card, dealCards) && rand < 50) + { + Global.logger.info("remove feiji"); + return true; + } + + if (CardUtil.checkSevenShunzi(card, dealCards) && rand < 50) + { + Global.logger.info("remove sevent shun zi"); + return true; + } + + if (CardUtil.checkFourDui(card, dealCards) && rand < 50) + { + Global.logger.info("remove four dui"); + return true; + } + + if (CardUtil.checkQPai(card, dealCards) && rand < 50) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + + + return false; + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < this.num ; index++) { + dealCards.add(this.pop()); + } + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/SettleLog.java b/game_pk_paodekuai/src/main/java/extend/pk/SettleLog.java new file mode 100644 index 0000000..eb6b8c6 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/SettleLog.java @@ -0,0 +1,44 @@ +package extend.pk; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDaNiaoTipState.java b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDaNiaoTipState.java new file mode 100644 index 0000000..805d0f7 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDaNiaoTipState.java @@ -0,0 +1,85 @@ +package extend.pk.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; + +import extend.pk.Config; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; + +/** + * + */ +public class EXPlayerDaNiaoTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.daNiaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.daNiaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + private void _action(EXPlayer owner,int id,int gid) { + //记录打鸟 + if (owner.room.config.getInt(Config.GAME_DANIAO)==1){ + //10分 + owner.niaoValue = 10; + }else if(owner.room.config.getInt(Config.GAME_DANIAO)==2){ + //20分 + owner.niaoValue = 20; + }else if(owner.room.config.getInt(Config.GAME_DANIAO)==3){ + //30分 + owner.niaoValue = 30; + } + owner.daNiao = id; + Global.logger.info("owner.daNiao:"+owner.daNiao); + if(id==1) { + owner.getRoom().daNiaoScore+=owner.niaoValue; + } + Global.logger.info("owner.getRoom().daNiaoScore:"+owner.getRoom().daNiaoScore); + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().daNiaoCount --; + EXMainServer.gameCtr.daNiaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_DA_NIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_DA_NIAO)) { + ITObject netParam = (ITObject) param; + int niaoflag = netParam.getInt("niaoflag"); + _action(owner, niaoflag, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + + } + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..5776b29 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java @@ -0,0 +1,439 @@ +package extend.pk.player.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.game.Global; +import com.game.Router; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import com.taurus.core.entity.TObject; +import extend.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.RoomCard; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.uitl.CardCheck; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +/** + * 等待玩家出牌状态 + * + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + // 设置防作弊场开牌的标志 + owner.open = 1; + + EXRoom room = owner.getRoom(); + + //如果最后一次打牌的座位等于自己 并且牌型是炸弹 + if(room.lastDiscardSeat == owner.seat&&room.discard.config == CardConfig.ZHA) { + + room.addAllBombScore(owner);//炸弹玩家增加积分 + } + + //如果最后一次的打牌的座位不等于零并且最后一次打牌的座位不等于自己 + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + boolean bNextBaodan = false; + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + bNextBaodan = true; + } + CardGroup big_ct = CardCheck.genOutCard(owner.cardInhand, room.discard,room.config,bNextBaodan); + if(big_ct==null) { + owner.stateMachine.changeState(Global.getState(EXPlayerPassState.class)); + + return; + } + else { + + if(big_ct.config.type == Config.TYPE_ZHA ) { + // 如果能出完,就自动出完 + if(big_ct.card_list.size() == owner.cardInhand.size()) { + + doAction(owner,big_ct,true); + return; + } + } + else { + + boolean bContainZha = false; + + boolean bThreeA = false; + if(owner.room.config.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = cardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + bContainZha = true; + } + + // 三条A 不能拆 + if(entry.getKey() == RoomCard.CARD_A && bThreeA && handNum >= 3) { + + bContainZha = true; + } + } + + if(big_ct.card_list.size() == owner.cardInhand.size() && bContainZha == false) { + doAction(owner,big_ct,true); + return; + } + } + } + } + else { + + // 自动出牌 + CardGroup auto_ct = CardCheck.autoOutLastHand(owner.cardInhand, room.config,false); + if(auto_ct != null) { + + doAction(owner,auto_ct,true); + + return; + } + } + EXMainServer.gameCtr.discardTipEvent(owner); + + owner.startActionTimer(); + } + + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.bankerSeat = owner.seat; + room.win = owner; + Timer passTimer = new Timer(1000, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + room.endGame(); + } + }); + room.addTimer(passTimer); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + + ITObject netParam = (ITObject) param; + ITArray card_list = netParam.getTArray("card"); + ITArray all_card = netParam.getTArray("all_card"); + + if (all_card != null) + { + ArrayList temCardList = new ArrayList(); + for(int i=0;i< all_card.size();++i) { + temCardList.add(all_card.getInt(i)); + } + Collections.sort(temCardList); + + ArrayList temCardList2 = new ArrayList(); + for(int i=0;i< owner.cardInhand.size();++i) { + temCardList2.add(owner.cardInhand.get(i).card); + } + Collections.sort(temCardList2); + + if (!temCardList.equals(temCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + // 如果出的牌的个数为0 或者大于手牌的数目 则是非法的 + if (card_list.size() == 0 || card_list.size() > owner.cardInhand.size()) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + List list = CardUtil.toList(card_list); + + + for(CardObj card : list) { + + boolean bNotExisted = false; + + for(CardObj handc : owner.cardInhand) { + if(card.card == handc.card) { + bNotExisted = true; + break; + } + } + + if(bNotExisted == false) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + if(owner.getRoom().firstCard != 0 && CardUtil.getCard1(owner.getRoom().firstCard, list) == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MIN); + return; + } + + CardGroup ct = CardCheck.getType(list, owner.room.config); + if(ct == null) { + + if (CardCheck.isConfig4_2_and_4_3(owner.room.config)) { + //四带二/四带三摆尾 + if (list.size() == owner.cardInhand.size()) { //最后一把 + Map cardMap =CardUtil.getCardNumMap(list); + + if(owner.room.config.containsKey(Config.ROOM_CONFIG_SIDAI_2) && owner.room.config.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) { + if (list.size() == 5) { + ct = CardCheck.checkSiWithTwo(cardMap,owner.room.config); + } + } + + if (ct == null) { + if(owner.room.config.containsKey(Config.ROOM_CONFIG_SIDAI_3) && owner.room.config.getBoolean(Config.ROOM_CONFIG_SIDAI_3)) { + if (list.size() == 5 || list.size() == 6) { + ct = CardCheck.checkSiWithThree(cardMap,owner.room.config); + } + } + } + + if (ct != null) { + for(CardObj cardObj : owner.cardInhand) { + ct.card_list.add(cardObj); + } + ct.card_list_mp = CardUtil.toTArray(ct.card_list); + } + } + } + + + if (ct == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + boolean bThreeA = false; + if(owner.room.config.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + //验证客户端发过来的类型 + if(!CardCheck.tryType(ct,owner.cardInhand.size(),owner.room.config)) { + + // tryType 判断3条a判断不出来, 所以 + if(!(ct.config.type == Config.TYPE_ZHA && + card_list.size() == 3 && + bThreeA && + CardUtil.checkCard(RoomCard.CARD_A, list, 3))) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + // 如果炸弹不允许拆分,则检测非炸弹和4带三的牌型,看他们是否拆分了炸弹 + if(owner.room.config.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + + if(ct.config.type != Config.TYPE_ZHA ) { + + Map hangCardMap =CardUtil.getCardNumMap(owner.cardInhand); + Map cardMap =CardUtil.getCardNumMap(list); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = hangCardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + + // 三条A 不能拆 + if(entry.getKey() == RoomCard.CARD_A && bThreeA && handNum == 3) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + } + } + } + + doAction(owner,ct,false); + break; + + case EXActionEvent.EVENT_PASS: + + if(owner.room.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1) { + return; + } + pass(owner); + + break; + case EXActionEvent.EVENT_OFFLINE: + owner.startActionTimer(); + break; + case EXActionEvent.EVENT_TIMER_AUTO: + case EXActionEvent.EVENT_ENTRUST: + + AutoOut(owner); + break; + } + } + + private void AutoOut(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + CardGroup big_ct = null; + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && room.discard.config.type ==Config.TYPE_DANPAI && playerNext.cardInhand.size() == 1) { + + Map> cardMap =CardUtil.getCardListMap(owner.cardInhand); + big_ct = CardCheck.selectDanpai(cardMap,room.discard,room.config,true); + }else { + big_ct = CardCheck.tryBig(owner.cardInhand, room.discard); + } + + if (big_ct != null) { + big_ct.card_list_mp = CardUtil.toTArray(big_ct.card_list); + doAction(owner,big_ct,true); + } else { + Global.logger.info("big_ct == null pass !!!!!!!!!!!!"); + pass(owner); + } + + }else { + + // 在托管或者自动出牌的时候 系统先出炸弹,如果炸弹没有 再出单张 + // 将来可以把这个函数做的能智能一些,不光可以出炸弹 也可以出顺子飞机等等 + CardGroup out_ct = CardCheck.autoOut(owner.cardInhand, owner.room.config); + if(out_ct == null) { + + out_ct = new CardGroup(); + List out_list = new ArrayList<>(); + out_ct.card_list = out_list; + out_ct.config = CardConfig.DAN; + out_ct.len = 1; + + if(room.firstCard != 0) { + CardObj co = CardUtil.getCard1(room.firstCard, owner.cardInhand); + out_list.add(co); + } + else + { + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + out_list.add(owner.cardInhand.get(owner.cardInhand.size() -1)); + }else { + out_list.add(owner.cardInhand.get(0)); + } + } + } + + out_ct.card_list_mp = CardUtil.toTArray(out_ct.card_list); + out_ct.min_card = out_ct.card_list.get(0).cardMod; + + doAction(owner,out_ct,true); + } + } + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + private void doAction(EXPlayer owner,CardGroup ct,boolean skip) { + + EXRoom room = owner.getRoom(); + boolean outcard = true; + if(!skip) { + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + outcard = CardCheck.tryCompete(room.discard, ct,room.config); + } + + // 如果玩家的下家只有一张牌,玩家出单张必须是最大的 + if(outcard && ct.config.type == Config.TYPE_DANPAI) { + + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && playerNext.cardInhand.size() == 1) { + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Integer number : cardMap.keySet()) { + + if(ct.min_card < number) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MAX); + return; + } + } + } + } + } + if(!outcard) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + EXMainServer.gameCtr.outCard(owner,ct); + + if (owner.cardInhand.size() == 0) { + // 如果最后一手牌是炸弹 则需要添加炸弹分 + if(ct.config.type == Config.TYPE_ZHA) { + + room.addAllBombScore(owner);//炸弹玩家增加积分 + } + this.over(owner); + } else { + this.toNextState(owner); + } + } + + +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPassState.java b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPassState.java new file mode 100644 index 0000000..bebb1b4 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPassState.java @@ -0,0 +1,54 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; + +/** + * 等待玩家Pass状态 + * + * + */ +public class EXPlayerPassState extends StateBase { + + private void pass(EXPlayer owner) { + + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + + } + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if(!owner.entrust) { + Timer passTimer = new Timer(100, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + pass(owner); + } + }); + room.addTimer(passTimer); + }else { + pass(owner); + } + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d2ecadb --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,64 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; + +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; + + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.piaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piao = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + EXMainServer.gameCtr.piaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_PIAO)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDaNiaoState.java b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDaNiaoState.java new file mode 100644 index 0000000..706d164 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDaNiaoState.java @@ -0,0 +1,42 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.EXActionEvent; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDaNiaoTipState; + +public class EXRoomDaNiaoState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.daNiaoCount = owner.maxPlayers; + Global.logger.info("owner.daNiaoCount:" + owner.daNiaoCount); + Global.logger.info("owner.isDaniao:" + owner.isDaniao); + + if (!owner.isDaniao) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + return; + } + + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerDaNiaoTipState.class)); + } + owner.isDaniao = false; + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if (cmd.equals(EXActionEvent.EVENT_DA_NIAO)) { + Global.logger.info("owner.daNiaoCount:" + owner.daNiaoCount); + if (owner.daNiaoCount <= 0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + + } + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDealState.java b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDealState.java new file mode 100644 index 0000000..d15d73a --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomDealState.java @@ -0,0 +1,114 @@ +package extend.pk.room.state; + + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.pk.Config; +import extend.pk.EXMainServer; +import extend.pk.EXPlayBack; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.uitl.CardCheck; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 房间发牌状态 + * + * + */ +public class EXRoomDealState extends StateBase { + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + owner.clearEx(); + owner.startGame(); + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 3000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //owner.card.init(); + if(owner.bankerSeat!=0&&!owner.playerMapBySeat.containsKey(owner.bankerSeat)) { + owner.bankerSeat = 0; + } + EXMainServer.gameCtr.dealCard(owner); + + owner.playBackData = new EXPlayBack(owner); + owner.config.putInt(Config.ROOM_CONFIG_HEARTTEN,2); + if(owner.config.getInt(Config.ROOM_CONFIG_MINBOOM) == 1) { + + int startSpringSeat = 0; + int seat = owner.bankerSeat; + do { + + EXPlayer player = (EXPlayer)owner.playerMapBySeat.get(seat); + if(CardCheck.checkStartSpring(player.cardInhand)) { + + startSpringSeat = seat; + break; + } + }while(seat != owner.bankerSeat); + + if(startSpringSeat != 0) { + owner.bankerSeat = startSpringSeat; + owner.win = (EXPlayer)owner.playerMapBySeat.get(startSpringSeat); + owner.endGame(); + return; + } + } + + + + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomPiaoState.java b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..dbb1ce8 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomPiaoState.java @@ -0,0 +1,31 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.EXActionEvent; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO)) { + if(owner.piaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomSetpState.java b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ce6843c --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomSetpState.java @@ -0,0 +1,35 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDiscardState; + +/** + * 房间转换座位 + * + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomStartGameState.java b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..2e1f5ad --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/room/state/EXRoomStartGameState.java @@ -0,0 +1,43 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.Config; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +/** + * 房间开始状态 + * + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.clearEx(); + player.ready = false; + } + + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + // TODO Auto-generated method stub + if (owner.config.containsKey(Config.GAME_DANIAO) && owner.config.getInt(Config.GAME_DANIAO) != 0) { + owner.stateMachine.changeState(Global.getState(EXRoomDaNiaoState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardCheck.java b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardCheck.java new file mode 100644 index 0000000..bebeb44 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardCheck.java @@ -0,0 +1,1310 @@ +package extend.pk.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +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.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.RoomCard; + + +/** + * + * + */ +public class CardCheck { + + /** + * 服务器跟牌判定 + * @param cardInhand + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup genOutCard(List cardInhand,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + Map> cardMap =CardUtil.getCardListMap(cardInhand); + int handCardSize = cardInhand.size(); + // 如果有炸弹 并且玩家手上仅剩下炸弹 就不用找了 直接出牌就可以了 + cg = selectZha(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + + // 如果别的玩家出的是一张单牌,则寻找一个合适的单牌,如果找不到就用炸弹,炸弹没有则过 + if(out.config.type == Config.TYPE_DANPAI) { + + CardGroup tempCg = selectDanpai(cardMap,out,roomConfig,nextBaodan); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是不能带牌的牌型(对子,顺子,连队)则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_DUIZI + || out.config.type == Config.TYPE_SHUNZI + || out.config.type == Config.TYPE_LIANDUI) { + + CardGroup tempCg = selectWithoutCardType(handCardSize,cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的三带牌型 ,则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_3_2) { + + boolean bLack = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_LACK) == 1) { + bLack = true; + } + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的飞机牌型,则寻找合适的牌型,如果找不到用则炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_FEIJI) { + + boolean bLack = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_PLANE_LACK) == 1) { + bLack = true; + } + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果是四带二或者四带三 就不处理了,如果有炸弹,则玩家自己去选择是炸还是跟,如果没有炸弹 玩家也大不了,所以后面就不用判断了 + if(cg != null) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectZha(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + + boolean bThreeA = false; + if(roomConfig != null && roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int minValue = 0; + if(out.config.type == Config.TYPE_ZHA) { + minValue = out.min_card; + } + + for(Map.Entry> entry : cardMap.entrySet()) { + + if(entry.getValue().size() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA && entry.getValue().size() == 3)) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + + return cg; + } + + /** + * 选择单牌 + * @param cardMap + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup selectDanpai(Map> cardMap,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + int minValue = out.min_card + 1; + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(!nextBaodan) { + + for(int i = minValue; i <= 15; i++) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3 ))) { + + } + else { + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + else + { + for(int i = 15; i >= minValue; i--) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() == 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3))) { + + } + else { + + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + + return cg; + } + + /** + * 选择不需要带牌的牌型 + * @param handCardSize + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectWithoutCardType(int handCardSize,Map> cardMap,CardGroup out,ITObject roomConfig) { + CardGroup cg = null; + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>14)) { + + int count =0; + + for(int i = min_card; i <= 14;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >=out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + private static CardGroup selectWithCardType(List cardInhand, + Map> cardMap, + CardGroup out, + ITObject roomConfig, + boolean bLack) { + + CardGroup cg = null; + + int handCardSize = cardInhand.size(); + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>14)) { + + int count =0; + + for(int i = min_card; i <= 14;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() == 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >= out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + int sd = out.config.repeat_num * len + out.config.with_card_num * len; + + boolean sandaidan = roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) && roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 1; + if(sandaidan) { + + if(handCardSize < out.card_list.size()) { + return cg; + } + } + else { + + if(bLack == false && handCardSize < sd) { + + return cg; + } + } + + // 新建一个临时的列表,来保存剩余的牌 + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + // 如果剩余的牌有炸弹,则需要把剩余牌中的炸弹对应的牌从临时列表中剔除,以确定是否有足够的单牌 + // 如果因为剔除的原因,最后牌型不能做成,那就提示他有炸弹出就可以了 + Map> reservedCardMap = CardUtil.getCardListMap(tem_list); + int duiNum = 0; + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num == 4 || (entry.getKey() == RoomCard.CARD_A && bThreeA && num == 3)) { + + CardUtil.removeCard(tem_list, entry.getValue()); + } + + if(num >= 2) { + duiNum++; + } + } + + + if(sandaidan) { + + boolean isDui = sd == out.card_list.size(); + if(isDui) { + + if(duiNum < len) { + return cg; + } + + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num >= 2 && num < 4) { + card_list.add(entry.getValue().get(0)); + card_list.add(entry.getValue().get(1)); + } + } + + }else { + + for(int m = 0; m < len; m++) { + card_list.add(tem_list.get(m)); + } + } + } + else { + + // 如果手牌数多于牌型的基本要求 + if(handCardSize >= sd) { + + if(tem_list.size() < out.config.with_card_num * len) { + return cg; + } + + for(int m = 0; m < out.config.with_card_num * len; m++) { + card_list.add(tem_list.get(m)); + } + } + else { + + card_list.addAll(tem_list); + } + } + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + /** + * 得到所出牌的牌型 + * @param cardOut + * @param roomConfig + * @return + */ + public static CardGroup getType(List cardOut,ITObject roomConfig) { + + CardGroup cg = autoOutLastHand(cardOut,roomConfig,true); + if(cg == null) { + + int len = cardOut.size(); + int sidai = roomConfig.getInt(Config.ROOM_CONFIG_SIDAI); + // 看看所处的牌是否 4带2 或者4带3 + if((len == 6 && sidai == 2) || (len == 7 && sidai == 3)) { + + Map cardMap =CardUtil.getCardNumMap(cardOut); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + if(len == 6) { + cg.config = CardConfig.SI_2; + } + else{ + cg.config = CardConfig.SI_3; + } + + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj : cardOut) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + } + } + } + + return cg; + } + + /** + * + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOutLastHand(List cardInhand,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + int len = cardInhand.size(); + //Global.logger.info( "auto out len:" + len); + if(len == 1) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DAN; + cg.min_card = cardInhand.get(0).cardMod; + cg.len = 1; + } + else if(len == 2) { + cg = checkTwo(cardMap); + } + else if(len == 3) { + + cg = checkThree(cardMap,roomConfig); + } + else if(len == 4) { + + cg = checkFour(cardMap,roomConfig); + } + else if(len == 5) { + + if(isConfig4_2_and_4_3(roomConfig) && getMaxCardNum(cardMap) == 4){//四带一 + return null;//不能判为三带二 + } + + cg = checkFive(cardMap,roomConfig,bSpecial); + } + else{ + if (bSpecial) { + if (len == 6) { + cg = checkSiWithTwo(cardMap,roomConfig); + } + + if (len == 7) { + cg = checkSiWithThree(cardMap,roomConfig); + } + } + + if (cg == null) { + cg = checkShunzi(len,cardMap,roomConfig); + if(cg == null) { + cg = checkLiandui(len,cardMap,roomConfig); + if(cg == null) { + cg = checkFeiji(len,cardMap,roomConfig,bSpecial); + } + } + } + } + + if(cg != null) { + + for(CardObj cardObj : cardInhand) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + private static int getMaxCardNum(Map cardMap) { + int maxNum = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue() > maxNum) { + maxNum = entry.getValue(); + } + } + + return maxNum; + } + + public static boolean isConfig4_2_and_4_3(ITObject roomConfig) { + if((roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_2) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) + ||(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_3) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_3))){ + return true; + } else { + return false; + } + } + + private static CardGroup checkTwo(Map cardMap) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DUIZI; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + return cg; + } + + private static CardGroup checkThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3) { + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA == true) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + } + return cg; + } + + private static CardGroup checkFour(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 3) { + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA) { + return cg; + } + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + if(minCard != 0 && maxCard != 0 && minCard + 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = 2; + } + } + } + return cg; + } + + private static CardGroup checkFive(Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3 /*|| (entry.getValue() == 4 && bSpecial == true)*/) { + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA) { + return cg; + } + + if(!roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) || roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 0) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else { + + if(entry.getValue() != 4 && cardMap.size() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + + break; + } + else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 5 && minCard != 0 && maxCard != 0 && minCard + 4 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 5; + } + } + } + + return cg; + } + + public static CardGroup checkSiWithTwo(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + if(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_2) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + break; + } + } + + return cg; + } + + public static CardGroup checkSiWithThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + if(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_3) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_3)) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_3; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + break; + } + } + + return cg; + } + + private static CardGroup checkShunzi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkLiandui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + return cg; + } + + private static CardGroup checkFeiji(int len,Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int[] cardThreeCount = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0}; + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int num2 = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + // 如果有炸弹 则不允许自动出牌 + if(bSpecial == false && (entry.getValue() == 4 || (entry.getKey() == RoomCard.CARD_A && entry.getValue() == 3 && bThreeA == true))) { + return cg; + } + + if(entry.getValue() >= 3) { + cardThreeCount[entry.getKey()] = 1; + } + else if(entry.getValue() == 2) { + num2++; + } + } + + int left = 0; + int right = 0; + + for(int i = 4; i < cardThreeCount.length; i++) { + + if(left == 0) { + + if(cardThreeCount[i] == 1 && cardThreeCount[i - 1] == 1) { + left = i - 1; + right = i; + } + } + else { + // 如果有连续的继续寻找 + if(cardThreeCount[i] == 1 && right + 1 == i) { + + right = i; + } + else + { + left = 0; + right = 0; + } + } + // 判断出来一个顺子,就判定一下是否可以全部出 + if(left != 0 && right != 0) { + + int threeCount = right - left + 1; + int sl = threeCount * 5; + + if(!roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) || roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 0) { + + if(len <= sl) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + }else { + + int withMin = threeCount * 4; + if(len == withMin || num2 == threeCount || len == threeCount * 3) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + } + + } + } + + return cg; + } + + /** + * 自动出牌 + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOut(List cardInhand,ITObject roomConfig) { + + CardGroup cg = null; + + //支持3A炸弹 + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + // 寻找炸弹 + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA == true && entry.getValue() == 3)) { + + cg = new CardGroup(); + List out_list = new ArrayList<>(); + + cg.card_list = out_list; + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj :cardInhand) { + + if(cardObj.cardMod == entry.getKey()) { + out_list.add(cardObj); + } + } + } + } + + return cg; + } + + + /** + * 验证牌型 + * @param ct + * @param left_count + * @return + */ + public static boolean tryType(CardGroup ct,int left_count,ITObject roomConfig) { + List cardInhand = ct.card_list; + int size = cardInhand.size(); + CardConfig config = ct.config; + if(size config.max_card_num) { + return false; + } + int len = ct.len; + if(len 0 && size == left_count) { + // 牌太少了 出牌太多了 + if(size < len*config.repeat_num || size > tem_size) { + return false; + } + // 如果带的牌不够 + if(size < tem_size) { + // 如果是三张 或者三带 + if(ct.config.type == Config.TYPE_3_2) { + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_LACK) == 0){ + return false; + } + } + // 如果是飞机 + else if(ct.config.type == Config.TYPE_FEIJI) { + if(roomConfig.getInt(Config.ROOM_CONFIG_PLANE_LACK) == 0){ + return false; + } + } + } + } + //没有带牌 没有全出 + else { + if(tem_size!=size) { + return false; + } + } + } + + int min_card = ct.min_card; + int max_card = min_card+len -1; + if(len>1&&max_card>14) { + return false; + } + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(int i=min_card;i<=max_card;++i) { + if(!cardMap.containsKey(i)) { + return false; + } + if(cardMap.get(i) < config.repeat_num) { + return false; + } + } + return true; + } + + + + /** + * 比牌大小 + * @param banker + * @param other + * @return + */ + public final static boolean tryCompete(CardGroup banker, CardGroup other,ITObject roomConfig) { + int bankerCradType = banker.config.type; + int otherCradType = other.config.type; + + if(bankerCradType !=Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) { + return true; + } + if(bankerCradType != otherCradType) { + return false; + } + + if(other.min_card > banker.min_card) { + if(otherCradType == Config.TYPE_ZHA) { + + return true; + } + else + { + + if(other.len == banker.len) { + + if(otherCradType == Config.TYPE_3_2 || otherCradType == Config.TYPE_FEIJI) { + + boolean sandaidan = roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) && roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 1; + if(sandaidan) { + if(other.card_list.size() != banker.card_list.size()) { + return false; + } + } + } + + return true; + } + else + { + return false; + } + } + } + + return false; + } + + + public final static CardGroup tryBig(List cardInhand,CardGroup other) { + + List card_list = new ArrayList(); + int size = cardInhand.size(); + CardConfig config = other.config; + Map> cardMap = null; + int len = other.len; + + if(size >= len*config.repeat_num) { + + int min_card = other.min_card + 1;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + + int max_card = min_card+len -1; //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + + if(!(len>1&&max_card>14)) {//长度如果大于一并且最大的牌 + + int count =0; + cardMap = CardUtil.getCardListMap(cardInhand); + int max = len>1?14:15; + for(int i=min_card;i<=max;++i) { + + List list =cardMap.get(i); + + if(cardMap.containsKey(i)&&list.size() >=config.repeat_num) { + + //不出炸牌 + if(other.config.type !=Config.TYPE_ZHA && list.size()>=4) { + count=0; + card_list.clear(); + continue; + } + + for(int k=0;k0) { + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + //不把炸牌带出去 + int rcard_size = 0; + rcard: + for(int k=0;k tem_list1 = cardMap.get(card); + if(tem_list1.size()>=4) { + CardUtil.removeCard(tem_list, tem_list1); + rcard_size += 4; + break rcard; + } + } + int with_card_size = config.with_card_num * len; + if(rcard_size == 0) { + with_card_size = tem_list.size()=4) { + if(cardMap==null) { + cardMap = CardUtil.getCardListMap(cardInhand); + } + + for (Entry> entry : cardMap.entrySet()) { + int card = entry.getKey(); + List list = entry.getValue(); + if(list.size() >=4) { + CardGroup ct = new CardGroup(); + ct.config = CardConfig.ZHA; + ct.card_list = list; + ct.len = 1; + ct.min_card = card; + return ct; + } + } + } + return null; + } + + public static boolean checkStartSpring(List cardInhand) { + + boolean bRet = false; + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + if(cardMap.getOrDefault(RoomCard.CARD_3, 0) == 4) { + + bRet = true; + } + else if(cardMap.getOrDefault(RoomCard.CARD_2, 0) == 1 && cardMap.getOrDefault(RoomCard.CARD_A, 0) == 3){ + + bRet = true; + } + + + return bRet; + } + + + public static void main(String[] args) { + + ITObject test = new TObject(); + ITArray card_list = new TArray(); + card_list.addInt(215); + card_list.addInt(114); + card_list.addInt(303); + card_list.addInt(204); + card_list.addInt(205); + //card_list.addInt(307); + //card_list.addInt(207); + test.putInt("sidaiyi",0); + test.putInt("threeA",1); + test.putInt("threelack",1); + test.putInt("fourBeltThree",1); + List tlist = CardUtil.toList(card_list); + // System.out.println(tlist); + CardGroup ct = CardCheck.getType(tlist, test ); + //Boolean a = CardCheck.tryType(ct,4,test); + // System.out.println(ct); + //System.out.println(a); + + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardConfig.java b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardConfig.java new file mode 100644 index 0000000..d2ccd9f --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardConfig.java @@ -0,0 +1,39 @@ +package extend.pk.uitl; + +import extend.pk.Config; + +public enum CardConfig { + DAN( "单牌", Config.TYPE_DANPAI, 1, 1, 1, 1, 0), + DUIZI( "对子", Config.TYPE_DUIZI, 1, 2, 2, 2, 0), + SHUNZI( "顺子", Config.TYPE_SHUNZI, 5, 1, 5, 12, 0), + LIANDUI( "连对", Config.TYPE_LIANDUI, 2, 2, 4, 16, 0), + SAN_2( "三带二", Config.TYPE_3_2, 1, 3, 3, 5, 2), + FEIJI( "飞机", Config.TYPE_FEIJI, 2, 3, 6, 16, 2), + SI_3( "四带三", Config.TYPE_4_3, 1, 4, 5, 7, 3), + SI_2( "四带二", Config.TYPE_4_2, 1, 4, 5, 6, 2), + ZHA( "炸弹", Config.TYPE_ZHA, 1, 4, 4, 4, 0); + + public final int type; + public final String name; + public final int min_len; + public final int repeat_num; + public final int min_card_num; + public final int max_card_num; + public final int with_card_num; + + + private CardConfig(String name,int type,int min_len,int repeat_num,int min_card_num,int max_card_num,int with_card_num) { + this.name = name; + this.type = type; + + this.min_len = min_len; + this.repeat_num = repeat_num; + this.min_card_num = min_card_num; + this.max_card_num = max_card_num; + this.with_card_num = with_card_num; + } + + public String toString() { + return this.name; + } +} diff --git a/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardUtil.java b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardUtil.java new file mode 100644 index 0000000..632e961 --- /dev/null +++ b/game_pk_paodekuai/src/main/java/extend/pk/uitl/CardUtil.java @@ -0,0 +1,377 @@ +package extend.pk.uitl; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.pk.CardObj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CardUtil { + + + /** + * list to TArray + * + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (CardObj card : list) { + result.addInt(card.card); + } + return result; + } + + public static final CardObj getCard(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.cardMod == eventCard) { + return card; + } + } + return null; + } + + public static final CardObj getCard1(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.card == eventCard) { + return card; + } + } + return null; + } + + /** + * 检测牌数量 + * + * @param eventCard + * @param cardList + * @param num + * @return + */ + public static final boolean checkCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result == num) + return true; + } + } + return false; + } + + public static final boolean checkGoodCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result >= num) + return true; + } + } + return false; + } + + public static final boolean checkShunZi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + } + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkSevenShunzi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + + if (result >= 6) + { + return true; + } + return false; + } + + public static final boolean checkFenJi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+1, cardList, 3)) + { + result++; + } + if (checkGoodCard(eventCard-1, cardList, 3)) + { + result++; + } + } + + if (result >= 2) + { + return true; + } + return false; + } + + public static final boolean checkFourDui(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 1)) + { + result++; + } + + if (checkGoodCard(eventCard+1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 2)) + { + result++; + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 2)) + { + result++; + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkQPai(int eventCard, List cardList) { + int result = 0; + if (eventCard >= 12) + { + result++; + for (CardObj card : cardList) { + if (card.cardMod >= 12) { + result++; + } + } + } + + if (result >= 5) + { + return true; + } + return false; + } + + /** + * TArray to list + * @param list + * @return + */ + public static final List toList(ITArray list) { + List tem = new ArrayList(); + for(int i=0;i getCardNumMap(List cardList) { + Map result = new HashMap(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + return result; + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final void getCardNumMap(Map result,List cardList) { + result.clear(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + public static final void getCardNumMap(Map result,List cardList, CardObj tempCard) { + result.clear(); + result.put(tempCard.cardMod, 1); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final Map> getCardListMap(List cardList) { + Map> result = new HashMap>(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + List list = new ArrayList(); + list.add(card); + result.put(card.cardMod, list); + } else { + List list = result.get(card.cardMod); + list.add(card); + } + } + return result; + } + + static public void removeCard(List cardList, List cards) { + for (int i = 0; i < cards.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).card ==cards.get(i).card) { + cardList.remove(j); + break; + } + } + } + } +} diff --git a/game_pk_paodekuai/src/test/java/game_pk_paodekuai/Pdkmain.java b/game_pk_paodekuai/src/test/java/game_pk_paodekuai/Pdkmain.java new file mode 100644 index 0000000..c849895 --- /dev/null +++ b/game_pk_paodekuai/src/test/java/game_pk_paodekuai/Pdkmain.java @@ -0,0 +1,9 @@ +package game_pk_paodekuai; + +import com.taurus.permanent.TPServer; + +public class Pdkmain { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_pk_sanqianfen/config/game-config.xml b/game_pk_sanqianfen/config/game-config.xml new file mode 100644 index 0000000..ac6918c --- /dev/null +++ b/game_pk_sanqianfen/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.8.135 + 192.168.8.135 + 8721 + 8721 + 203 + true + \ No newline at end of file diff --git a/game_pk_sanqianfen/config/log4j.properties b/game_pk_sanqianfen/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/game_pk_sanqianfen/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_pk_sanqianfen/config/taurus-core.xml b/game_pk_sanqianfen/config/taurus-core.xml new file mode 100644 index 0000000..0f9fa8f --- /dev/null +++ b/game_pk_sanqianfen/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_pk_sanqianfen/config/taurus-permanent.xml b/game_pk_sanqianfen/config/taurus-permanent.xml new file mode 100644 index 0000000..cafcfef --- /dev/null +++ b/game_pk_sanqianfen/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - test + extend.extend.pk.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_pk_sanqianfen/pom.xml b/game_pk_sanqianfen/pom.xml new file mode 100644 index 0000000..2090378 --- /dev/null +++ b/game_pk_sanqianfen/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + com.game + game_pk_sanqianfen + 1.0.0 + jar + + game_pk_sanqianfen + http://maven.apache.org + + + UTF-8 + + + + + + com.game + game_common + 1.0.0 + + + + + game_pk_sanqianfen + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/CardGroup.java b/game_pk_sanqianfen/src/main/java/extend/pk/CardGroup.java new file mode 100644 index 0000000..fc7ee92 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/CardGroup.java @@ -0,0 +1,45 @@ +package extend.pk; + +import java.util.List; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import extend.pk.uitl.CardConfig; + +public class CardGroup { + /** + * 当前type + */ + public CardConfig config; + + public int min_card; + /** + * 长度 + */ + public int len = 1; + + public List card_list; + + public ITArray card_list_mp; + + public ITObject toObject(boolean card_size) { + ITObject obj = TObject.newInstance(); + if (card_size) { + obj.putInt("card_size", card_list.size()); + } else { + obj.putTArray("card_list", card_list_mp); + } + + obj.putInt("type", config.type); + obj.putInt("min_card", min_card); + obj.putInt("len", len); + return obj; + } + + public String toString() { + return "{type:" + config + " min_card:" + min_card + " len:" + len + " list:" + card_list + "}"; + } + +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/CardObj.java b/game_pk_sanqianfen/src/main/java/extend/pk/CardObj.java new file mode 100644 index 0000000..bc2d762 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/CardObj.java @@ -0,0 +1,21 @@ +package extend.pk; + +public class CardObj implements Comparable{ + public int card; + public int cardMod; + + public CardObj(int card) { + this.card = card; + this.cardMod = card % 100; + } + + @Override + public int compareTo(CardObj paramT) { + return cardMod == paramT.cardMod ? 0 : cardMod < paramT.cardMod ? -1 : 1; + } + + @Override + public String toString() { + return card + ""; + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/Config.java b/game_pk_sanqianfen/src/main/java/extend/pk/Config.java new file mode 100644 index 0000000..18be886 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/Config.java @@ -0,0 +1,223 @@ +package extend.pk; + +public class Config { + + public static final int XIPAI_SCORE = 10; + + /** + * 玩家的初始手牌数 + */ + public static final String ROOM_CONFIG_CARDNUM = "leaf"; + + /** + * 炸弹带的规则 + */ + public static final String ROOM_CONFIG_SIDAI = "fourBeltThree"; + + public static final String ROOM_CONFIG_SIDAI_2 = "fourDaiTwo"; + public static final String ROOM_CONFIG_SIDAI_3 = "fourDaiThree"; + + /** + * 首局出牌规则 + */ + public static final String ROOM_CONFIG_RULE = "rule"; + + /** + * 第一局系统随机选一张先出,随后赢家先出 + */ + public static final int RULE_RANDOM = 2; + /** + * 第一局黑桃3先出,随后赢家先出 + */ + public static final int RULE_HEITAO3 = 1; + + /** + * 炸弹不能拆 + */ + public static final String ROOM_CONFIG_DEMOLITION = "demolition"; + /** + * 可不必出 + */ + public static final String ROOM_CONFIG_WILL_BE_OUT = "willBeOut"; + + /** + * 3条a是否是炸弹 + */ + public static final String ROOM_CONFIG_THREE_A = "threeA"; + + /** + * 红桃10分翻倍 + */ + public static final String ROOM_CONFIG_HEARTTEN = "heartten"; + + /** + * 飞机少带可接完 + */ + public static final String ROOM_CONFIG_PLANE_LACK = "planelack"; + + /** + * 三张少带可接完 + */ + public static final String ROOM_CONFIG_THREE_LACK = "threelack"; + + /** + * 4个3333 或者 2 AAA 算春天 + */ + public static final String ROOM_CONFIG_MINBOOM = "minboom"; + + /** + * 自动托管功能 + */ + public static final String ROOM_CONFIG_AUTO_TUOGUAN = "autotuoguan"; + + /** + * 飘分玩法 + */ + public static final String ROOM_CONFIG_PIAO = "piao"; + + /** + * 打鸟 + */ + public static final String ROOM_CONFIG_DANIAO = "daniao"; + + /** + * 三带 飞机带 + */ + public static final String ROOM_CONFIG_SANDAIDAN = "sandaidan"; + + 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_510K_SCORE = "score_510k"; + public static final String ROOM_CONFIG_510K_SCORE_TYPE = "score_510k_type"; //0,1,2 + + //-------------------------------牌类型--------------------------------- + /** + * 单牌 + */ + public final static int TYPE_DANPAI = 1; + /** + * 对子 + */ + public final static int TYPE_DUIZI = 2; + /** + * 顺子 + */ + public final static int TYPE_SHUNZI = 3; + /** + * 连对 + */ + public final static int TYPE_LIANDUI = 4; + /** + * 3带2 + */ + public final static int TYPE_3_2 = 5; + /** + * 飞机 + */ + public final static int TYPE_FEIJI = 6; + /** + * 4带3 + */ + public final static int TYPE_4_3 = 7; + + /** + * 炸 + */ + public final static int TYPE_ZHA = 8; + + /** + * 4带2 + */ + public final static int TYPE_4_2 = 9; + + + //-------------------------------协议--------------------------------- + + public static final String GAME_EVT_MING_PAI = "2117"; + /** + * 发牌协议 + */ + public static final String GAME_EVT_PLAYER_DEAL = "2011"; + /** + * 出牌 + */ + public static final String GAME_DIS_CARD = "1013"; + /** + * 不出 + */ + public static final String GAME_DIS_PASS = "1014"; + /** + * + */ + public static final String GAME_PIAO = "1015"; + /** + * 出牌事件 + */ + public static final String GAME_EVT_DISCARD = "2021"; + + public static final String GAME_EVT_CARDINHAND = "202022"; + /** + * 出牌提示事件 + */ + public static final String GAME_EVT_DISCARD_TIP = "2004"; + /** + * 转盘指向事件 + */ + public static final String GAME_EVT_CHANGE_ACTIVE_PLAYER = "2016"; + /** + * pass事件 + */ + public static final String GAME_EVT_PASS = "2030"; + /** + * 更新炸弹分数 + */ + public static final String GAME_EVT_UPDATE_BOM_SCORE = "2118"; + + /** + * 更新510K分数 + */ + public static final String GAME_EVT_UPDATE_510K_SCORE = "22119"; + + /** + * 更新喜分 + */ + public static final String GAME_EVT_UPDATE_XI_SCORE = "22120"; + + /** + * 更新510K分数 + */ + public static final String GAME_EVT_ALL_UPDATE_510K_SCORE = "22121"; + + /** + * 通知上游 + */ + public static final String GAME_EVT_SHANGYOU = "22122"; + + /** + * 小结算 + */ + public static final String GAME_EVT_RESULT1 = "2007"; + + /** + * 飘鸟提示 + */ + public static final String GAME_EVT_PIAO_TIP = "2031"; + public static final String GAME_EVT_PIAO = "2032"; + + /** + * 出牌错误 + */ + public static final String GAME_EVT_PUT_ERROR = "2111"; + + public static final int PUT_ERROR_MUST_OUT_MIN = 0; + public static final int PUT_ERROR_INVALID_TYPE = 1; + public static final int PUT_ERROR_MUST_OUT_MAX = 2; + public static final int PUT_ERROR_BOMB_CHAI =3; + + public static final String SETTLE_WIN_COUNT = "winnum"; + public static final String SETTLE_CHUNTIAN_COUNT = "springnum"; + public static final String SETTLE_BOMB_COUNT = "boomnum"; + public static final String SETTLE_MAX_SCORE = "maxscore"; +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXActionEvent.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXActionEvent.java new file mode 100644 index 0000000..b94a22c --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXActionEvent.java @@ -0,0 +1,10 @@ +package extend.pk; + +import com.game.ActionEvent; + +public class EXActionEvent extends ActionEvent{ + + public static final String EVENT_DISCARD = "1013"; + public static final String EVENT_PASS = "1014"; + public static final String EVENT_PIAO= "1015"; +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXGameController.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXGameController.java new file mode 100644 index 0000000..cf4c383 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXGameController.java @@ -0,0 +1,650 @@ +package extend.pk; + +import com.game.Constant; +import com.game.GameController; +import com.game.Global; +import com.game.data.Player; +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.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +import java.util.*; +import java.util.Map.Entry; + +/** + * + * + */ +public class EXGameController extends GameController { + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_DIS_CARD) + public void RouterDisCard(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, params); + } + + @ActionKey(Config.GAME_DIS_PASS) + public void RouterDisPass(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PASS, 0, params); + } + + @ActionKey(Config.GAME_PIAO) + public void RouterPiao(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PIAO, 0, params); + } + + // 改变活动玩家 + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("index", activeSeat); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + public void sendPutError(EXPlayer owner,int code) { + ITObject param = new TObject(); + param.putInt("error", code); + owner.sendEvent(Config.GAME_EVT_PUT_ERROR, param); + } + + /** + * pass + * @param owner + */ + public void pass(EXPlayer owner) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + if (Global.loggerDebug) { + Global.logger.info(owner + " pass!"); + } + owner.pass = true; + owner.last_outcard = null; + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addPassCommand(owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_PASS, response); + } + + /** + * 票鸟提示 + * @param owner + */ + public void piaoTipEvent(EXPlayer owner,int reload) { + + ITObject response = new TObject(); + response.putInt("piao", owner.room.config.getInt(Config.ROOM_CONFIG_PIAO)); + response.putInt("reload", reload); + owner.sendEvent(Config.GAME_EVT_PIAO_TIP, response); + } + + /** + * 票鸟事件 + * @param owner + */ + public void piaoEvent(EXPlayer owner) { + if(owner.piao==-1)return; + + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("piao", owner.piao); + owner.room.broadCastToClient(0, Config.GAME_EVT_PIAO, param); + } + + public void outCard(EXPlayer owner,CardGroup ct) { + EXRoom room = owner.getRoom(); + ITObject response = new TObject(); + response.putInt("player", owner.seat); + response.putTObject("card_obj", ct.toObject(false)); + //如果最后一次打牌的座位等于自己 并且牌型是炸弹 + if(ct.config == CardConfig.ZHA) { + room.addAllBombScore(owner, ct);//炸弹玩家增加积分 + } + //用8替代5 + int add510kFen = 0; + Map> cardMap =CardUtil.getCardListMap(ct.card_list); + if (cardMap.containsKey(RoomCard.CUR_5_CARD)) + { + add510kFen += cardMap.get(RoomCard.CUR_5_CARD).size() * 5; + room.cur5Num += cardMap.get(RoomCard.CUR_5_CARD).size(); + } + if (cardMap.containsKey(10)) + { + add510kFen += cardMap.get(10).size() * 10; + room.cur10Num += cardMap.get(10).size(); + } + if (cardMap.containsKey(13)) + { + add510kFen += cardMap.get(13).size() * 10; + room.curkNum += cardMap.get(13).size(); + } + + room.cur510kFen += add510kFen; + + owner.outCards.addAll(ct.card_list); + response.putInt("add510k", add510kFen); + response.putInt("all510k", room.cur510kFen); + response.putInt("cur5Num", room.cur5Num); + response.putInt("cur10Num", room.cur10Num); + response.putInt("curkNum", room.curkNum); + + room.lastDiscardSeat = owner.seat; + room.discard = ct; + owner.last_outcard = ct; + owner.pass = false; + room.firstCard = 0; + if (Global.loggerDebug) { + Global.logger.info(owner + " out card:" + ct); + } + EXPlayBack pb = (EXPlayBack)room.playBackData; + pb.addOutCardCommand(owner.seat, ct, owner, add510kFen, room); + CardUtil.removeCard(owner.cardInhand, ct.card_list); + + response.putInt("remain", owner.cardInhand.size()); + room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + } + + public void dealCard(EXRoom owner) { + if (owner.targetCards.size() == 0) { + owner.card.init(); + } + + int maxZhaDan = 0; + int maxZhaDanCardNum = 0; + boolean existWhite = false; + boolean existXingyunhao = false; + boolean existGeneral = false; + boolean existBlack = false; + double white_rate = 0; + + ArrayList tmpPlayerList = new ArrayList<>(); + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmpPlayerList.add(player); + } + + Collections.shuffle(tmpPlayerList); + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) { + existXingyunhao = true; + } else { + if (player.black_white_status == 0) { + existGeneral = true; + } + else if (player.black_white_status == 1) { + existBlack = true; + } + else if (player.black_white_status == 2) { + existWhite = true; + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + white_rate = 100 - owner.white_value; + Global.logger.info("dealcards playerid:"+player.playerid+ " xingyuhao:"+player.is_white+" white_value:"+owner.white_value); + } + else { + continue; + } + + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0); + + if(owner.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1 && owner.config.getInt(Config.ROOM_CONFIG_HEARTTEN) == 1) { + if(CardUtil.getCard1(RoomCard.HEART_TEN,player.cardInhand) != null) { + player.isHaveRedTen = true; + } + } + + Collections.sort(player.cardInhand); + + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + + if (num == maxZhaDanCardNum) + { + if (card > maxZhaDan) + { + maxZhaDan = card; + } + } + else if (num > maxZhaDanCardNum) + { + maxZhaDan = card; + maxZhaDanCardNum = num; + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 2) + { + white_rate = player.black_white_rate; + Global.logger.info("dealcards playerid:"+player.playerid+ " white player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate, player.black_white_rate, maxZhaDan, maxZhaDanCardNum); + + } + + if(owner.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1 && owner.config.getInt(Config.ROOM_CONFIG_HEARTTEN) == 1) { + if(CardUtil.getCard1(RoomCard.HEART_TEN,player.cardInhand) != null) { + player.isHaveRedTen = true; + } + } + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && (existGeneral || existBlack)) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (num == maxZhaDanCardNum) + { + if (card > maxZhaDan) + { + maxZhaDan = card; + } + } + else if (num > maxZhaDanCardNum) + { + maxZhaDan = card; + maxZhaDanCardNum = num; + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 0) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " general player:" + player.black_white_rate); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, 0, 0); + + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, white_rate, white_rate, maxZhaDan, maxZhaDanCardNum); + + } + + if(owner.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1 && owner.config.getInt(Config.ROOM_CONFIG_HEARTTEN) == 1) { + if(CardUtil.getCard1(RoomCard.HEART_TEN,player.cardInhand) != null) { + player.isHaveRedTen = true; + } + } + + Collections.sort(player.cardInhand); + + if (!existXingyunhao && !existWhite && existBlack) + { + Map playermap = CardUtil.getCardNumMap(player.cardInhand); + for(Entry card_entry : playermap.entrySet()) + { + int card = card_entry.getKey(); + int num = card_entry.getValue(); + if (num == maxZhaDanCardNum) + { + if (card > maxZhaDan) + { + maxZhaDan = card; + } + } + else if (num > maxZhaDanCardNum) + { + maxZhaDan = card; + maxZhaDanCardNum = num; + } + } + } + } + + for (int i = 0;i < tmpPlayerList.size();i++) { + EXPlayer player = tmpPlayerList.get(i); + + if (player.is_white) + { + continue; + } + else + { + if (player.black_white_status == 1) + { + Global.logger.info("dealcards playerid:"+player.playerid+ " black player:" + (player.black_white_rate+white_rate)); + } + else { + continue; + } + } + + if (!existXingyunhao && !existWhite && !existGeneral) + { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, 0, 0); + } + else { + player.cardInhand = owner.card.deal(owner.while_list, player.is_white, owner.white_value, + player.black_white_status, player.black_white_rate+white_rate, player.black_white_rate+white_rate, maxZhaDan, maxZhaDanCardNum); + } + + if(owner.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1 && owner.config.getInt(Config.ROOM_CONFIG_HEARTTEN) == 1) { + if(CardUtil.getCard1(RoomCard.HEART_TEN,player.cardInhand) != null) { + player.isHaveRedTen = true; + } + } + + Collections.sort(player.cardInhand); + } + + //for (int i = 0;i < tmpPlayerList.size();i++) { + // EXPlayer player = tmpPlayerList.get(i); + + // player.cardInhand = owner.card.deal6(player.seat); + + // Collections.sort(player.cardInhand); + //} + + Global.logger.info("sssss==>" + owner.supCards.size()); + if (owner.targetCards.size() > 0 && owner.adminSeat > 0 && owner.supCards.size() > 0) { + owner.card.cardList = owner.supCards.get(0); + } + + // 如果是首局,需要确定庄家 + if(owner.bankerSeat == 0) { + + int rule = Config.RULE_RANDOM; + if(owner.config.containsKey(Config.ROOM_CONFIG_RULE)) { + rule = owner.config.getInt(Config.ROOM_CONFIG_RULE); + } + + owner.bankerSeat = this.getBankerSeat(owner); + + this.sendPlayerDeal(owner); + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + if(player != null) { + + int len = player.cardInhand.size(); + if(len > 0) { + Random random = new Random(); + int rand_pos = random.nextInt(len); + + //this.sendMingPai(owner, player.cardInhand.get(rand_pos).card); + } + } + } + } + else + { + this.sendPlayerDeal(owner); + } + + for(int i = 0; i < 6; i++) + { + owner.card.jiangliCardList.add(owner.card.pop()); + } + } + + /** + * 发生随机牌 用于指示谁首先出牌 + * @param owner + */ + private void sendMingPai(EXRoom owner,int card) { + + ITObject param = new TObject(); + param.putInt("mingpai", card); + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + exPlayer.sendEvent(Config.GAME_EVT_MING_PAI, param); + }; + } + /** + * 发牌 + * @param owner + */ + private void sendPlayerDeal(EXRoom owner){ + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer exPlayer=(EXPlayer)entry.getValue(); + ITObject param = new TObject(); + ITArray handCard = CardUtil.toTArray(exPlayer.cardInhand); + param.putTArray("cards", handCard); + param.putInt("bank_seat", exPlayer.room.bankerSeat); + param.putInt("round", owner.round); + param.putInt("cur510kFen", exPlayer.cur510kFen); + if (Global.loggerDebug) { + Global.logger.info(owner + " deal card:"+exPlayer.cardInhand); + } + exPlayer.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + }; + } + + private int getBankerSeatByCard(EXRoom owner) { + for (int index = 3; index <= 13; index++) { + for(int color = 4; color >= 1; color--) { + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (CardObj card : player.cardInhand) { + if (card.card == color *100 + index) { + owner.firstCard = card.card; + return player.seat; + } + } + } + } + } + return 0; + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + + int rule = Config.RULE_RANDOM; + if(owner.config.containsKey(Config.ROOM_CONFIG_RULE)) { + rule = owner.config.getInt(Config.ROOM_CONFIG_RULE); + } + //如果是兩人的情況 + if (owner.maxPlayers == 2) { + + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + // 如果是黑桃3先出 + else + { + seat = getBankerSeatByCard(owner); + + // 如果黑桃3 不在任何一个玩家手里 则随机确定一个庄家 + if(seat == 0) { + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + } + } else { + // 如果是随机确定庄家 + if(rule == Config.RULE_RANDOM) { + Random random = new Random(); + seat = random.nextInt(3) + 1; + } + // 如果是黑桃3先出 + else + { + seat = getBankerSeatByCard(owner); + + } + } + return seat; + } + + public void discardTipEvent(EXPlayer owner) { + ITObject param = new TObject(); + boolean gen = (owner.getRoom().lastDiscardSeat != 0 &&owner.getRoom().lastDiscardSeat != owner.seat); + param.putInt("play", gen ? 1 : 0); + if(gen) { + param.putTObject("card_obj", owner.getRoom().discard.toObject(true)); + + } + // 如果可以不出 + + + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + } + + private ITObject getRoomResultData(EXRoom owner,boolean total) { + + ITObject mp = TObject.newInstance(); + + EXPlayer win = owner.win; + if (total) + { + int max = RoomCard.MAX_510K_SCORE; + for (Entry entry : owner.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer.cur510kFen+fromPlayer.curXiFen >= max) + { + max = fromPlayer.cur510kFen+fromPlayer.curXiFen; + win = fromPlayer; + } + } + } + + ITArray info = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.total_score); + obj.putInt("winscore", player.score.round_score); + player.hp_info(obj); + obj.putInt("thisboomnum", player.boomnum); + obj.putInt("piao", player.piao); + obj.putTArray("cards", CardUtil.toTArray(player.cardInhand)); + obj.putBoolean("chuntian", player.chuntian); + + obj.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + obj.putTArray("outCards", CardUtil.toTArray(player.outCards)); + + obj.putInt("cur510kFen", player.cur510kFen); + obj.putInt("ju510kFen", player.ju510kFen); + obj.putInt("juXiFen", player.juXiFen); + obj.putInt("curXiFen", player.curXiFen); + obj.putInt("jiangli", player.jiangli); + obj.putInt("boomnum", player.boomnum); + obj.putInt("leftCardFen", player.leftCardFen); + + obj.putInt("allJu510kFen", player.allJu510kFen); + obj.putInt("allJiangLi", player.allJiangLi); + obj.putInt("allLeftCardFen", player.allLeftCardFen); + + obj.putInt("jieSuanJiangLi", player.jieSuanJiangLi); + + if(total) { + obj.putInt("daniao", player.daniaoScore); + obj.putInt("award", player.bonusScore); + + if(owner.endType == Constant.END_TYPE_ENTRUST) { + obj.putInt("entrust", player.entrust ? 1 : 0); + } + obj.putTObject("settle_log", player.settleLog.toTObject()); + obj.putInt("total_score", player.score.total_score); + + } + info.addTObject(obj); + } + if(win != null) { + mp.putInt("winseat",win.seat); + } + else { + mp.putInt("winseat",0); + } + mp.putTArray("remaincards", CardUtil.toTArray(owner.card.jiangliCardList)); + mp.putTArray("info", info); + mp.putInt("xipai_score", owner.xi_pai_score); + return mp; + } + + public void roomResult(EXRoom owner) { + + ITObject result = getRoomResultData(owner,false); + result.putInt("type", 0); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + + /** + * 房间大结算 + * @param owner + * @param dissmiss + */ + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + + ITObject result = getRoomResultData(owner,true); + + long t = System.currentTimeMillis() / 1000; + result.putLong("time", t); + result.putInt("type", dissmiss?2:1); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, result); + } + +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXMainServer.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXMainServer.java new file mode 100644 index 0000000..44e5e63 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXMainServer.java @@ -0,0 +1,66 @@ +package extend.pk; + +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.room.state.RoomStartGameState; + +import extend.pk.player.state.EXPlayerDiscardState; +import extend.pk.player.state.EXPlayerPassState; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; +import extend.pk.room.state.EXRoomDealState; +import extend.pk.room.state.EXRoomPiaoState; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.room.state.EXRoomStartGameState; + +/** + * + * + */ +public class EXMainServer extends MainServer { + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + gameCtr = (EXGameController) Global.gameCtr; + registerState(); + } + + private final void registerState() { + + Global.registerState(RoomStartGameState.class, new EXRoomStartGameState()); + Global.registerState(EXRoomSetpState.class, new EXRoomSetpState()); + Global.registerState(EXRoomDealState.class, new EXRoomDealState()); + Global.registerState(EXRoomPiaoState.class, new EXRoomPiaoState()); + + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerPassState.class, new EXPlayerPassState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + } + + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayBack.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayBack.java new file mode 100644 index 0000000..9f4d1e5 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayBack.java @@ -0,0 +1,67 @@ +package extend.pk; + + +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; + +import extend.pk.uitl.CardUtil; + +public class EXPlayBack extends BasePlayBack{ + + public EXPlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + } + + protected ITObject getPlayerInfo(Player p) { + + EXPlayer player = (EXPlayer)p; + ITObject obj =super.getPlayerInfo(player); + ITArray cardInhand = CardUtil.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + obj.putInt("piao", player.piao); + obj.putInt("cur510kFen", player.cur510kFen); + obj.putInt("ju510kFen", player.ju510kFen); + obj.putInt("curXiFen", player.curXiFen); + obj.putInt("juXiFen", player.juXiFen); + + player.hp_info(obj); + return obj; + } + + public void addOutCardCommand(int seat, CardGroup ct, EXPlayer owner, int all510k, EXRoom room) { + ITObject cmdData = ct.toObject(false); + cmdData.putInt("all510k", all510k); + cmdData.putInt("cur5Num", room.cur5Num); + cmdData.putInt("cur10Num", room.cur10Num); + cmdData.putInt("curkNum", room.curkNum); + addCommand("OutCard", seat, cmdData); + } + + public void add510KFenCommand(int seat, EXPlayer owner) { + ITObject obj = TObject.newInstance(); + obj.putInt("cur510kFen", owner.cur510kFen); + obj.putInt("ju510kFen", owner.ju510kFen); + obj.putInt("curXiFen", owner.curXiFen); + obj.putInt("juXiFen", owner.juXiFen); + addCommand("510kFen", seat, obj); + } + + public void addPassCommand(int seat) { + ITObject cmdData = TObject.newInstance(); + addCommand("pass", seat, cmdData); + } + + public void addNewRoundCommand() { + ITObject cmdData = TObject.newInstance(); + addCommand("newindex", 0, cmdData); + } + + public void addResultCommand(int seat,ITObject cmdData) { + addCommand("result", seat, cmdData); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayer.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayer.java new file mode 100644 index 0000000..1ca90cc --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXPlayer.java @@ -0,0 +1,152 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.List; + +import com.game.data.Player; +import com.game.data.Room; +import com.game.data.Score; +import com.taurus.core.entity.ITObject; + +import extend.pk.uitl.CardUtil; + + + +/** + * + * + */ +public class EXPlayer extends Player { + + /**默认action时间 20s*/ + public static final int DEFAULT_ACTION_TIME = 20000; + /**默认托管时间 1s*/ + public static final int DEFAULT_ENTRUST_TIME = 1000; + /** + * 默认准备时间 20s + */ + public static final int DEFAULT_READY_TIME = 20000; + + // 手牌 + public List cardInhand; + + //打出的牌 + public List outCards; + + public CardGroup last_outcard; + public boolean pass; + + // 放作弊场第一张牌是否关闭 + public int open = 0; + + /**春天 */ + public boolean chuntian; + + /**是否有红桃10*/ + public boolean isHaveRedTen; + + public SettleLog settleLog; + + public int boomnum = 0; + public int piao = -1; + public int daniaoScore = 0; + public int bonusScore = 0; + public int awardScore = 0; + public int cur510kFen = 0; + public int ju510kFen = 0; + public int allJu510kFen = 0; + public int curXiFen = 0; + public int juXiFen = 0; + public int jiangli = 0; + public int allJiangLi = 0; + public int leftCardFen = 0; + public int allLeftCardFen = 0; + public int jieSuanJiangLi = 0; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + cardInhand = new ArrayList<>(); + outCards = new ArrayList<>(); + + settleLog = new SettleLog(); + settleLog.put(Config.SETTLE_WIN_COUNT, 0); + settleLog.put(Config.SETTLE_CHUNTIAN_COUNT, 0); + settleLog.put(Config.SETTLE_BOMB_COUNT, 0); + settleLog.put(Config.SETTLE_MAX_SCORE, 0); + } + + protected Score newScore() { + return new EXScore(this); + } + + @Override + public ITObject getReloadInfo() { + ITObject playerData = super.getReloadInfo(); + playerData.putInt("card_size", this.cardInhand.size()); + playerData.putInt("piao", this.piao); + playerData.putInt("cur510kFen", this.cur510kFen); + playerData.putInt("ju510kFen", this.ju510kFen); + playerData.putInt("curXiFen", this.curXiFen); + playerData.putInt("juXiFen", this.juXiFen); + playerData.putInt("jiangli", this.jiangli); + playerData.putInt("leftCardFen", this.leftCardFen); + + playerData.putInt("allJu510kFen", this.allJu510kFen); + playerData.putInt("allJiangLi", this.allJiangLi); + playerData.putInt("allLeftCardFen", this.allLeftCardFen); + if(last_outcard!=null) { + playerData.putTObject("last_outcard", last_outcard.toObject(false)); + } + + if(this.room.isplaying == false) { + playerData.putTArray("cards", CardUtil.toTArray(this.cardInhand)); + + playerData.putTArray("handCards", CardUtil.toTArray(this.cardInhand)); + playerData.putTArray("outCards", CardUtil.toTArray(this.outCards)); + + playerData.putInt("score", score.total_score); + playerData.putInt("winscore", score.round_score); + playerData.putInt("thisboomnum", boomnum); + playerData.putInt("open", open); + } + return playerData; + } + + @Override + public ITObject getInfo() { + ITObject playerData = super.getInfo(); + playerData.putInt("score", score.total_score); + playerData.putInt("cur510kFen", this.cur510kFen); + return playerData; + } + + + public void clear() { + super.clear(); + + } + + public void clearEx() { + + this.score.resetRound(); + this.cardInhand.clear(); + this.outCards.clear(); + this.last_outcard = null; + this.pass = false; + this.chuntian =false; + this.isHaveRedTen=false; + this.open = 0; + //this.boomnum = 0; + this.piao = -1; + this.daniaoScore = 0; + this.ju510kFen = 0; + this.juXiFen = 0; + this.jiangli = 0; + this.leftCardFen = 0; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXRoom.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXRoom.java new file mode 100644 index 0000000..3aadcba --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXRoom.java @@ -0,0 +1,603 @@ +package extend.pk; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + + +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.TArray; +import com.taurus.core.entity.TObject; + +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +public class EXRoom extends Room { + public RoomCard card; + + /**上次打牌的座位*/ + public int lastDiscardSeat; + + /**打出牌的集合 */ + public CardGroup discard; + + public EXPlayer win; + + public int firstCard = 0; + + public Map card_config_map; + + public int piaoCount = 0; + + public List> supCards; + public List targetCards; + public List winPlayerList; + public int adminSeat = 0; + + public int chooseover = 0; + + public int cur510kFen = 0; + public int cur5Num = 0; + public int cur10Num = 0; + public int curkNum = 0; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + + card = new RoomCard(this, 30,maxPlayers); + card_config_map = new HashMap(); + card_config_map.put(CardConfig.DAN.type, CardConfig.DAN); + card_config_map.put(CardConfig.DUIZI.type, CardConfig.DUIZI); + card_config_map.put(CardConfig.LIANDUI.type, CardConfig.LIANDUI); + card_config_map.put(CardConfig.SHUNZI.type, CardConfig.SHUNZI); + card_config_map.put(CardConfig.ZHA.type, CardConfig.ZHA); + card_config_map.put(CardConfig.FEIJI.type, CardConfig.FEIJI); + card_config_map.put(CardConfig.SAN_2.type, CardConfig.SAN_2); + + this.config.putInt(Config.ROOM_CONFIG_THREE_A,0); + this.config.putBoolean(Config.ROOM_CONFIG_SIDAI_2, false); + this.config.putBoolean(Config.ROOM_CONFIG_SIDAI_3, false); + this.config.putInt(Config.ROOM_CONFIG_DEMOLITION, 1); + this.config.putInt(Config.ROOM_CONFIG_THREE_LACK, 0); + this.config.putInt(Config.ROOM_CONFIG_PLANE_LACK, 0); + this.config.putInt(Config.ROOM_CONFIG_MINBOOM, 0); + this.config.putInt(Config.ROOM_CONFIG_SANDAIDAN, 0); + this.config.putInt(Config.ROOM_CONFIG_HEARTTEN, 0); + this.config.putInt(Config.ROOM_CONFIG_WILL_BE_OUT, 1); + this.config.putInt(Config.ROOM_CONFIG_SIDAI, 0); + + + boolean sidai_2 = this.config.getBoolean(Config.ROOM_CONFIG_SIDAI_2); + boolean sidai_3 = this.config.getBoolean(Config.ROOM_CONFIG_SIDAI_3); + if(sidai_2) { + card_config_map.put(CardConfig.SI_2.type, CardConfig.SI_2); + } + if(sidai_3) { + card_config_map.put(CardConfig.SI_3.type, CardConfig.SI_3); + } + + 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_510K_SCORE)) + { + this.config.putInt(Config.ROOM_CONFIG_510K_SCORE, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_510K_SCORE_TYPE)) + { + this.config.putInt(Config.ROOM_CONFIG_510K_SCORE_TYPE, 0); + } + + this.isEntrust = true; + + this.supCards = new ArrayList<>(); + this.targetCards = new ArrayList<>(); + this.winPlayerList = new ArrayList<>(); + this.adminSeat = 0; + this.chooseover = 0; + this.cur510kFen = 0; + } + + public void clear() { + super.clear(); + + } + + public void clearEx() { + this.activeSeat = 0; + this.discard = null; + this.lastDiscardSeat = 0; + this.win = null; + this.firstCard = 0; + this.cur510kFen = 0; + this.cur5Num = 0; + this.cur10Num = 0; + this.curkNum = 0; + this.winPlayerList.clear(); + } + + public ITObject getReloadInfo(Player player) { + ITObject data = super.getReloadInfo(player); + EXPlayer p = (EXPlayer) player; + + data.putTArray("hand_card", CardUtil.toTArray(p.cardInhand)); + + data.putTArray("handCards", CardUtil.toTArray(p.cardInhand)); + data.putTArray("outCards", CardUtil.toTArray(p.outCards)); + data.putInt("cur510kFen", this.cur510kFen); + data.putInt("cur5Num", this.cur5Num); + data.putInt("cur10Num", this.cur10Num); + data.putInt("curkNum", this.curkNum); + + data.putInt("open", p.open); + + data.putInt("last_outcard_seat", this.lastDiscardSeat); + + // 游戏结束 + if(this.isplaying == false) { + + if(this.win != null) { + data.putInt("winseat", this.win.seat); + } + else + { + data.putInt("winseat", 0); + } + if(this.card.getCount() > 0) { + data.putTArray("remaincards", CardUtil.toTArray(this.card.jiangliCardList)); + } + } + + return data; + } + + /** + * 决定总结算方式 + * + * @return true : 总结算 + */ + protected boolean totalType() { + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.cur510kFen >= RoomCard.MAX_510K_SCORE) + { + return true; + } + } + return false; + //return this.round >= this.maxRound; + } + + public boolean entrustTotal() { + return false; + } + + /** + * + * */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } + + public void addScore(Player destPlayer, Player fromPlayer, int score, int type) { + + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int)fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + // + + 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; + } + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void addAllBombScore(EXPlayer destPlayer, CardGroup card) { + if (card.card_list.size() == 7) + { + addXiScore(destPlayer, 100); + } + else if (card.card_list.size() == 8) + { + addXiScore(destPlayer, 200); + } + else if (card.card_list.size() == 9) + { + addXiScore(destPlayer, 400); + } + else if (card.card_list.size() == 10) + { + addXiScore(destPlayer, 800); + } + else if (card.card_list.size() == 11) + { + addXiScore(destPlayer, 1600); + } + else if (card.card_list.size() == 12) + { + addXiScore(destPlayer, 3200); + } + } + + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void add510kScore(EXPlayer destPlayer) { + //destPlayer.cur510kFen += this.cur510kFen; + if (this.cur510kFen > 0) + { + destPlayer.ju510kFen += this.cur510kFen; + TArray seatData=TArray.newInstance(); + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("add510kfen", this.cur510kFen); + seatListData.putInt("ju510kfen", destPlayer.ju510kFen); + seatListData.putInt("all510kfen", destPlayer.cur510kFen); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + + this.cur510kFen = 0; + this.cur5Num = 0; + this.cur10Num = 0; + this.curkNum = 0; + allData.putInt("cur510kFen", 0); + allData.putInt("cur5Num", 0); + allData.putInt("cur10Num", 0); + allData.putInt("curkNum", 0); + + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_510K_SCORE, allData); + + EXPlayBack pb = (EXPlayBack)destPlayer.getRoom().playBackData; + pb.add510KFenCommand(destPlayer.seat, destPlayer); + } + } + + /** + * 变更炸弹积分 + * @param destPlayer + */ + public void addXiScore(EXPlayer destPlayer, int score) { + destPlayer.curXiFen += score; + destPlayer.juXiFen += score; + TArray seatData=TArray.newInstance(); + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("addXiFen", score); + seatListData.putInt("juXiFen", destPlayer.juXiFen); + seatListData.putInt("allXiFen", destPlayer.curXiFen); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + TObject allData=TObject.newInstance(); + allData.putTArray("gold_list", seatData); + + this.broadCastToClient(0, Config.GAME_EVT_UPDATE_XI_SCORE, allData); + + EXPlayBack pb = (EXPlayBack)destPlayer.getRoom().playBackData; + pb.add510KFenCommand(destPlayer.seat, destPlayer); + } + + /** + * 变更游戏积分 + * @param destPlayer + */ + public void addAllScore(EXPlayer destPlayer) { + if (true) + { + TArray seatData = TArray.newInstance(); + int add510kFen = 0; + int jiangli = 0; + //用8替代5 + Map> cardMap =CardUtil.getCardListMap(this.card.jiangliCardList); + if (cardMap.containsKey(RoomCard.CUR_5_CARD)) + { + add510kFen += cardMap.get(RoomCard.CUR_5_CARD).size() * 5; + } + if (cardMap.containsKey(10)) + { + add510kFen += cardMap.get(10).size() * 10; + } + if (cardMap.containsKey(13)) + { + add510kFen += cardMap.get(13).size() * 10; + } + if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 0 || this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 1) + { + jiangli += 100; + } + else { + jiangli += 40; + } + destPlayer.jiangli = jiangli; + destPlayer.leftCardFen = add510kFen; + destPlayer.cur510kFen += add510kFen; + destPlayer.cur510kFen += destPlayer.jiangli; + destPlayer.cur510kFen += destPlayer.ju510kFen; + //destPlayer.curXiFen += destPlayer.juXiFen; + destPlayer.allJu510kFen += destPlayer.ju510kFen; + destPlayer.allJiangLi += destPlayer.jiangli; + destPlayer.allLeftCardFen += destPlayer.leftCardFen; + { + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("add510kfen", add510kFen); + seatListData.putInt("ju510kfen", destPlayer.ju510kFen); + seatListData.putInt("all510kfen", destPlayer.cur510kFen); + seatListData.putInt("juXiFen", destPlayer.juXiFen); + seatListData.putInt("curXiFen", destPlayer.curXiFen); + seatListData.putInt("jiangli", destPlayer.jiangli); + seatListData.putInt("aid", destPlayer.playerid); + seatData.addTObject(seatListData); + } + + if (this.playerMapByPlaying.size() == 2) { + for (Entry entry : this.playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer != destPlayer) { + int add510kFenFrom = 0; + int jiangliFrom = 0; + if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 0 || this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 1) + { + jiangliFrom = -100; + } + else { + jiangliFrom = -40; + } + fromPlayer.jiangli = jiangliFrom; + fromPlayer.cur510kFen += add510kFenFrom; + fromPlayer.cur510kFen += fromPlayer.jiangli; + fromPlayer.cur510kFen += fromPlayer.ju510kFen; + //fromPlayer.curXiFen += fromPlayer.juXiFen; + fromPlayer.allJu510kFen += fromPlayer.ju510kFen; + fromPlayer.allJiangLi += fromPlayer.jiangli; + fromPlayer.allLeftCardFen += fromPlayer.leftCardFen; + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("add510kfen", add510kFenFrom); + seatListData.putInt("ju510kfen", fromPlayer.ju510kFen); + seatListData.putInt("all510kfen", fromPlayer.cur510kFen); + seatListData.putInt("juXiFen", fromPlayer.juXiFen); + seatListData.putInt("curXiFen", fromPlayer.curXiFen); + seatListData.putInt("jiangli", fromPlayer.jiangli); + seatListData.putInt("aid", fromPlayer.playerid); + seatData.addTObject(seatListData); + } + } + } else { + EXPlayer second = null; + EXPlayer third = null; + if (this.winPlayerList.size() >= 2) + { + second = this.winPlayerList.get(1); + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer.playerid != destPlayer.playerid && fromPlayer.playerid != second.playerid) { + third = fromPlayer; + } + } + } + + if (second == null || third == null) + { + for (Entry entry : this.playerMapByPlaying.entrySet()) { + + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer != destPlayer) { + if (fromPlayer.cardInhand.size() <= 0) + { + second = fromPlayer; + } + else { + third = fromPlayer; + } + } + } + } + + + if (second != null) + { + int add510kFenFrom = 0; + int jiangliFrom = 0; + if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 0) + { + jiangliFrom = -40; + } + else if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 1) + { + jiangliFrom = -30; + } + else { + jiangliFrom = 0; + } + second.jiangli = jiangliFrom; + second.cur510kFen += add510kFenFrom; + second.cur510kFen += second.jiangli; + second.cur510kFen += second.ju510kFen; + //second.curXiFen += second.juXiFen; + second.allJu510kFen += second.ju510kFen; + second.allJiangLi += second.jiangli; + second.allLeftCardFen += second.leftCardFen; + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("add510kfen", add510kFenFrom); + seatListData.putInt("ju510kfen", second.ju510kFen); + seatListData.putInt("all510kfen", second.cur510kFen); + seatListData.putInt("juXiFen", second.juXiFen); + seatListData.putInt("curXiFen", second.curXiFen); + seatListData.putInt("aid", second.playerid); + seatListData.putInt("jiangli", second.jiangli); + seatData.addTObject(seatListData); + } + + if (third != null) { + int add510kFenFrom = 0; + int jiangliFrom = 0; + if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 0) + { + jiangliFrom = -60; + } + else if (this.config.getInt(Config.ROOM_CONFIG_510K_SCORE_TYPE) == 1) + { + jiangliFrom = -70; + } + else { + jiangliFrom = -40; + } + third.jiangli = jiangliFrom; + third.cur510kFen += add510kFenFrom; + third.cur510kFen += third.jiangli; + third.cur510kFen += third.ju510kFen; + //third.curXiFen += third.juXiFen; + third.allJu510kFen += third.ju510kFen; + third.allJiangLi += third.jiangli; + third.allLeftCardFen += third.leftCardFen; + ITObject seatListData = TObject.newInstance(); + seatListData.putInt("add510kfen", add510kFenFrom); + seatListData.putInt("ju510kfen", third.ju510kFen); + seatListData.putInt("all510kfen", third.cur510kFen); + seatListData.putInt("juXiFen", third.juXiFen); + seatListData.putInt("curXiFen", third.curXiFen); + seatListData.putInt("aid", third.playerid); + seatListData.putInt("jiangli", third.jiangli); + seatData.addTObject(seatListData); + } + } + TObject allData = TObject.newInstance(); + allData.putTArray("gold_list", seatData); + allData.putInt("cur510kFen", 0); + this.broadCastToClient(0, Config.GAME_EVT_ALL_UPDATE_510K_SCORE, allData); + + if (totalType()) + { + boolean has = false; + for(int i = 0; i < this.winPlayerList.size(); i++) + { + EXPlayer xxPlayer = this.winPlayerList.get(i); + if (xxPlayer.cur510kFen >= RoomCard.MAX_510K_SCORE) + { + xxPlayer.jieSuanJiangLi += 100; + xxPlayer.cur510kFen += xxPlayer.jieSuanJiangLi; + has = true; + break; + } + } + + if (has == false) + { + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.cur510kFen >= RoomCard.MAX_510K_SCORE) + { + player.jieSuanJiangLi += 100; + player.cur510kFen += player.jieSuanJiangLi; + break; + } + } + } + } + } + + if (totalType()) + { + EXPlayer winPlayer = this.win; + int max = RoomCard.MAX_510K_SCORE; + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer.cur510kFen+fromPlayer.curXiFen >= max) + { + max = fromPlayer.cur510kFen+fromPlayer.curXiFen; + winPlayer = fromPlayer; + } + } + + if (winPlayer != null) + { + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer.playerid != winPlayer.playerid) + { + this.addScore(winPlayer, fromPlayer, winPlayer.cur510kFen+winPlayer.curXiFen-fromPlayer.cur510kFen-fromPlayer.curXiFen, EXScore.WIN); + } + } + } + } + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + @Override + public void endGame() { + addAllScore(win); + + this.chooseover = 0; + + EXPlayBack pb = (EXPlayBack)this.playBackData; + + + ITObject pbResult = TObject.newInstance(); + + ITArray info = new TArray(); + for (Entry entry : playerMapByPlaying.entrySet()) { + EXPlayer player=(EXPlayer)entry.getValue(); + ITObject obj = TObject.newInstance(); + obj.putInt("seat", player.seat); + obj.putInt("score", player.score.round_score); + obj.putBoolean("entrust", player.entrust); + obj.putInt("cur510kFen", player.cur510kFen); + obj.putInt("ju510kFen", player.ju510kFen); + obj.putInt("curXiFen", player.curXiFen); + obj.putInt("juXiFen", player.juXiFen); + obj.putInt("jiangli", player.jiangli); + obj.putInt("leftCardFen", player.leftCardFen); + obj.putInt("jieSuanJiangLi", player.jieSuanJiangLi); + obj.putInt("boomnum", player.boomnum); + info.addTObject(obj); + } + pbResult.putTArray("result", info); + + pb.addResultCommand(win.seat, pbResult); + + pb.addNewRoundCommand(); + super.endGame(); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/EXScore.java b/game_pk_sanqianfen/src/main/java/extend/pk/EXScore.java new file mode 100644 index 0000000..fc4343f --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/EXScore.java @@ -0,0 +1,18 @@ +package extend.pk; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + public static final int ZHA = 2; + + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + this.round_log.put(ZHA, 0); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/RoomCard.java b/game_pk_sanqianfen/src/main/java/extend/pk/RoomCard.java new file mode 100644 index 0000000..1617080 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/RoomCard.java @@ -0,0 +1,524 @@ +package extend.pk; + +import com.game.Global; +import extend.pk.uitl.CardUtil; + +import java.util.*; + +public class RoomCard { + + public static final int HEART_TEN = 310; + public static final int CARD_A = 14; + public static final int CARD_2 = 15; + public static final int CARD_3 = 3; + public static final int MAX_510K_SCORE = 1000; + public static final int CUR_5_CARD = 8; + public List cardList; + public List cardListTemp; + public List jiangliCardList; + EXRoom room; + int num; + int maxPlayer; + Random rand = new Random(); + + int boomNumLimit = rand.nextInt(2) + 2; + int sangzhangNumLimit = rand.nextInt(5) + 10; + + int totalBoomNum = 0; + int totalSanZhangNum = 0; + + public RoomCard(EXRoom table,int num,int maxPlayer) { + this.cardList = new ArrayList(); + this.cardListTemp = new ArrayList(); + this.jiangliCardList = new ArrayList(); + this.room = table; + this.num = num; + this.maxPlayer = maxPlayer; + } + + public void init() { + this.boomNumLimit = rand.nextInt(2) + 5; + this.sangzhangNumLimit = rand.nextInt(5) + 10; + + this.totalBoomNum = 0; + this.totalSanZhangNum = 0; + this.cardList.clear(); + this.jiangliCardList.clear(); + this.initCard(); + int currentBoomNum = 0; + int currentSanZhangNum = 0; + Map result = new HashMap(); + do { + currentBoomNum = 0; + currentSanZhangNum = 0; + this.shuffle(); + for(int i = 0; i entry : result.entrySet()) { + if(entry.getValue() >= 4) { + currentBoomNum++; + } + else if(entry.getValue() == 3) { + currentSanZhangNum++; + } + } + }while((currentBoomNum + totalBoomNum > boomNumLimit) || (currentSanZhangNum + totalSanZhangNum > sangzhangNumLimit)); + } + + private void initCard() { + for(int i = 0; i < 3; i++) + { + for (int index = 8; index <= 15; index++) { + // 方片 + this.cardList.add(new CardObj(100 + index)); + // 梅花 + this.cardList.add(new CardObj(200 + index)); + // 红桃 + this.cardList.add(new CardObj(300 + index)); + // 黑桃 + this.cardList.add(new CardObj(400 + index)); + } + } + + rand.setSeed(System.currentTimeMillis()); + int len = this.cardList.size(); + for(int i = 0; i < len; i++) { + + int randpos = rand.nextInt(1000000000) % len; + CardObj cotemp = this.cardList.get(i); + + this.cardList.set(i, this.cardList.get(randpos)); + this.cardList.set(randpos,cotemp); + } + + Global.logger.info("RoomCard initCard(): "+this.cardList); + } + + private void shuffle() { + for(int i = 0; i < 100; i++) + { + Collections.shuffle(this.cardList); + } + Random rand = new Random(); + int len = this.cardList.size(); + + for(int i = 0; i < 10000; i++) { + rand.setSeed(System.currentTimeMillis()); + int start = rand.nextInt(len); + int end = rand.nextInt(len); + + CardObj co = this.cardList.get(start); + this.cardList.set(start, this.cardList.get(end)); + this.cardList.set(end, co); + } + } + + public CardObj pop() { + CardObj card = this.cardList.remove(0); + return card; + } + + public int getCount() { + return this.cardList.size(); + } + + // 发牌 + public List deal(boolean room_white, boolean is_white, double room_rate, int white_black_status, double black_white_rate, double black_black_rate, int maxZhaDan, int cardNum) { + List dealCards = new ArrayList(); + //shuffle(); + + double rand1 = Math.random() % 100 * 100; + for (int index = 0; index < this.num ; index++) { + if (room_white && is_white) + { + if (rand1 > room_rate) + { + if (index == 0) + { + if (maxZhaDan == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards xingyun card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, true, maxZhaDan, cardNum)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + else { + double rand111 = Math.random() % 100 * 100; + if (tempCard.cardMod <= 11 && rand111 < 10) + { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, true, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + else { + double rand111 = Math.random() % 100 * 100; + if (tempCard.cardMod <= 11 && rand111 <= 10) + { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (white_black_status == 2) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxZhaDan == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards white card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, true, maxZhaDan, cardNum)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, true, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else if (white_black_status == 1) { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxZhaDan == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards black card"); + } + } +; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, true, false, maxZhaDan, cardNum)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, true, false, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + else { + if (room_white && rand1 > room_rate) + { + if (index == 0) + { + if (maxZhaDan == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, false, maxZhaDan, cardNum)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (rand1 < black_white_rate) + { + if (index == 0) + { + if (maxZhaDan == 0) + { + Global.logger.info("dealcards rand card"); + } + else + { + Global.logger.info("dealcards general cha card"); + } + } + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard(tempCard.cardMod, dealCards, false, false, maxZhaDan, cardNum)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + else { + if (index == 0) + Global.logger.info("dealcards rand card"); + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + CardObj tempCard = this.pop(); + + if (isGooodCard2(tempCard.cardMod, dealCards, false, true, 0, 0)) { + if (this.cardList.size() > 0 && count++ <= this.cardList.size()) { + tempCardList.add(tempCard); + continue; + } + } + + dealCards.add(tempCard); + break; + } while (true); + this.cardList.addAll(tempCardList); + } + } + } + } + } + //shuffle(); + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + + boolean isGooodCard(int card, List dealCards, boolean black, boolean white, int maxZhaDan, int cardNum) + { + if (isGooodCard2(card, dealCards, black, white, maxZhaDan, cardNum)) { + return true; + } + + if (maxZhaDan > 0) + { + if (cardNum > 0) + { + if (CardUtil.checkCard(card, dealCards, cardNum-1)) { + if (card >= maxZhaDan) + { + return true; + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, cardNum-1)) { + return true; + } + } + } + else { + if (CardUtil.checkGoodCard(card, dealCards, 6)) { + if (card >= maxZhaDan) + { + return true; + } + } + } + } + + return false; + } + + boolean isGooodCard2(int card, List dealCards, boolean black, boolean white, int maxZhaDan, int cardNum) + { + double rand = Math.random() % 100 * 100; + if (black) + { + if (CardUtil.checkQPai(card, dealCards) && rand < 70) + { + Global.logger.info("remove checkQPai"); + return true; + } + } + else { + if (!white) + { + if (CardUtil.checkQPai(card, dealCards) && rand < 50) + { + Global.logger.info("remove checkQPai"); + return true; + } + + if (CardUtil.checkGoodCard(card, dealCards, 6)) { + if (rand < 80) + { + Global.logger.info("remove seven zha dan"); + return true; + } + else { + Global.logger.info("remove seven zha dan fail"); + } + } + } + } + + if (CardUtil.checkGoodCard(card, dealCards, 6)) { + if (rand < 60) + { + Global.logger.info("remove seven zha dan"); + return true; + } + else { + Global.logger.info("remove seven zha dan fail"); + } + } + + return false; + } + + public List deal() { + List dealCards = new ArrayList(); + + for (int index = 0; index < this.num ; index++) { + dealCards.add(this.pop()); + } + + Map result = new HashMap(); + CardUtil.getCardNumMap(result, dealCards); + for(Map.Entry entry : result.entrySet()) { + if(entry.getValue() >= 4) { + this.totalBoomNum++; + } + else if(entry.getValue() == 3) { + this.totalSanZhangNum++; + } + } + + return dealCards; + } + +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/SettleLog.java b/game_pk_sanqianfen/src/main/java/extend/pk/SettleLog.java new file mode 100644 index 0000000..eb6b8c6 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/SettleLog.java @@ -0,0 +1,44 @@ +package extend.pk; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..7f52804 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerDiscardState.java @@ -0,0 +1,545 @@ +package extend.pk.player.state; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.game.Global; +import com.game.Router; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import com.taurus.core.entity.TObject; +import extend.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.RoomCard; +import extend.pk.room.state.EXRoomSetpState; +import extend.pk.uitl.CardCheck; +import extend.pk.uitl.CardConfig; +import extend.pk.uitl.CardUtil; + +/** + * 等待玩家出牌状态 + * + * + */ +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + // 设置防作弊场开牌的标志 + owner.open = 1; + + EXRoom room = owner.getRoom(); + if (owner.cardInhand.size() == 0) { + //如果最后一次打牌的座位等于自己 分数加到自己身上 + if(room.lastDiscardSeat == owner.seat) { + //加5,10,k分 + room.add510kScore(owner); + room.lastDiscardSeat = 0; + //加5,10,k分 + int hasCardNum = 0; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + if (player.cardInhand.size() > 0) + { + hasCardNum++; + } + } + if (hasCardNum <= 1) + { + this.over(owner); + return; + } + } + toNextState(owner); + return; + } + + //如果最后一次打牌的座位等于自己 分数加到自己身上 + if(room.lastDiscardSeat == owner.seat) { + //加5,10,k分 + room.add510kScore(owner); + //加5,10,k分 + int hasCardNum = 0; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + if (player.cardInhand.size() > 0) + { + hasCardNum++; + } + } + if (hasCardNum <= 1) + { + this.over(owner); + return; + } + } + + //如果最后一次的打牌的座位不等于零并且最后一次打牌的座位不等于自己 + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + boolean bNextBaodan = false; + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + bNextBaodan = true; + } + CardGroup big_ct = CardCheck.genOutCard(owner.cardInhand, room.discard,room.config,bNextBaodan); + if(big_ct==null) { + + owner.stateMachine.changeState(Global.getState(EXPlayerPassState.class)); + return; + } + else { + + if(big_ct.config.type == Config.TYPE_ZHA ) { + // 如果能出完,就自动出完 + if(big_ct.card_list.size() == owner.cardInhand.size()) { + + doAction(owner,big_ct,true); + return; + } + } + else { + + boolean bContainZha = false; + + boolean bThreeA = false; + if(owner.room.config.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = cardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + bContainZha = true; + } + + // 三条A 不能拆 + if(entry.getKey() == RoomCard.CARD_A && bThreeA && handNum >= 3) { + + bContainZha = true; + } + } + + if(big_ct.card_list.size() == owner.cardInhand.size() && bContainZha == false) { + doAction(owner,big_ct,true); + return; + } + } + } + } + else { + + // 自动出牌 + //CardGroup auto_ct = CardCheck.autoOutLastHand(owner.cardInhand, room.config,false); + //if(auto_ct != null) { + // doAction(owner,auto_ct,true); + // return; + //} + } + EXMainServer.gameCtr.discardTipEvent(owner); + + owner.startActionTimer(); + } + + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.discardTipEvent(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + public void over(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.winPlayerList.size() > 0) + { + EXPlayer win = room.winPlayerList.get(0); + room.bankerSeat = win.seat; + room.win = win; + } + else { + if (room.playerMapByPlaying.size() == 2) + { + for (Map.Entry entry : room.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.cardInhand.size() == 0) + { + room.bankerSeat = player.seat; + room.win = player; + break; + } + } + } + else { + for (Map.Entry entry : room.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.playerid != owner.playerid && player.cardInhand.size() == 0) + { + room.bankerSeat = player.seat; + room.win = player; + } + } + } + } + + room.endGame(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + + ITObject netParam = (ITObject) param; + ITArray card_list = netParam.getTArray("card"); + ITArray all_card = netParam.getTArray("all_card"); + + if (all_card != null) + { + ArrayList temCardList = new ArrayList(); + for(int i=0;i< all_card.size();++i) { + temCardList.add(all_card.getInt(i)); + } + Collections.sort(temCardList); + + ArrayList temCardList2 = new ArrayList(); + for(int i=0;i< owner.cardInhand.size();++i) { + temCardList2.add(owner.cardInhand.get(i).card); + } + Collections.sort(temCardList2); + + if (!temCardList.equals(temCardList2)) + { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + // 如果出的牌的个数为0 或者大于手牌的数目 则是非法的 + if (card_list.size() == 0 || card_list.size() > owner.cardInhand.size()) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + + List list = CardUtil.toList(card_list); + + + for(CardObj card : list) { + + boolean bNotExisted = false; + + for(CardObj handc : owner.cardInhand) { + if(card.card == handc.card) { + bNotExisted = true; + break; + } + } + + if(bNotExisted == false) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + } + + if(owner.getRoom().firstCard != 0 && CardUtil.getCard1(owner.getRoom().firstCard, list) == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MIN); + return; + } + + CardGroup ct = CardCheck.getType(list, owner.room.config); + if(ct == null) { + + if (CardCheck.isConfig4_2_and_4_3(owner.room.config)) { + //四带二/四带三摆尾 + if (list.size() == owner.cardInhand.size()) { //最后一把 + Map cardMap =CardUtil.getCardNumMap(list); + + if(owner.room.config.containsKey(Config.ROOM_CONFIG_SIDAI_2) && owner.room.config.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) { + if (list.size() == 5) { + ct = CardCheck.checkSiWithTwo(cardMap,owner.room.config); + } + } + + if (ct == null) { + if(owner.room.config.containsKey(Config.ROOM_CONFIG_SIDAI_3) && owner.room.config.getBoolean(Config.ROOM_CONFIG_SIDAI_3)) { + if (list.size() == 5 || list.size() == 6) { + ct = CardCheck.checkSiWithThree(cardMap,owner.room.config); + } + } + } + + if (ct != null) { + for(CardObj cardObj : owner.cardInhand) { + ct.card_list.add(cardObj); + } + ct.card_list_mp = CardUtil.toTArray(ct.card_list); + } + } + } + + + if (ct == null) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + boolean bThreeA = false; + if(owner.room.config.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + //验证客户端发过来的类型 + if(!CardCheck.tryType(ct,owner.cardInhand.size(),owner.room.config)) { + + // tryType 判断3条a判断不出来, 所以 + if(!(ct.config.type == Config.TYPE_ZHA && + card_list.size() == 3 && + bThreeA && + CardUtil.checkCard(RoomCard.CARD_A, list, 3))) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + } + + // 如果炸弹不允许拆分,则检测非炸弹和4带三的牌型,看他们是否拆分了炸弹 + if(owner.room.config.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + + if(ct.config.type != Config.TYPE_ZHA ) { + + Map hangCardMap =CardUtil.getCardNumMap(owner.cardInhand); + Map cardMap =CardUtil.getCardNumMap(list); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = hangCardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum >= 4) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + + // 三条A 不能拆 + if(entry.getKey() == RoomCard.CARD_A && bThreeA && handNum == 3) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + } + } + else { + Map hangCardMap =CardUtil.getCardNumMap(owner.cardInhand); + Map cardMap =CardUtil.getCardNumMap(list); + for(Map.Entry entry : cardMap.entrySet()) { + + int handNum = hangCardMap.get(entry.getKey()); + + // 4张牌 不能出现在处大赞的牌型中 + if(handNum != ct.card_list.size()) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + + // 三条A 不能拆 + if(entry.getKey() == RoomCard.CARD_A && bThreeA && handNum == 3) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_BOMB_CHAI); + return; + } + } + } + } + + doAction(owner,ct,false); + break; + + case EXActionEvent.EVENT_PASS: + + if(owner.room.config.getInt(Config.ROOM_CONFIG_WILL_BE_OUT) == 1) { + return; + } + pass(owner); + + break; + case EXActionEvent.EVENT_OFFLINE: + owner.startActionTimer(); + break; + case EXActionEvent.EVENT_TIMER_AUTO: + case EXActionEvent.EVENT_ENTRUST: + + AutoOut(owner); + break; + } + } + + private void AutoOut(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + + CardGroup big_ct = null; + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && room.discard.config.type ==Config.TYPE_DANPAI && playerNext.cardInhand.size() == 1) { + + Map> cardMap =CardUtil.getCardListMap(owner.cardInhand); + big_ct = CardCheck.selectDanpai(cardMap,room.discard,room.config,true); + }else { + big_ct = CardCheck.tryBig(owner.cardInhand, room.discard); + } + + if (big_ct != null) { + big_ct.card_list_mp = CardUtil.toTArray(big_ct.card_list); + doAction(owner,big_ct,true); + } else { + Global.logger.info("big_ct == null pass !!!!!!!!!!!!"); + pass(owner); + } + + }else { + + // 在托管或者自动出牌的时候 系统先出炸弹,如果炸弹没有 再出单张 + // 将来可以把这个函数做的能智能一些,不光可以出炸弹 也可以出顺子飞机等等 + CardGroup out_ct = CardCheck.autoOut(owner.cardInhand, owner.room.config); + if(out_ct == null) { + + out_ct = new CardGroup(); + List out_list = new ArrayList<>(); + out_ct.card_list = out_list; + out_ct.config = CardConfig.DAN; + out_ct.len = 1; + + if(room.firstCard != 0) { + CardObj co = CardUtil.getCard1(room.firstCard, owner.cardInhand); + out_list.add(co); + } + else + { + EXPlayer next = (EXPlayer) owner.room.playerMapBySeat.get(owner.nextSeat); + if(next.cardInhand.size() == 1) { + out_list.add(owner.cardInhand.get(owner.cardInhand.size() -1)); + }else { + out_list.add(owner.cardInhand.get(0)); + } + } + } + + out_ct.card_list_mp = CardUtil.toTArray(out_ct.card_list); + out_ct.min_card = out_ct.card_list.get(0).cardMod; + + doAction(owner,out_ct,true); + } + } + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + private void doAction(EXPlayer owner,CardGroup ct,boolean skip) { + + EXRoom room = owner.getRoom(); + boolean outcard = true; + if(!skip) { + + if(room.lastDiscardSeat != 0 &&room.lastDiscardSeat != owner.seat) { + outcard = CardCheck.tryCompete(room.discard, ct,room.config); + } + + // 如果玩家的下家只有一张牌,玩家出单张必须是最大的 + if(outcard && ct.config.type == Config.TYPE_DANPAI) { + /* + EXPlayer playerNext = (EXPlayer)room.playerMapBySeat.get(owner.nextSeat); + if(playerNext != null && playerNext.cardInhand.size() == 1) { + + Map cardMap =CardUtil.getCardNumMap(owner.cardInhand); + for(Integer number : cardMap.keySet()) { + + if(ct.min_card < number) { + + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_MUST_OUT_MAX); + return; + } + } + } + */ + } + } + if(!outcard) { + EXMainServer.gameCtr.sendPutError(owner,Config.PUT_ERROR_INVALID_TYPE); + return; + } + + ///////////////////////////////////////////// + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + + ITObject param = new TObject(); + param.putInt("player", player.seat); + param.putTArray("handCards", CardUtil.toTArray(player.cardInhand)); + player.sendEvent(Config.GAME_EVT_CARDINHAND, param); + + //Global.logger.info(player + " Config.GAME_EVT_CARDINHAND: " + param); + } + ///////////////////////////////////////////// + + EXMainServer.gameCtr.outCard(owner,ct); + + if (owner.cardInhand.size() == 0) + { + room.winPlayerList.add(owner); + int hasCardNum = 0; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + if (player.cardInhand.size() <= 0) + { + hasCardNum++; + } + } + if (hasCardNum == 1) + { + ITObject param = new TObject(); + param.putInt("player", owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_SHANGYOU, param); + } + } + + this.toNextState(owner); + + + } + + +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPassState.java b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPassState.java new file mode 100644 index 0000000..7985073 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPassState.java @@ -0,0 +1,52 @@ +package extend.pk.player.state; + +import com.game.Global; +import com.game.data.Timer; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.room.state.EXRoomSetpState; + +/** + * 等待玩家Pass状态 + * + * + */ +public class EXPlayerPassState extends StateBase { + + private void pass(EXPlayer owner) { + EXMainServer.gameCtr.pass(owner);//打不起过 + this.toNextState(owner);//下一位大哥 + } + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if(!owner.entrust) { + Timer passTimer = new Timer(1000, new Timer.ITaskHandler() { + @Override + public void doTask(Timer timer) { + pass(owner); + } + }); + room.addTimer(passTimer); + }else { + pass(owner); + } + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..d2ecadb --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,64 @@ +package extend.pk.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; + +import extend.pk.EXActionEvent; +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; + + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.piaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piao = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + EXMainServer.gameCtr.piaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_PIAO)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomDealState.java b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomDealState.java new file mode 100644 index 0000000..c2e34a9 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomDealState.java @@ -0,0 +1,112 @@ +package extend.pk.room.state; + + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.pk.Config; +import extend.pk.EXMainServer; +import extend.pk.EXPlayBack; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.uitl.CardCheck; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * 房间发牌状态 + * + * + */ +public class EXRoomDealState extends StateBase { + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Map.Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 3000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //owner.card.init(); + if(owner.bankerSeat!=0&&!owner.playerMapBySeat.containsKey(owner.bankerSeat)) { + owner.bankerSeat = 0; + } + EXMainServer.gameCtr.dealCard(owner); + + owner.playBackData = new EXPlayBack(owner); + + if(owner.config.getInt(Config.ROOM_CONFIG_MINBOOM) == 1) { + + int startSpringSeat = 0; + int seat = owner.bankerSeat; + do { + + EXPlayer player = (EXPlayer)owner.playerMapBySeat.get(seat); + if(CardCheck.checkStartSpring(player.cardInhand)) { + + startSpringSeat = seat; + break; + } + }while(seat != owner.bankerSeat); + + if(startSpringSeat != 0) { + owner.bankerSeat = startSpringSeat; + owner.win = (EXPlayer)owner.playerMapBySeat.get(startSpringSeat); + owner.endGame(); + return; + } + } + + + + owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomPiaoState.java b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..dbb1ce8 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomPiaoState.java @@ -0,0 +1,31 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.EXActionEvent; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerPiaoNiaoTipState; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO)) { + if(owner.piaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomSetpState.java b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ce6843c --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomSetpState.java @@ -0,0 +1,35 @@ +package extend.pk.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.pk.EXMainServer; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; +import extend.pk.player.state.EXPlayerDiscardState; + +/** + * 房间转换座位 + * + * + */ +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + EXPlayer player = null; + if (owner.activeSeat == 0) { + player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = (EXPlayer) owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = (EXPlayer) owner.playerMapBySeat.get(nextSeat); + } + + + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomStartGameState.java b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..665018e --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/room/state/EXRoomStartGameState.java @@ -0,0 +1,43 @@ +package extend.pk.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.pk.Config; +import extend.pk.EXPlayer; +import extend.pk.EXRoom; + +/** + * 房间开始状态 + * + * + */ +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.clearEx(); + } + owner.clearEx(); + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + if(owner.config.containsKey(Config.ROOM_CONFIG_PIAO) && owner.config.getInt(Config.ROOM_CONFIG_PIAO) != 0) { + owner.stateMachine.changeState(Global.getState(EXRoomPiaoState.class)); + } + else{ + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardCheck.java b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardCheck.java new file mode 100644 index 0000000..e78d33a --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardCheck.java @@ -0,0 +1,1453 @@ +package extend.pk.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; + +import extend.pk.CardGroup; +import extend.pk.CardObj; +import extend.pk.Config; +import extend.pk.RoomCard; + + +/** + * + * + */ +public class CardCheck { + + /** + * 服务器跟牌判定 + * @param cardInhand + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup genOutCard(List cardInhand,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + + CardGroup cg = null; + + Map> cardMap =CardUtil.getCardListMap(cardInhand); + int handCardSize = cardInhand.size(); + // 如果有炸弹 并且玩家手上仅剩下炸弹 就不用找了 直接出牌就可以了 + cg = selectZha(cardMap,out,roomConfig); + if(cg != null && cg.card_list.size() == handCardSize) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + return cg; + } + + // 如果别的玩家出的是一张单牌,则寻找一个合适的单牌,如果找不到就用炸弹,炸弹没有则过 + if(out.config.type == Config.TYPE_DANPAI) { + + CardGroup tempCg = selectDanpai(cardMap,out,roomConfig,nextBaodan); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是不能带牌的牌型(对子,顺子,连队)则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_DUIZI + || out.config.type == Config.TYPE_SHUNZI + || out.config.type == Config.TYPE_LIANDUI) { + + CardGroup tempCg = selectWithoutCardType(handCardSize,cardMap,out,roomConfig); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的三带牌型 ,则寻找合适的牌型,如果找不到就用炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_3_2) { + + boolean bLack = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_LACK) == 1) { + bLack = true; + } + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + + // 如果别的玩家出的是带牌的飞机牌型,则寻找合适的牌型,如果找不到用则炸弹,炸弹没有则过 + else if(out.config.type == Config.TYPE_FEIJI) { + + boolean bLack = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_PLANE_LACK) == 1) { + bLack = true; + } + + CardGroup tempCg = selectWithCardType(cardInhand,cardMap,out,roomConfig,bLack); + if(tempCg != null) { + cg = tempCg; + } + } + // 如果是四带二或者四带三 就不处理了,如果有炸弹,则玩家自己去选择是炸还是跟,如果没有炸弹 玩家也大不了,所以后面就不用判断了 + if(cg != null) { + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + return cg; + } + + /** + * 选择炸弹 + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectZha(Map> cardMap,CardGroup out,ITObject roomConfig) { + + CardGroup cg = null; + + boolean bThreeA = false; + if(roomConfig != null && roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int minValue = 0; + if(out.config.type == Config.TYPE_ZHA) { + minValue = out.min_card; + } + + for(Map.Entry> entry : cardMap.entrySet()) { + if (out.config.type == Config.TYPE_ZHA) + { + if (entry.getValue().size() > out.card_list.size()) + { + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + else if(entry.getValue().size() == out.card_list.size()) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + else { + if(entry.getValue().size() >= 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA && entry.getValue().size() == 3)) { + + if(entry.getKey() > minValue) { + + cg = new CardGroup(); + + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + cg.card_list = new ArrayList<>(); + for(CardObj cardObj : entry.getValue()) { + cg.card_list.add(cardObj); + } + break; + } + } + } + } + + return cg; + } + + /** + * 选择单牌 + * @param cardMap + * @param out + * @param roomConfig + * @param nextBaodan + * @return + */ + public static CardGroup selectDanpai(Map> cardMap,CardGroup out,ITObject roomConfig,boolean nextBaodan) { + CardGroup cg = null; + + int minValue = out.min_card + 1; + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(!nextBaodan) { + + for(int i = minValue; i <= 15; i++) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() >= 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3 ))) { + + } + else { + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + else + { + for(int i = 15; i >= minValue; i--) { + + List listCard = cardMap.get(i); + if(listCard != null && listCard.size() >= 1) { + + // 如果是炸弹 并且不能拆分炸弹,则不能用它作为单牌来处理 + if(bDemolition && (listCard.size() >= 4 || (i == RoomCard.CARD_A && bThreeA && listCard.size() == 3))) { + + } + else { + + cg = new CardGroup(); + + cg.config = CardConfig.DAN; + cg.min_card = i; + cg.len = 1; + + cg.card_list = new ArrayList<>(); + cg.card_list.add(listCard.get(0)); + break; + } + } + } + } + + return cg; + } + + /** + * 选择不需要带牌的牌型 + * @param handCardSize + * @param cardMap + * @param out + * @param roomConfig + * @return + */ + private static CardGroup selectWithoutCardType(int handCardSize,Map> cardMap,CardGroup out,ITObject roomConfig) { + CardGroup cg = null; + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>15)) { + + int count =0; + + for(int i = min_card; i <= 15;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() >= 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >=out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + private static CardGroup selectWithCardType(List cardInhand, + Map> cardMap, + CardGroup out, + ITObject roomConfig, + boolean bLack) { + + CardGroup cg = null; + + int handCardSize = cardInhand.size(); + + boolean bDemolition = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_DEMOLITION) == 1) { + bDemolition = true; + } + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int len = out.len; + + // 如果手牌数满足要求 + if( handCardSize >= len * out.config.repeat_num ) { + + List card_list = new ArrayList(); + + //最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + int min_card = out.min_card + 1; + + //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + int max_card = min_card+len -1; + + //长度如果大于一并且最大的牌 + if(!(len>1&&max_card>15)) { + + int count =0; + + for(int i = min_card; i <= 15;++i) { + + List list =cardMap.get(i); + + // 如果牌值对应的牌为空 或者他是炸弹,则之前找到的牌取消 + if( list == null || (bDemolition && (list.size() >= 4 || (i == RoomCard.CARD_A && bThreeA && list.size() == 3))) ) { + count=0; + card_list.clear(); + continue; + } + + // 如果牌值对应的牌的个数满足要求,则将牌放入队列中 + if(list.size() >= out.config.repeat_num) { + + for(int k = 0; k < out.config.repeat_num;++k) { + card_list.add(list.get(k)); + } + count++; + + // 如果已经找到了足够数量的相同牌型 + if(count == len) { + + int sd = out.config.repeat_num * len + out.config.with_card_num * len; + + boolean sandaidan = roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) && roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 1; + if(sandaidan) { + + if(handCardSize < out.card_list.size()) { + return cg; + } + } + else { + + if(bLack == false && handCardSize < sd) { + + return cg; + } + } + + // 新建一个临时的列表,来保存剩余的牌 + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + // 如果剩余的牌有炸弹,则需要把剩余牌中的炸弹对应的牌从临时列表中剔除,以确定是否有足够的单牌 + // 如果因为剔除的原因,最后牌型不能做成,那就提示他有炸弹出就可以了 + Map> reservedCardMap = CardUtil.getCardListMap(tem_list); + int duiNum = 0; + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num >= 4 || (entry.getKey() == RoomCard.CARD_A && bThreeA && num == 3)) { + + CardUtil.removeCard(tem_list, entry.getValue()); + } + + if(num >= 2) { + duiNum++; + } + } + + + if(sandaidan) { + + boolean isDui = sd == out.card_list.size(); + if(isDui) { + + if(duiNum < len) { + return cg; + } + + for(Map.Entry> entry : reservedCardMap.entrySet()) { + + int num = entry.getValue().size(); + if(num >= 2 && num < 4) { + card_list.add(entry.getValue().get(0)); + card_list.add(entry.getValue().get(1)); + } + } + + }else { + + for(int m = 0; m < len; m++) { + card_list.add(tem_list.get(m)); + } + } + } + else { + + // 如果手牌数多于牌型的基本要求 + if(handCardSize >= sd) { + + if(tem_list.size() < out.config.with_card_num * len) { + return cg; + } + + for(int m = 0; m < out.config.with_card_num * len; m++) { + card_list.add(tem_list.get(m)); + } + } + else { + + card_list.addAll(tem_list); + } + } + + cg = new CardGroup(); + + cg.config = out.config; + cg.card_list = card_list; + cg.len = len; + cg.min_card = card_list.get(0).cardMod; + + return cg; + } + }else { + count=0; + card_list.clear(); + } + } + } + } + + return cg; + } + + /** + * 得到所出牌的牌型 + * @param cardOut + * @param roomConfig + * @return + */ + public static CardGroup getType(List cardOut,ITObject roomConfig) { + + CardGroup cg = autoOutLastHand(cardOut,roomConfig,true); + if(cg == null) { + + int len = cardOut.size(); + int sidai = roomConfig.getInt(Config.ROOM_CONFIG_SIDAI); + // 看看所处的牌是否 4带2 或者4带3 + if((len == 6 && sidai == 2) || (len == 7 && sidai == 3)) { + + Map cardMap =CardUtil.getCardNumMap(cardOut); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + if(len == 6) { + cg.config = CardConfig.SI_2; + } + else{ + cg.config = CardConfig.SI_3; + } + + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj : cardOut) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + } + } + } + + return cg; + } + + /** + * + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOutLastHand(List cardInhand,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + int len = cardInhand.size(); + if(len == 1) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DAN; + cg.min_card = cardInhand.get(0).cardMod; + cg.len = 1; + } + else if(len == 2) { + cg = checkTwo(cardMap); + } + else if(len == 3) { + + cg = checkThree(cardMap,roomConfig); + } + else if(len == 4) { + + cg = checkFour(cardMap,roomConfig); + } + else if(len == 5) { + + if(isConfig4_2_and_4_3(roomConfig) && getMaxCardNum(cardMap) == 4){//四带一 + return null;//不能判为三带二 + } + + cg = checkFive(cardMap,roomConfig,bSpecial); + } + else{ + if (bSpecial) { + if (len == 6) { + cg = checkSiWithTwo(cardMap,roomConfig); + } + + if (len == 7) { + cg = checkSiWithThree(cardMap,roomConfig); + } + } + + if (cg == null) { + cg = checkZhaDan(len,cardMap,roomConfig); + if (cg == null) + { + cg = checkShunzi(len,cardMap,roomConfig); + if(cg == null) { + cg = checkLiandui(len,cardMap,roomConfig); + if(cg == null) { + cg = checkFeiji(len,cardMap,roomConfig,bSpecial); + } + } + } + } + } + + if(cg != null) { + + for(CardObj cardObj : cardInhand) { + cg.card_list.add(cardObj); + } + cg.card_list_mp = CardUtil.toTArray(cg.card_list); + } + + return cg; + } + + private static int getMaxCardNum(Map cardMap) { + int maxNum = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if (entry.getValue() > maxNum) { + maxNum = entry.getValue(); + } + } + + return maxNum; + } + + public static boolean isConfig4_2_and_4_3(ITObject roomConfig) { + if((roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_2) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) + ||(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_3) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_3))){ + return true; + } else { + return false; + } + } + + private static CardGroup checkTwo(Map cardMap) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.DUIZI; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + return cg; + } + + private static CardGroup checkThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 3) { + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA == true) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + } + return cg; + } + + private static CardGroup checkFour(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 3) { + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA) { + return cg; + } + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 2) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + + if(minCard != 0 && maxCard != 0 && minCard + 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = 2; + } + } + } + return cg; + } + + private static CardGroup checkFive(Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + if(entry.getValue() == 5) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else if(entry.getValue() == 3 /*|| (entry.getValue() == 4 && bSpecial == true)*/) { + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + if(entry.getKey() == RoomCard.CARD_A && bThreeA) { + return cg; + } + + if(!roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) || roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 0) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else { + + if(entry.getValue() != 4 && cardMap.size() == 2) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SAN_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + } + + + break; + } + //else if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) { + else if(entry.getValue() == 1) { + + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == 5 && minCard != 0 && maxCard != 0 && minCard + 4 == maxCard) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = 5; + } + } + } + + return cg; + } + + public static CardGroup checkSiWithTwo(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + if(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_2) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_2)) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_2; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + break; + } + } + + return cg; + } + + public static CardGroup checkSiWithThree(Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 4) { + if(roomConfig.containsKey(Config.ROOM_CONFIG_SIDAI_3) && roomConfig.getBoolean(Config.ROOM_CONFIG_SIDAI_3)) { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SI_3; + cg.min_card = entry.getKey(); + cg.len = 1; + } + + break; + } + } + + return cg; + } + + private static CardGroup checkZhaDan(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == len) + { + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkShunzi(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + + int minCard = 0; + int maxCard = 0; + int count = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 1) + //if(entry.getValue() == 1 && entry.getKey() != RoomCard.CARD_2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.SHUNZI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + + return cg; + } + + private static CardGroup checkLiandui(int len,Map cardMap,ITObject roomConfig) { + + CardGroup cg = null; + int minCard = 0; + int maxCard = 0; + int count = 0; + + if(len % 2 != 0) { + return cg; + } + + len = len / 2; + + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() == 2) + { + if(minCard == 0 || entry.getKey() < minCard) { + minCard = entry.getKey(); + } + + if(maxCard == 0 || entry.getKey() > maxCard) { + maxCard = entry.getKey(); + } + count++; + + if(count == len && minCard != 0 && maxCard != 0 && minCard + len - 1 == maxCard) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.LIANDUI; + cg.min_card = minCard; + cg.len = count; + } + } + else + { + break; + } + } + return cg; + } + + private static CardGroup checkFeiji(int len,Map cardMap,ITObject roomConfig,boolean bSpecial) { + + CardGroup cg = null; + + int[] cardThreeCount = { 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0}; + + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + int num2 = 0; + for(Map.Entry entry : cardMap.entrySet()) { + + // 如果有炸弹 则不允许自动出牌 + if(bSpecial == false && (entry.getValue() == 4 || (entry.getKey() == RoomCard.CARD_A && entry.getValue() == 3 && bThreeA == true))) { + return cg; + } + + if(entry.getValue() >= 3) { + cardThreeCount[entry.getKey()] = 1; + } + else if(entry.getValue() == 2) { + num2++; + } + } + + int left = 0; + int right = 0; + + for(int i = 4; i < cardThreeCount.length; i++) { + + if(left == 0) { + + if(cardThreeCount[i] == 1 && cardThreeCount[i - 1] == 1) { + left = i - 1; + right = i; + } + } + else { + // 如果有连续的继续寻找 + if(cardThreeCount[i] == 1 && right + 1 == i) { + + right = i; + } + else + { + left = 0; + right = 0; + } + } + // 判断出来一个顺子,就判定一下是否可以全部出 + if(left != 0 && right != 0) { + + int threeCount = right - left + 1; + int sl = threeCount * 5; + + if(!roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) || roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 0) { + + if(len <= sl) { + if ((i + 1 < cardThreeCount.length) && (cardThreeCount[i+1] == 1)) + { + if (threeCount == 2) + { + left = 0; + right = 0; + continue; + } + else if (threeCount == 3){ + left += 1; + continue; + } + } + + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + }else { + if ((i + 1 < cardThreeCount.length) && (cardThreeCount[i+1] == 1)) + { + if (threeCount == 2) + { + left = 0; + right = 0; + continue; + } + else if (threeCount == 3){ + left += 1; + continue; + } + } + + int withMin = threeCount * 4; + if(len == withMin || num2 == threeCount || len == threeCount * 3) { + + cg = new CardGroup(); + cg.card_list = new ArrayList<>(); + cg.config = CardConfig.FEIJI; + cg.min_card = left; + cg.len = threeCount; + + return cg; + } + } + + } + } + + return cg; + } + + /** + * 自动出牌 + * @param cardInhand + * @param roomConfig + * @return + */ + public static CardGroup autoOut(List cardInhand,ITObject roomConfig) { + + CardGroup cg = null; + + //支持3A炸弹 + boolean bThreeA = false; + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_A) == 1) { + bThreeA = true; + } + + // 寻找炸弹 + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(Map.Entry entry : cardMap.entrySet()) { + + if(entry.getValue() >= 4 || ( entry.getKey() == RoomCard.CARD_A && bThreeA == true && entry.getValue() == 3)) { + + cg = new CardGroup(); + List out_list = new ArrayList<>(); + + cg.card_list = out_list; + cg.config = CardConfig.ZHA; + cg.min_card = entry.getKey(); + cg.len = 1; + + for(CardObj cardObj :cardInhand) { + + if(cardObj.cardMod == entry.getKey()) { + out_list.add(cardObj); + } + } + } + } + + return cg; + } + + + /** + * 验证牌型 + * @param ct + * @param left_count + * @return + */ + public static boolean tryType(CardGroup ct,int left_count,ITObject roomConfig) { + List cardInhand = ct.card_list; + int size = cardInhand.size(); + CardConfig config = ct.config; + if(size config.max_card_num) { + return false; + } + int len = ct.len; + if(len 0 && size == left_count) { + // 牌太少了 出牌太多了 + if(size < len*config.repeat_num || size > tem_size) { + return false; + } + // 如果带的牌不够 + if(size < tem_size) { + // 如果是三张 或者三带 + if(ct.config.type == Config.TYPE_3_2) { + if(roomConfig.getInt(Config.ROOM_CONFIG_THREE_LACK) == 0){ + return false; + } + } + // 如果是飞机 + else if(ct.config.type == Config.TYPE_FEIJI) { + if(roomConfig.getInt(Config.ROOM_CONFIG_PLANE_LACK) == 0){ + return false; + } + } + } + } + //没有带牌 没有全出 + else { + if(tem_size!=size) { + return false; + } + } + } + + int min_card = ct.min_card; + int max_card = min_card+len -1; + if(len>1&&max_card>15) { + return false; + } + + Map cardMap =CardUtil.getCardNumMap(cardInhand); + for(int i=min_card;i<=max_card;++i) { + if(!cardMap.containsKey(i)) { + return false; + } + if(cardMap.get(i) < config.repeat_num) { + return false; + } + } + return true; + } + + + + /** + * 比牌大小 + * @param banker + * @param other + * @return + */ + public final static boolean tryCompete(CardGroup banker, CardGroup other,ITObject roomConfig) { + int bankerCradType = banker.config.type; + int otherCradType = other.config.type; + + if(bankerCradType !=Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) { + return true; + } + if(bankerCradType != otherCradType) { + return false; + } + + if (bankerCradType ==Config.TYPE_ZHA&& otherCradType == Config.TYPE_ZHA) + { + if (other.card_list.size() > banker.card_list.size()) + { + return true; + } + else if (other.card_list.size() == banker.card_list.size()) + { + if(other.min_card > banker.min_card) + { + return true; + } + } + else { + return false; + } + } + + if(other.min_card > banker.min_card) { + if(otherCradType == Config.TYPE_ZHA) { + + return true; + } + else + { + + if(other.len == banker.len) { + + if(otherCradType == Config.TYPE_3_2 || otherCradType == Config.TYPE_FEIJI) { + + boolean sandaidan = roomConfig.containsKey(Config.ROOM_CONFIG_SANDAIDAN) && roomConfig.getInt(Config.ROOM_CONFIG_SANDAIDAN) == 1; + if(sandaidan) { + if(other.card_list.size() != banker.card_list.size()) { + return false; + } + } + } + + return true; + } + else + { + return false; + } + } + } + + return false; + } + + + public final static CardGroup tryBig(List cardInhand,CardGroup other) { + + List card_list = new ArrayList(); + int size = cardInhand.size(); + CardConfig config = other.config; + Map> cardMap = null; + int len = other.len; + + if(other.config.type ==Config.TYPE_ZHA) + { + if(size >= other.card_list.size()) + { + int min_card = 8;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + cardMap = CardUtil.getCardListMap(cardInhand); + for(int i=min_card;i<=15;++i) { + List list =cardMap.get(i); + if(cardMap.containsKey(i)) { + if (i <= other.min_card) + { + if (list.size() > other.card_list.size()) + { + for(int k=0;k=other.card_list.size()) + { + for(int k=0;k= len*config.repeat_num) { + + int min_card = other.min_card + 1;//最小的数字是9 加一,下一位玩家需要出的牌时从10开始 + + int max_card = min_card+len -1; //最小的数字加上上家玩家牌的长度。就是下家玩家需要出牌的张数 + + if(!(len>1&&max_card>=15)) {//长度如果大于一并且最大的牌 + + int count =0; + cardMap = CardUtil.getCardListMap(cardInhand); + int max = len>1?14:15; + for(int i=min_card;i<=max;++i) { + + List list =cardMap.get(i); + + if(cardMap.containsKey(i)&&list.size() >=config.repeat_num) { + + //不出炸牌 + if(other.config.type !=Config.TYPE_ZHA && list.size()>=4) { + count=0; + card_list.clear(); + continue; + } + + for(int k=0;k0) { + List tem_list = new ArrayList(); + tem_list.addAll(cardInhand); + CardUtil.removeCard(tem_list, card_list); + + //不把炸牌带出去 + int rcard_size = 0; + rcard: + for(int k=0;k tem_list1 = cardMap.get(card); + if(tem_list1.size()>=4) { + CardUtil.removeCard(tem_list, tem_list1); + rcard_size += 4; + break rcard; + } + } + int with_card_size = config.with_card_num * len; + if(rcard_size == 0) { + with_card_size = tem_list.size()=4) { + if(cardMap==null) { + cardMap = CardUtil.getCardListMap(cardInhand); + } + + for (Entry> entry : cardMap.entrySet()) { + int card = entry.getKey(); + List list = entry.getValue(); + if(list.size() >=4) { + CardGroup ct = new CardGroup(); + ct.config = CardConfig.ZHA; + ct.card_list = list; + ct.len = 1; + ct.min_card = card; + return ct; + } + } + } + return null; + } + + public static boolean checkStartSpring(List cardInhand) { + + boolean bRet = false; + Map cardMap =CardUtil.getCardNumMap(cardInhand); + + if(cardMap.getOrDefault(RoomCard.CARD_3, 0) == 4) { + + bRet = true; + } + else if(cardMap.getOrDefault(RoomCard.CARD_2, 0) == 1 && cardMap.getOrDefault(RoomCard.CARD_A, 0) == 3){ + + bRet = true; + } + + + return bRet; + } + + + public static void main(String[] args) { + + + + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardConfig.java b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardConfig.java new file mode 100644 index 0000000..3b70df2 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardConfig.java @@ -0,0 +1,39 @@ +package extend.pk.uitl; + +import extend.pk.Config; + +public enum CardConfig { + DAN( "单牌", Config.TYPE_DANPAI, 1, 1, 1, 1, 0), + DUIZI( "对子", Config.TYPE_DUIZI, 1, 2, 2, 2, 0), + SHUNZI( "顺子", Config.TYPE_SHUNZI, 5, 1, 5, 12, 0), + LIANDUI( "连对", Config.TYPE_LIANDUI, 2, 2, 4, 16, 0), + SAN_2( "三带二", Config.TYPE_3_2, 1, 3, 3, 5, 2), + FEIJI( "飞机", Config.TYPE_FEIJI, 2, 3, 6, 16, 2), + SI_3( "四带三", Config.TYPE_4_3, 1, 4, 5, 7, 3), + SI_2( "四带二", Config.TYPE_4_2, 1, 4, 5, 6, 2), + ZHA( "炸弹", Config.TYPE_ZHA, 1, 4, 4, 12, 0); + + public final int type; + public final String name; + public final int min_len; + public final int repeat_num; + public final int min_card_num; + public final int max_card_num; + public final int with_card_num; + + + private CardConfig(String name,int type,int min_len,int repeat_num,int min_card_num,int max_card_num,int with_card_num) { + this.name = name; + this.type = type; + + this.min_len = min_len; + this.repeat_num = repeat_num; + this.min_card_num = min_card_num; + this.max_card_num = max_card_num; + this.with_card_num = with_card_num; + } + + public String toString() { + return this.name; + } +} diff --git a/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardUtil.java b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardUtil.java new file mode 100644 index 0000000..110a118 --- /dev/null +++ b/game_pk_sanqianfen/src/main/java/extend/pk/uitl/CardUtil.java @@ -0,0 +1,384 @@ +package extend.pk.uitl; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.pk.CardObj; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CardUtil { + + + /** + * list to TArray + * + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (CardObj card : list) { + result.addInt(card.card); + } + return result; + } + + public static final CardObj getCard(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.cardMod == eventCard) { + return card; + } + } + return null; + } + + public static final CardObj getCard1(int eventCard,List cardList) { + for (CardObj card : cardList) { + if(card.card == eventCard) { + return card; + } + } + return null; + } + + /** + * 检测牌数量 + * + * @param eventCard + * @param cardList + * @param num + * @return + */ + public static final boolean checkCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result == num) + return true; + } + } + return false; + } + + public static final boolean checkGoodCard(int eventCard, List cardList, int num) { + int result = 0; + for (CardObj card : cardList) { + if (card.cardMod == eventCard) { + result++; + if (result >= num) + return true; + } + } + return false; + } + + public static final boolean checkShunZi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + } + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkSevenShunzi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard+1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard+7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-5, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-6, cardList, 1)) + { + result++; + if (checkGoodCard(eventCard-7, cardList, 1)) + { + result++; + } + } + } + } + } + } + } + + if (result >= 6) + { + return true; + } + return false; + } + + public static final boolean checkFenJi(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+1, cardList, 3)) + { + result++; + } + if (checkGoodCard(eventCard-1, cardList, 3)) + { + result++; + } + } + + if (result >= 2) + { + return true; + } + return false; + } + + public static final boolean checkFourDui(int eventCard, List cardList) { + int result = 0; + if (checkGoodCard(eventCard, cardList, 1)) + { + result++; + } + + if (checkGoodCard(eventCard+1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard+4, cardList, 2)) + { + result++; + } + } + } + } + if (checkGoodCard(eventCard-1, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-2, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-3, cardList, 2)) + { + result++; + if (checkGoodCard(eventCard-4, cardList, 2)) + { + result++; + } + } + } + } + + if (result >= 4) + { + return true; + } + return false; + } + + public static final boolean checkQPai(int eventCard, List cardList) { + int kNum = 0; + int aNum = 0; + int a2Num = 0; + if (eventCard >= 13) + { + for (CardObj card : cardList) { + if (card.cardMod == 13) { + kNum++; + } + else if (card.cardMod == 14) { + aNum++; + } + else if (card.cardMod == 15) { + a2Num++; + } + } + } + + if (kNum >= 3 || aNum >= 3 || a2Num >= 3) + { + return true; + } + return false; + } + + /** + * TArray to list + * @param list + * @return + */ + public static final List toList(ITArray list) { + List tem = new ArrayList(); + for(int i=0;i getCardNumMap(List cardList) { + Map result = new HashMap(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + return result; + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final void getCardNumMap(Map result,List cardList) { + result.clear(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + public static final void getCardNumMap(Map result,List cardList, CardObj tempCard) { + result.clear(); + result.put(tempCard.cardMod, 1); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + result.put(card.cardMod, 1); + } else { + int num = result.get(card.cardMod); + result.put(card.cardMod, (num + 1)); + } + } + } + + /** + * 获取每张牌的数量MAP + * + * @param cardList + * @return + */ + public static final Map> getCardListMap(List cardList) { + Map> result = new HashMap>(); + for (CardObj card : cardList) { + if (!result.containsKey(card.cardMod)) { + List list = new ArrayList(); + list.add(card); + result.put(card.cardMod, list); + } else { + List list = result.get(card.cardMod); + list.add(card); + } + } + return result; + } + + static public void removeCard(List cardList, List cards) { + for (int i = 0; i < cards.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).card ==cards.get(i).card) { + cardList.remove(j); + break; + } + } + } + } +} diff --git a/game_pk_sanqianfen/src/test/java/game_pk_sanqianfen/Main.java b/game_pk_sanqianfen/src/test/java/game_pk_sanqianfen/Main.java new file mode 100644 index 0000000..d54a7ed --- /dev/null +++ b/game_pk_sanqianfen/src/test/java/game_pk_sanqianfen/Main.java @@ -0,0 +1,9 @@ +package game_pk_sanqianfen; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_zp_anxiang/config/game-config.xml b/game_zp_anxiang/config/game-config.xml new file mode 100644 index 0000000..b39358c --- /dev/null +++ b/game_zp_anxiang/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.1.213 + 192.168.1.213 + 10146 + 7993 + 50 + true + \ No newline at end of file diff --git a/game_zp_anxiang/config/log4j.properties b/game_zp_anxiang/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_anxiang/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_anxiang/config/taurus-core.xml b/game_zp_anxiang/config/taurus-core.xml new file mode 100644 index 0000000..cca23f5 --- /dev/null +++ b/game_zp_anxiang/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_anxiang/config/taurus-permanent.xml b/game_zp_anxiang/config/taurus-permanent.xml new file mode 100644 index 0000000..6547939 --- /dev/null +++ b/game_zp_anxiang/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_anxiang/pom.xml b/game_zp_anxiang/pom.xml new file mode 100644 index 0000000..edb6210 --- /dev/null +++ b/game_zp_anxiang/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_anxiang + game_zp_anxiang + 1.0.0 + jar + game_zp_anxiang + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_ah_weimaque_zipai + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_anxiang/src/main/java/extend/zp/Config.java b/game_zp_anxiang/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..6364b28 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/Config.java @@ -0,0 +1,75 @@ +package extend.zp; + +public class Config { + + + public static final String ROOM_CONFIG_WANFA = "wanfa"; + + public static final String ROOM_CONFIG_ZHUANGXIAN = "zhuang"; + + public static final String ROOM_CONFIG_YIDENG = "deng"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + public static final String ROOM_CONFIG_CHUPAI = "duichupai"; + + public static final String ROOM_CONFIG_FANPAI = "fanpai"; + + + public static final String ROOM_CONFIG_LBW = "longbaiwei"; + + public static final String ROOM_CONFIG_TH = "tianhu"; + + public static final String ROOM_CONFIG_QQR = "quanqiuren"; + + public static final String ROOM_CONFIG_DD = "dingdui"; + + public static final String ROOM_CONFIG_PD = "piaodui"; + + public static final String ROOM_CONFIG_SXWQN = "wuqiannian"; + + public static final String ROOM_CONFIG_ZXS = "zhuoxiaosan"; + + public static final String ROOM_CONFIG_XLX = "xinlianxin"; + + + + 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_THROW_CARD = "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_ADDDRAW = "821"; + + + public static final String GAME_PX_DATA = "613"; + + + public static final String GAME_PLAYER_SUOPAI = "822"; + + public static final String GAME_EVT_SISHOU = "827"; + public static final String GAME_EVT_TING = "828"; +} + + + + diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXActionEvent.java b/game_zp_anxiang/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..1ec6082 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,20 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_WIN = "win"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_START_GAME ="start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXGameController.java b/game_zp_anxiang/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..0caad04 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,464 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +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.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.TingCard; + + +/** + * + * + */ +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); + } + + + @ActionKey(Config.GAME_PX_DATA) + public void RouterPXData(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.pxData = params.getTArray("card_list"); + player.getRoom().changePaiXing(player.seat, 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 showCard(EXPlayer player,int card,boolean draw,int leftCount){ + ITObject param = new TObject(); + param.putInt( "card", card); + param.putInt("seat", player.room.activeSeat); + param.putBoolean("discard", !draw); + param.putInt("left_count", leftCount); + + if(Global.loggerDebug) { + Global.logger.info(player +" draw:"+ draw + " showcard["+card+"]"); + } + player.room.broadCastToClient(0, Config.GAME_EVT_DRAW, param); + + player.getRoom().playBackData.showCardCommand(player.room.activeSeat, card,leftCount,!draw); + }*/ + + public void outCard(EXPlayer player,int discard){ + EXRoom room = player.getRoom(); + ITObject param = new TObject(); + param.putInt( "card", discard); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, param); + CardUtil.removeCard(player.cardInhand, discard, 1); + room.getPlayBack().addOutCardCommand(player.seat, discard); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + + public void addCard(EXPlayer player,int card){ + ITObject param = new TObject(); + param.putInt( "card", card); + param.putInt("seat", player.seat); + if(Global.loggerDebug) { + Global.logger.info(player + " addcard["+card+"]"); + } + player.cardInhand.add(card); + player.room.broadCastToClient(0, Config.GAME_EVT_ADDDRAW, param); + player.getRoom().getPlayBack().addCardCommand(player.seat, card); + } + + public void actionCard(EXPlayer player,int card,int type,int from_seat,ITArray opcard,int huxi, List tyScore){ + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + paramBroadCast.putInt("huxi", type == RuleWeight.TYPE_CHOW ? tyScore.get(0) : huxi); + if(opcard!=null){ + paramBroadCast.putTArray("opcard", opcard); + } + EXRoom room = player.getRoom(); + if(Global.loggerDebug) { + Global.logger.info(String.format("%s from_seat:%d card:%d type:%d", player,from_seat,card,type)); + } + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + + CardUtil.sendSuoCardEvent(player); + + + room.getPlayBack().addActionCommand(player.seat, type, card, from_seat,opcard,huxi); + ITObject param = new TObject(); + Utils.objectCopy(paramBroadCast, param); + param.putInt("card", type == RuleWeight.TYPE_WEI ? 0 : card); + param.putInt("huxi", type == RuleWeight.TYPE_WEI ? 0 : (type == RuleWeight.TYPE_CHOW ? tyScore.get(1) : huxi)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, param); + } + + public void dealCard(EXRoom owner) { + if(owner.maxPlayers == 2 && owner.config.containsKey(Config.ROOM_CONFIG_QUPAI) + && owner.config.getBoolean(Config.ROOM_CONFIG_QUPAI)) { + for(int num = 0; num < 19; num++) { + owner.throwList.addInt(owner.card.pop()); + } + } + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer)entry.getValue(); + player.cardInhand = owner.card.deal(19); + /*if(player.seat == 1) { + player.cardInhand = owner.card.dealFake1(); + } else if(player.seat == 2) { + player.cardInhand = owner.card.dealFake2(); + } else if(player.seat == 3) { + player.cardInhand = owner.card.dealFake3(); + }*/ + + if(Global.loggerDebug) { + Global.logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + player.cardInhand); + } + } +// owner.card.cardList = owner.card.dealFake(); + if(Global.loggerDebug) + Global.logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + for (Entry 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)); + if (player.seat != owner.bankerSeat) CardUtil.sendSuoCardEvent(player); + } + } + + public void getCard(EXPlayer player, int leftCount) { + ITObject param = new TObject(); + param.putInt("card", player.getRoom().showCard); + param.putInt("seat", player.room.activeSeat); + param.putInt("left_count", leftCount); + player.room.broadCastToClient(0, Config.GAME_EVT_DRAW, param); + player.getRoom().getPlayBack().addGetCardCommand(player.room.activeSeat, player.getRoom().showCard, leftCount); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + ITObject param = new TObject(); + if (owner.tingMap.size() > 0) { + ITArray infoList = new TArray(); + for (Entry> entry : owner.tingMap.entrySet()) { + ITObject obj = TObject.newInstance(); + obj.putInt("card", entry.getKey()); + obj.putTArray("ting_list", Util.toTArray(entry.getValue()));; + infoList.addTObject(obj); + } + param.putTArray("ting", infoList); + } + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, param); + } + + public void qiShouTing(EXPlayer owner) { + owner.resetHuXi(); + List currentOpCardList = new ArrayList(); + List cardList = new ArrayList<>(owner.cardInhand); + List myAngleCard = new ArrayList<>(); + myAngleCard.addAll(owner.cardInhand); + Set roomCardSet = new HashSet<>(); + for (int index = 1; index <= 10; index++) { + roomCardSet.add(100 + index); + roomCardSet.add(200 + index); + } + owner.tingList.clear(); + for (Integer tingCard : roomCardSet) { + TingCard ting = new TingCard(cardList, tingCard, owner.AEhuXi, true, + currentOpCardList, owner.getRoom().config.getInt(Config.ROOM_CONFIG_WANFA)); + try { + if (ting.checkHu()) { + if (!Util.checkCard(tingCard, myAngleCard, 4)) { + owner.tingList.add(tingCard); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + owner.resetHuXi(); + if (owner.tingList.size() > 0) { + ITObject param = new TObject(); + param.putTArray("tinglist", Util.toTArray(owner.tingList)); + owner.sendEvent(Config.GAME_EVT_TING, param); + } + } + public void ting(EXPlayer owner) { + owner.resetHuXi(); + List currentOpCardList = new ArrayList(); + Set cardSet = new HashSet<>(owner.cardInhand); + List removeList = new ArrayList<>(); + List myAngleCard = new ArrayList<>(); + myAngleCard.addAll(owner.cardInhand); + for (Entry entry : owner.getRoom().playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + for (OpCard opCard : player.opCardList) { + if ((opCard.type == RuleWeight.TYPE_WEI && owner.seat == entry.getKey()) || + !(opCard.type == RuleWeight.TYPE_WEI)) { + myAngleCard.add(opCard.card1); + myAngleCard.add(opCard.card2); + myAngleCard.add(opCard.card3); + } + } + myAngleCard.addAll(player.outcardList); + } + for (Integer card : cardSet) { + if (Util.cardNum(card, owner.cardInhand) == 3 || owner.suoCardList.contains(card)) + removeList.add(card); + } + cardSet.removeAll(removeList); + Set roomCardSet = new HashSet<>(); + for (int index = 1; index <= 10; index++) { + roomCardSet.add(100 + index); + roomCardSet.add(200 + index); + } + Map> tMap = new HashMap>(); + for (Integer card : cardSet) { + List cardList = new ArrayList<>(owner.cardInhand); + cardList.remove(card); + for (Integer tingCard : roomCardSet) { + currentOpCardList.clear(); + for (OpCard opCard : owner.opCardList) { + currentOpCardList.add(new OpCard(opCard.type, opCard.card1, opCard.card2, opCard.card3, opCard.huXi)); + } + TingCard ting = new TingCard(cardList, tingCard, owner.AEhuXi, true, + currentOpCardList, owner.getRoom().config.getInt(Config.ROOM_CONFIG_WANFA)); + try { + if (ting.checkHu()) { + if (!Util.checkCard(tingCard, myAngleCard, 4)) { + if (tMap.containsKey(card)) { + tMap.get(card).add(tingCard); + }else { + List list = new ArrayList<>(); + list.add(tingCard); + tMap.put(card, list); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + owner.resetHuXi(); + if (tMap.size() > 0) { + owner.tingMap.clear(); + owner.tingMap.putAll(tMap); + } + } + + 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); + param.putInt("hutype", owner.hutype); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + private ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + mp.putTArray("left_cards", Util.toTArray(owner.card.cardList)); + if(owner.maxPlayers == 2) { + mp.putTArray("throw_list", owner.throwList); + } + if (owner.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) { + mp.putInt("score_pool", owner.douLiuZi); + } + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.allHuXi); + param.putInt("ying_xi", player.huXi); + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + if (owner.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) { + param.putInt("douliszi_score", player.score.round_log.get(EXScore.DOULIUZISCORE) == null ? 0 : + player.score.round_log.get(EXScore.DOULIUZISCORE)); + } + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.winMtList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.type); + obj.putInt("type", mingTang.v_type); + obj.putInt("score", mingTang.value); + + mtList.addTObject(obj); + } + param.putTArray("mt_list", mtList); + if (player.winer == 1) { + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("huxi", opCard.huXi); + ITArray op = TArray.newInstance(); + if(opCard.card1 > 0) op.addInt(opCard.card1); + if(opCard.card2 > 0) op.addInt(opCard.card2); + if(opCard.card3 > 0) op.addInt(opCard.card3); + obj.putTArray("opcard", op); + cardList.addTObject(obj); + } + for (OpCard opCard : player.currentOpCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("huxi", opCard.huXi); + ITArray op = TArray.newInstance(); + if(opCard.card1 > 0) op.addInt(opCard.card1); + if(opCard.card2 > 0) op.addInt(opCard.card2); + if(opCard.card3 > 0) op.addInt(opCard.card3); + obj.putTArray("opcard", op); + cardList.addTObject(obj); + } + param.putTArray("win_card_list", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + ITArray opCardList = TArray.newInstance(); + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("huxi", opCard.huXi); + obj.putInt("card", opCard.card1); + ITArray op = TArray.newInstance(); + op.addInt(opCard.card2); + if(opCard.card3 > 0) op.addInt(opCard.card3); + obj.putTArray("opcard", op); + opCardList.addTObject(obj); + } + param.putTArray("opcard_list", opCardList); + } + player.hp_info(param); + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + owner.getPlayBack().addResultCommand(result); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + + public void roomTotalResult(EXRoom owner,boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + int douLiuZiScore = 0; + if (owner.douLiuZi > 0) { + douLiuZiScore = owner.douLiuZi / owner.maxPlayers; + } + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (owner.douLiuZi > 0) { + owner.addDouLiuZiScore(player,player.seat == 1 ? -douLiuZiScore - + (owner.douLiuZi - douLiuZiScore*owner.maxPlayers) : -douLiuZiScore, EXScore.DOULIUZISCORE); + } + 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); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss?2:1); + if(!dissmiss) { + ITObject result = getRoomResultData(owner); + owner.getPlayBack().addResultCommand(result); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXMainServer.java b/game_zp_anxiang/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..27e93b7 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,88 @@ +package extend.zp; + +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.zp.player.rulestate.PRChowState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerPreDrawState; +import extend.zp.player.state.EXPlayerWaitState; +import extend.zp.player.state.EXPlayerWeiState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.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(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + 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(EXPlayerWeiState.class, new EXPlayerWeiState()); + + Global.registerState(PRChowState.class, new PRChowState()); + Global.registerState(PRWinState.class, new PRWinState()); + Global.registerState(PRPongState.class, new PRPongState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXPlayer.java b/game_zp_anxiang/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..ef49004 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,253 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Stack; + +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.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; + +/** + * + * + */ +public class EXPlayer extends Player { + + public List cardInhand; + + + public List outcardList; + public Set suoCardList; + + public Tip actionTip; + + + public List opCardList; + public List currentOpCardList; + public Stack handCard; + public int actionCard = 0; + public int winCard = 0; + public int winHuxi = 0; + public int huXi = 0; + public int AEhuXi = 0; + public int allHuXi = 0; + public List winMtList; + public TipManager tipMgr; + + public SettleLog settleLog; + public boolean draw = false; + public ITArray pxData =null; + + public Set chouList; + public boolean daPai; + public boolean fangpao; + public boolean isZiMo; + public boolean siShou; + + public int hutype; + + public int winType = 0; + public List specialList; + public boolean kaWei = false; + public Map> tingMap; + public List tingList; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + + opCardList = new ArrayList<>(); + currentOpCardList = new ArrayList<>(); + + tipMgr = new TipManager(this); + specialList = new ArrayList<>(); + settleLog = new SettleLog(); + handCard = new Stack(); + winMtList = new ArrayList<>(); + tingList = new ArrayList<>(); + tingMap = new HashMap>(); +// settleLog.put(Config.SETTLE_DA_DIAN_PAO, 0); +// settleLog.put(Config.SETTLE_DA_JIE_PAO, 0); +// settleLog.put(Config.SETTLE_DA_ZIMO, 0); + + this.chouList = new HashSet(); + this.suoCardList = new HashSet(); + } + + protected Score newScore() { + return new EXScore(this); + } + + public void paiZu() { + List bigCharacterList = new ArrayList<>(); + List smallCharacterList = new ArrayList<>(); + this.handCard.clear(); + for (Integer card : this.cardInhand) { + if (card / 100 == 2) { + bigCharacterList.add(card); + }else { + smallCharacterList.add(card); + } + } + zuHe(bigCharacterList); + zuHe(smallCharacterList); + } + + + public Integer autoDiscard() { + Map cardNum = CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue() == 1 || card.getValue() == 2) { + return card.getKey(); + } + } + return 0; + } + + public void zuHe(List cardList) { + Collections.sort(cardList); + for (Entry entry : Util.getCardNumMap(cardList).entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 3) { + Util.removeCard(cardList, card, 3); + OpCard opCard = new OpCard(RuleWeight.TYPE_KAN, card, card, card, 0); + this.handCard.push(opCard); + } + } + List tempList = new ArrayList<>(cardList); + while (true) { + if (tempList.size() < 3) break; + int card = tempList.get(0); + if (Util.checkCard(card + 1, tempList) && Util.checkCard(card + 2, tempList)) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card+1, card+2, 0); + this.handCard.push(opCard); + Util.removeCard(tempList, card, 1); + Util.removeCard(tempList, card + 1, 1); + Util.removeCard(tempList, card + 2, 1); + Util.removeCard(cardList, card, 1); + Util.removeCard(cardList, card + 1, 1); + Util.removeCard(cardList, card + 2, 1); + }else { + tempList.remove(0); + } + } + + for (Entry entry : Util.getCardNumMap(cardList).entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num == 2) { + Util.removeCard(cardList, card, 2); + OpCard opCard = new OpCard(RuleWeight.TYPE_JIANG, card, card, 0, 0); + this.handCard.push(opCard); + } + } + while (true) { + if (cardList.size() >= 3) { + int card1 = cardList.get(0), card2 = cardList.get(1), card3 = cardList.get(2); + OpCard opCard = new OpCard(RuleWeight.TYPE_SAN, card1, card2, card3, 0); + this.handCard.push(opCard); + Util.removeCard(cardList, card1, 1); + Util.removeCard(cardList, card2, 1); + Util.removeCard(cardList, card3, 1); + }else if (cardList.size() >= 0 && cardList.size() < 3) { + int card1 = 0, card2 = 0; + if (cardList.size() == 1) { + card1 = cardList.get(0); + }else if (cardList.size() == 2){ + card1 = cardList.get(0); + card2 = cardList.get(1); + } + if (card1 > 0) { + OpCard opCard = new OpCard(RuleWeight.TYPE_SAN, card1, card2, 0, 0); + this.handCard.push(opCard); + } + break; + } + } + } + + public ITObject getReloadInfo(boolean self) { + 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("sishou", this.siShou); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("huxi", opcard.type == RuleWeight.TYPE_WEI && !self ? 0 : opcard.huXi); + opcardParam.putInt("card", opcard.card1); + ITArray op = TArray.newInstance(); + op.addInt(opcard.card2); + if(opcard.card3 > 0) op.addInt(opcard.card3); + opcardParam.putTArray("opcard", op); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + + return playerData; + } + + public void resetHuXi() { + this.AEhuXi = 0; + for (OpCard opCard : this.opCardList) { + this.AEhuXi += opCard.huXi; + } + } + + public void clear() { + super.clear(); + this.cardInhand.clear(); + this.draw = false; + this.outcardList.clear(); + this.opCardList.clear(); + this.currentOpCardList.clear(); + this.pxData = null; + this.winCard = 0; + this.huXi = 0; + this.winHuxi = 0; + this.actionCard = 0; + this.score.resetRound(); + this.chouList.clear(); + this.suoCardList.clear(); + this.daPai = false; + this.fangpao = false; + this.hutype = 0; + this.AEhuXi = 0; + this.isZiMo = false; + this.kaWei = false; + this.winType = 0; + this.winMtList.clear(); + this.specialList.clear(); + this.tingMap.clear(); + this.tingList.clear(); + this.siShou = false; + } + + + public EXRoom getRoom() { + return (EXRoom) room; + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXRoom.java b/game_zp_anxiang/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..4eb5620 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1470 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +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.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; + +public class EXRoom extends Room { + + // + public Map tipMap; + public Action curAction; + + public List actionList; + public RoomCard card; + + public int showCard; + public int currenDiscardSeat; + public boolean liuju = false; + + + public boolean tianHu = true; + public ITArray throwList; + public int lastPaoSeat; + public int draw = -1; + public boolean isAllPass = false; + public int douLiuZi = 0; + + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.actionList = new ArrayList(); + this.tipMap = new HashMap(); + this.throwList = TArray.newInstance(); + this.isEntrust=true; + } + + + /*public void addAction(Action action) { + if (this.curAction ==null) { + this.curAction = action; + } else if (action.tip.weight > this.curAction.tip.weight) { + this.curAction = action; + } else if (action.tip.weight == this.curAction.tip.weight) { + int pos = Util.getPos(this.activeSeat, action.player.seat,this.maxPlayers); + int pos1 = Util.getPos(this.activeSeat, this.curAction.player.seat, this.maxPlayers); + if (pos < pos1) { + this.curAction = action; + } + } + + checkAction(); + }*/ + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void changePaiXing(int seat, ITObject params) { + ITArray paixing = params.getTArray("card_list"); + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", seat, cmdData); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + EXPlayer activePlayer = (EXPlayer)this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = this.getReloadInfoEx(player); + EXPlayer p = (EXPlayer) player; + + if(p.pxData !=null) { + data.putTArray("hand_px_data", p.pxData); + } + data.putInt("show_card", this.showCard); + data.putTArray("hand_card", Util.toTArray(p.cardInhand)); + data.putInt("left_card", card.getCount()); + data.putInt("score_pool", this.douLiuZi); + + ITArray paramArray = TArray.newInstance(); + for (int chiCard : p.suoCardList) { + paramArray.addInt(chiCard); + } + data.putTArray("suoCard", paramArray); + data.putTArray("tinglist", Util.toTArray(p.tingList)); + if (p.tingMap.size() > 0) { + ITArray infoList = new TArray(); + for (Entry> entry : p.tingMap.entrySet()) { + ITObject obj = TObject.newInstance(); + obj.putInt("card", entry.getKey()); + obj.putTArray("ting_list", Util.toTArray(entry.getValue()));; + infoList.addTObject(obj); + } + data.putTArray("ting", infoList); + } + data.putInt("curren_outcard_seat", currenDiscardSeat); + + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + for (Entry entry : this.playerMapBySeat.entrySet()) { + info_list.addTObject(((EXPlayer)entry.getValue()).getReloadInfo(entry.getValue().seat == player.seat ? true : false)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + 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 addDouLiuZiScore(EXPlayer destPlayer, int score, int type) { + destPlayer.score.round_log.put(type, (destPlayer.score.round_log.get(type) == null + ? 0 : destPlayer.score.round_log.get(type)) - score); + + destPlayer.score.round_score -= score; + destPlayer.score.total_score -= score; + this.douLiuZi += score; + } + + public void addAllScore(EXPlayer destPlayer, int socre, int type) { + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + this.addScore(destPlayer, fromPlayer, socre, type); + } + } + + private boolean checkBian3(List opCardList, int winCard) { + for (OpCard opCard : opCardList) { + if (opCard.type != RuleWeight.TYPE_CHOW) continue; + List list = new ArrayList(); + list.add(opCard.card1); + list.add(opCard.card2); + list.add(opCard.card3); + if ((winCard % 100 == 3 && Collections.max(list) == winCard) + || (winCard % 100 == 8 && Collections.min(list) == winCard)) { + return true; + }else { + if (Collections.min(list) + 1 == winCard) return true; + } + } + return false; + } + + public int caclSpecialScore(EXPlayer owner) { + int huXi = 0; + int wanFa = owner.getRoom().config.getInt(Config.ROOM_CONFIG_WANFA); + for(int i = 0; i < owner.specialList.size(); i++) { + if (owner.specialList.get(i) == 1) { + int xi = wanFa == 3 ? (i == 6 ? 150 : 100) : (i == 6 ? 200 : 150); + huXi += xi; + owner.winMtList.add(new MingTang(50+(i > 5 ? i + 1 : i), MingTang.ST_HUXI, xi)); + } + } + owner.winHuxi += huXi; + if (owner.winType == 1) owner.paiZu(); + return huXi; + } + + + public int caclWin(EXPlayer owner,boolean zimo) { + owner.winMtList.clear(); + int wanfa = owner.room.config.getInt(Config.ROOM_CONFIG_WANFA); + int huxi = 0; + boolean duizi = true, duiDaoHu = false, dandiao = false, haveXi = true, bianKan = false + , geShanDaNiu = false; + int shouXi = 0, zhuoXi = 0, hong_num = 0; + for(OpCard opc : owner.opCardList) { + zhuoXi += opc.huXi; + switch(opc.type) { + /*case RuleWeight.TYPE_PONG: + case RuleWeight.TYPE_WEI: + break;*/ + case RuleWeight.TYPE_CHOW: + duizi = false; + break; + } + if(opc.huXi <= 0) haveXi = false; + if(CardUtil.checkHongCard(opc.card1))hong_num++; + if(CardUtil.checkHongCard(opc.card2))hong_num++; + if(CardUtil.checkHongCard(opc.card3))hong_num++; + } + int jiangCard = 0; + for(OpCard cg : owner.handCard) { + Set set = new HashSet(); + set.add(cg.card1); + set.add(cg.card2); + if (cg.card3 > 0) set.add(cg.card3); + if (RuleWeight.TYPE_JIANG == cg.type) jiangCard = cg.card1; + if(set.size() > 1) + duizi = false; + if(RuleWeight.TYPE_JIANG == cg.type && cg.card1 == owner.winCard) + dandiao = true; + if(cg.huXi <= 0) haveXi = false; + shouXi += cg.huXi; + if (RuleWeight.TYPE_CHOW == cg.type) duizi = false; + if (RuleWeight.TYPE_PONG == cg.type && set.contains(owner.winCard) || owner.kaWei) duiDaoHu = true;// ���ȵ����ͶԶԵ������ڱ߿��� + if(CardUtil.checkHongCard(cg.card1))hong_num++; + if(CardUtil.checkHongCard(cg.card2))hong_num++; + if(cg.card3 > 0 && CardUtil.checkHongCard(cg.card3))hong_num++; + } + boolean piaodui = false; + if (duizi && hong_num == 3 && CardUtil.checkPiaoDui(owner.opCardList, owner.handCard)) + piaodui = true; + if (duiDaoHu && Math.abs(jiangCard - owner.winCard) == 2) geShanDaNiu = true; + int contains123 = 0; + if (!duizi && !duiDaoHu && !dandiao) { + bianKan = checkBian3(owner.handCard, owner.winCard); + } + int beishu = 0, jiaxi = 0; + Global.logger.info("list card"); + Global.logger.info(owner.opCardList); + Global.logger.info(owner.handCard); + Set tuanYuanSet = CardUtil.checkTuanYuan(owner.opCardList, owner.handCard); + Global.logger.info(tuanYuanSet); + List yinList = new ArrayList(); + for(int ty : tuanYuanSet) { + if(CardUtil.checkHongCard(ty)) + yinList.add(ty); + } + if (owner.huXi == 2) { + int hxi = wanfa == 3 ? 150 : 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_ERXIMANHUAYUAN, MingTang.ST_HUXI, wanfa == 3 ? 150 : 200));// ��Ϣ��԰�� + if (wanfa == 3) { + if(zimo) { + hxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 20)); + } + if(bianKan) { + hxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 20)); + } + if(dandiao) { + if(duizi) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + hxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,20)); + } + } + if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { // ׽С�� + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 30)); + } + + if (this.config.getBoolean(Config.ROOM_CONFIG_XLX) && CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + hxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 20)); + } + }else if (wanfa == 2) { + if(zimo) { + hxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40)); + } + if(bianKan) { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 30)); + } + if(dandiao) { + if(duizi) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) {// ȫ���� + hxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { // ׽С�� + hxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + if(this.card.getCount() == 0) { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,30)); + } + + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + }else if (wanfa == 1) { + if(zimo) { + hxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40)); + } + if(bianKan) { + hxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40)); + } + if(dandiao) { + if(duizi) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + if(zimo && owner.winCard == 103) { + hxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + if(this.card.getCount() == 0) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50)); + } + if(owner.cardInhand.size() == 1) { + hxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + }else if (wanfa == 4) { + if(zimo) { + hxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40)); + } + if(bianKan) { + hxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40)); + } + if(dandiao) { + if(duizi) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + if(this.card.getCount() == 0) { + hxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50)); + } + + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + hxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + if(owner.cardInhand.size() == 1) { + hxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + if(zimo && owner.winCard == 103) { + hxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + } + owner.winHuxi = hxi; + return hxi; + } + if(wanfa == 0) { + if(yinList.size() >= 1) { + int xi = (yinList.size() * 10); + owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + } + if(hong_num >= 10) { + int xi = (hong_num - 9) * 10; + if(xi > 10) { + owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi)); + } else { + owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi)); + } + jiaxi += xi; + } + if(hong_num <= 0) { + if(duizi) { + beishu += 6; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 6)); + }else { + + beishu += 4; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 4)); + } + } + if(hong_num > 0 && duizi) { + beishu += 4; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 4)); + } + if(hong_num == 1) { + beishu += 3; + owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 3)); + } + boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard); + if(huayuan) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,50)); + } + int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard); + if(se > 0) { + jiaxi += 50; + owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,50)); + } + huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi; + /*===========================================================================================================*/ + } else if(wanfa == 1) { + if(hong_num > 0 && duizi) { + beishu += 10; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10)); + } + if(hong_num <= 0) { + if(duizi) { + beishu += 15; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15)); + }else { + + beishu += 6; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 6)); + } + } + + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + if(hong_num == 1) { + beishu += 4; + owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 4)); + } + if(yinList.size() >= 1) { + if(hong_num == yinList.size() * 4) { + int xi = (yinList.size() * 150); + owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + }// else { + int xi = (yinList.size() * 30); + owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + //} + } + if(hong_num >= 10) { + int xi = (hong_num - 9) * 30; + if(xi > 30) { + owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi)); + } else { + owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi)); + } + jiaxi += xi; + } + boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard); + if(huayuan) { + //按需求150改成120 05-20 mt + jiaxi += 120; + owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,120)); + } + int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard); + if(se > 0) { + //按需求200改成150 05-20 mt + jiaxi += 150; + owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150)); + } + if(zimo) { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40)); + } + if (duiDaoHu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20)); + } + if (geShanDaNiu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20)); + } + if(zimo && owner.winCard == 103) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + + if(tuanYuanSet.size() >= 2) { + boolean result1 = false; + boolean result2 = false; + boolean result3 = false; + boolean result4 = false; + for(int ty : tuanYuanSet) { + if(ty % 100 == 10) { + if(tuanYuanSet.contains(ty - 9)) + result1 = true; + } else { + if(tuanYuanSet.contains(ty +1)) + result2 = true; + } + if(ty % 100 <= 8) { + if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2)) + result3 = true; + } + int type = ty / 100; + if(type == 1 && tuanYuanSet.contains(ty + 100)) { + result4 = true; + } + if(type == 2 && tuanYuanSet.contains(ty - 100)) { + result4 = true; + } + } + if(tuanYuanSet.size() == 2) { + if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { // �����ͷ + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300)); + }else if (result4) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150)); + }else if (result1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + }else if (result2) { + jiaxi += 80; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80)); + }//else { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,40)); + //} + } else if(tuanYuanSet.size() > 2) { + if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { // �����ͷ + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300)); + } + if (result4) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150)); + } + if (result1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + } + if (result3) { + if(tuanYuanSet.size() == 4) { + jiaxi += 400; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400)); + }else { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300)); + } + } + if (result2 &&!result3) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,150)); + } + if (tuanYuanSet.size() == 3 && !result3 && !result2) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,100)); + }else if (tuanYuanSet.size() == 4) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300)); + } + } + } + if(this.card.getCount() == 0) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50)); + } + if(dandiao) { + if(duizi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + int specialDuiDaoHu = 0 ; + if(duiDaoHu) { + specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard); + if(specialDuiDaoHu == 1) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50)); + }else if (specialDuiDaoHu == 2) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50)); + } + } + if(haveXi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50)); + } + if(owner.cardInhand.size() == 1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + if(owner.huXi == 10 && owner.kaWei) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50)); + } + if(this.tianHu &&owner.seat == this.bankerSeat) { + //按需求150改100 05-20 mt + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 100)); + } + if(piaodui) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50)); + } + + if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100)); + } + if(shouXi == zhuoXi && zhuoXi ==5) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50)); + } + if(bianKan) { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40)); + } + if(specialDuiDaoHu == 3) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBEIKAOBEI, MingTang.ST_HUXI, 100)); + } + if(specialDuiDaoHu == 4) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_FENGPAIWEI, MingTang.ST_HUXI, 50)); + } + if(owner.huXi == 10) { + //按需求50改30 05-20 mt + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 30)); + } + huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi; + /*===========================================================================================================*/ + } else if(wanfa == 2) { + Global.logger.info("yinhu :"+yinList.size()); + if(yinList.size() >= 1) { + if(hong_num == yinList.size() * 4) { + int xi = (yinList.size() * 150); + owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + } //else { + int xi = (yinList.size() * 30); + owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + //} + } + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + if(bianKan) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 30)); + } + if (geShanDaNiu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20)); + } + if (duiDaoHu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20)); + } + if(owner.huXi == 10) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 30)); + } + if(zimo) { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40)); + } + if(hong_num >= 10) { + //按需求20改30,05-20 mt + int xi = (hong_num - 9) * 30; + if(xi > 30) { + owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi)); + } else { + owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi)); + } + jiaxi += xi; + } + if(hong_num > 0 && duizi) { + //按需求8改10,05-20 mt + beishu += 10; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10)); + } + if(hong_num <= 0) { + if(duizi) { + //按需求10改15,05-20 mt + beishu += 15; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15)); + } else { + beishu += 6; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 6)); + } + } + if(hong_num == 1) { + beishu += 4; + owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 4)); + } + boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard); + if(huayuan) { + //按需求200改120,05-20 mt 此处本来是150 + jiaxi += 120; + owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,120)); + } + int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard); + if(se > 0) { + //按需求200改150,05-20 mt + jiaxi += 150; + owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150)); + } + if(tuanYuanSet.size() >= 2) { + boolean result1 = false; + boolean result2 = false; + boolean result3 = false; + boolean result4 = false; + for(int ty : tuanYuanSet) { + if(ty % 100 == 10) { + if(tuanYuanSet.contains(ty - 9)) + result1 = true; + } else { + if(tuanYuanSet.contains(ty +1)) + result2 = true; + } + if(ty % 100 <= 8) { + if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2)) + result3 = true; + } + int type = ty / 100; + if(type == 1 && tuanYuanSet.contains(ty + 100)) { + result4 = true; + } + if(type == 2 && tuanYuanSet.contains(ty - 100)) { + result4 = true; + } + } + if(tuanYuanSet.size() == 2) { + if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300)); + }else if (result4) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150)); + }else if (this.config.getBoolean(Config.ROOM_CONFIG_LBW) && result1) {// ����β + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + }else if (result2) { + jiaxi += 80; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80)); + }//else { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,40)); + //} + } else if(tuanYuanSet.size() > 2) { + if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300)); + } + if (result4) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150)); + } + if (result1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + } + if (result3) { + if(tuanYuanSet.size() == 4) { + jiaxi += 400; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400)); + }else { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300)); + } + } + if (result2 && !result3) { + //按需求120改成150 05-20 mt + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,150)); + } + if (tuanYuanSet.size() == 3 && !result3 && !result2) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,100)); + }else if (tuanYuanSet.size() == 4) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300)); + } + } + } + if(this.card.getCount() == 0) { + //按需求30改成50 05-20 mt + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50)); + } + if(dandiao) { + if(duizi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + if(duiDaoHu) { + int specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard); + if(specialDuiDaoHu == 1 || specialDuiDaoHu == 3) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50)); + }else if (specialDuiDaoHu == 2) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50)); + } + } + if(this.config.getBoolean(Config.ROOM_CONFIG_DD) && haveXi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + if(owner.huXi == 10 && owner.kaWei) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_TH) && this.tianHu && owner.seat == this.bankerSeat) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 100)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_PD) && piaodui) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50)); + } + + if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_SXWQN) && shouXi == zhuoXi && zhuoXi ==5) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50)); + } + huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi; + /*===========================================================================================================*/ + } else if(wanfa == 3) { + if(yinList.size() >= 1) { + if(hong_num == yinList.size() * 4) { + int xi = (yinList.size() * 100); + owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + }// else { + int xi = (yinList.size() * 20); + owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + //} + } + if(bianKan) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 20)); + } + if (geShanDaNiu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20)); + } + if (duiDaoHu) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20)); + } + if(owner.huXi == 10) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 20)); + } + if(zimo) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 20)); + } + + if (this.config.getBoolean(Config.ROOM_CONFIG_XLX) && CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 20)); + } + if(hong_num >= 10) { + int xi = (hong_num - 9) * 20; + if(xi > 10) { + owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi)); + } else { + owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi)); + } + jiaxi += xi; + } + if(hong_num > 0 && duizi) { + beishu += 6; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 6)); + } + if(hong_num <= 0) { + if(duizi) { + beishu += 8; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 8)); + } else { + beishu += 4; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 4)); + } + } + if(hong_num == 1) { + beishu += 3; + owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 3)); + } + boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard); + if(huayuan) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,100)); + } + int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard); + if(se > 0) { + jiaxi += 100; + owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,100)); + } + if(tuanYuanSet.size() >= 2) { + boolean result1 = false; + boolean result2 = false; + boolean result3 = false; + boolean result4 = false; + for(int ty : tuanYuanSet) { + if(ty % 100 == 10) { + if(tuanYuanSet.contains(ty - 9)) + result1 = true; + } else { + if(tuanYuanSet.contains(ty +1)) + result2 = true; + } + if(ty % 100 <= 8) { + if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2)) + result3 = true; + } + int type = ty / 100; + if(type == 1 && tuanYuanSet.contains(ty + 100)) { + result4 = true; + } + if(type == 2 && tuanYuanSet.contains(ty - 100)) { + result4 = true; + } + } + if(tuanYuanSet.size() == 2) { + if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + jiaxi += 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,200)); + }else if (result4) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,100)); + }else if (this.config.getBoolean(Config.ROOM_CONFIG_LBW) && result1) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,100)); + }else if (result2) { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,40)); + }//else { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,20)); + //} + } else if(tuanYuanSet.size() > 2) { + if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + jiaxi += 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,200)); + } + if (result4) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,100)); + } + if (result1) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,100)); + } + if (result3) { + if(tuanYuanSet.size() == 4) { + //按需求,200改成300 05-20 mt + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,300)); + }else { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,150)); + } + } + if (result2 && !result3) { + jiaxi += 80; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,80)); + } + if (tuanYuanSet.size() == 3 && !result3 && !result2) { + jiaxi += 60; + owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,60)); + }else if (tuanYuanSet.size() == 4 && !result3) { + //按需求,100改成200 05-20 mt + jiaxi += 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,200)); + } + } + } + if(this.card.getCount() == 0) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,20)); + } + if(dandiao) { + if(duizi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,20)); + } + } + if(duiDaoHu) { + int specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard); + if(specialDuiDaoHu == 1 || specialDuiDaoHu == 3) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,20)); + }else if (specialDuiDaoHu == 2) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,20)); + } + } + if(this.config.getBoolean(Config.ROOM_CONFIG_DD) && haveXi) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,20)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,100)); + } + if(owner.huXi == 10 && owner.kaWei) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_TH) && this.tianHu && owner.seat == this.bankerSeat) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 50)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_PD) && piaodui) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 20)); + } + + if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 50)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_SXWQN) && shouXi == zhuoXi && zhuoXi ==5) { + jiaxi += 20; + owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 20)); + } + if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 30)); + } + huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi; + /*===========================================================================================================*/ + } else if(wanfa == 4) { + if(hong_num > 0 && duizi) { + beishu += 10; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10)); + } + if(hong_num <= 0) { + if(duizi) { + beishu += 15; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15)); + } else { + //按需求6改8 05-20 mt + beishu += 8; + owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 8)); + } + } + if(hong_num == 1) { + //按需求4改6 05-20 mt + beishu += 6; + owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 6)); + } + if(yinList.size() >= 1) { + if(hong_num == yinList.size() * 4) { + int xi = (yinList.size() * 150); + owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + }// else { + int xi = (yinList.size() * 30); + owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi)); + jiaxi += xi; + //} + } + if(hong_num >= 10) { + int xi = (hong_num - 9) * 30; + if(xi > 30) { + owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi)); + } else { + owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi)); + } + jiaxi += xi; + } + boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard); + if(huayuan) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,150)); + } + int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard); + if(se > 0) { + //按需求200改150 05-20 mt + jiaxi += 150; + owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150)); + } + if(tuanYuanSet.size() >= 2) { + boolean result1 = false; + boolean result2 = false; + boolean result3 = false; + boolean result4 = false; + for(int ty : tuanYuanSet) { + if(ty % 100 == 10) { + if(tuanYuanSet.contains(ty - 9)) + result1 = true; + } else { + if(tuanYuanSet.contains(ty +1)) + result2 = true; + } + if(ty % 100 <= 8) { + if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2)) + result3 = true; + } + int type = ty / 100; + if(type == 1 && tuanYuanSet.contains(ty + 100)) { + result4 = true; + } + if(type == 2 && tuanYuanSet.contains(ty - 100)) { + result4 = true; + } + } + if(tuanYuanSet.size() == 2) { + if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300)); + }else if (result4) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150)); + }else if (result1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + }else if (result2) { + jiaxi += 80; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80)); + }//else { + //按需求40改50 05-20 mt + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,50)); + //} + } else if(tuanYuanSet.size() > 2) { + if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { + //按需求300改400 05-20 mt + jiaxi += 400; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,400)); + } + if (result4) { + //按需求150改200 05-20 mt + jiaxi += 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,200)); + } + if (result1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150)); + } + if (result3) { + if(tuanYuanSet.size() == 4) { + jiaxi += 400; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400)); + }else { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300)); + } + } + if (result2 &&!result3) { + //按需求150改200 05-20 mt + jiaxi += 200; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,200)); + } + if (tuanYuanSet.size() == 3 && !result3 && !result2) { + //按需求100改150 05-20 mt jefe + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,150)); + }else if (tuanYuanSet.size() == 4) { + jiaxi += 300; + owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300)); + } + } + } + if(this.card.getCount() == 0) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50)); + } + if(dandiao) { + if(duizi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50)); + } else { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30)); + } + } + int specialDuiDaoHu = 0; + if(duiDaoHu) { + specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard); + if(specialDuiDaoHu == 1) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50)); + }else if (specialDuiDaoHu == 2) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50)); + } + } + if(haveXi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50)); + } + if(owner.cardInhand.size() == 1) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150)); + } + if(owner.huXi == 10 && owner.kaWei) { + //按需求50改100 05-20 mt + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,100)); + } + if(this.tianHu && owner.seat == this.bankerSeat) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 150)); + } + if(piaodui) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50)); + } + if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100)); + } + if(shouXi == zhuoXi && zhuoXi ==5) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50)); + } + /**=========================================================================================*/ + if(bianKan) { + jiaxi += 40; + owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40)); + } + if(specialDuiDaoHu == 3 ) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBEIKAOBEI, MingTang.ST_HUXI, 100)); + } + if(specialDuiDaoHu == 4) { + int xiao = owner.winCard % 100; + if(xiao == 1 || xiao == 10) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_FENGPAIWEI, MingTang.ST_HUXI, 50)); + } + } + if(owner.huXi == 10) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 50)); + } + if(zimo) { + //按需求40改30 05-20 mt + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 30)); + } + if(haveXi) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDINGXI, MingTang.ST_HUXI, 50)); + } + if (duiDaoHu) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 30)); + } + if (geShanDaNiu) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 30)); + } + if (specialDuiDaoHu == 5) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIAFENGBAIWEI, MingTang.ST_HUXI, 30)); + } + if(zimo && owner.winCard == 103) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100)); + } + /*if(CardUtil.checkErXiManHuaYuan(owner.opCardList, owner.handCard)) { + jiaxi += 150; + owner.winMtList.add(new MingTang(MingTang.TYPE_ERXIMANHUAYUAN, MingTang.ST_HUXI, 150)); + }*/ + if((tuanYuanSet.contains(101) && tuanYuanSet.contains(210)) || (tuanYuanSet.contains(110) && tuanYuanSet.contains(201))) { + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_JIALONGBAIWU, MingTang.ST_HUXI, 100)); + } + if (dandiao && CardUtil.checkYuanYuanDing(owner.opCardList, owner.handCard, owner.winCard)) { + //按需求50改100 05-20 mt + jiaxi += 100; + owner.winMtList.add(new MingTang(MingTang.TYPE_YUANYUANDING, MingTang.ST_HUXI, 100)); + } + + if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) { + jiaxi += 30; + owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30)); + } + + if(hong_num == 2 && contains123 == 2) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_ERLONGXIZHU, MingTang.ST_HUXI, 50)); + } + if(owner.cardInhand.size() == 1 && CardUtil.checkHongCard(owner.cardInhand.get(0))) { + jiaxi += 50; + owner.winMtList.add(new MingTang(MingTang.TYPE_MEINVCAIDANCHE,MingTang.ST_HUXI,50)); + } + huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi; + } + owner.winHuxi = huxi; + return huxi; + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void endGame() { + super.endGame(); + } + + /*public void settleRound() { + boolean total = this.round >= this.maxRound; + if (!total) + EXMainServer.gameCtr.roomResult(this); + else { + this.saveMilitaryTotal(false); + } + saveMilitaryRound(playBackData.getData()); + this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + + if (total) { + if (this.maxRound == 8) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winCount == 8) { + player.redisTask(3, 8); + } + } + } + this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + return; + } + }*/ + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + @Override + public void clear() { + super.clear(); + this.tianHu = true; + this.throwList.clear(); + this.liuju = false; + this.activeSeat = this.currenDiscardSeat = 0; + this.lastPaoSeat = 0; + this.draw = -1; + this.isAllPass = false; + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/EXScore.java b/game_zp_anxiang/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..e99220f --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,18 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score{ + public static final int WIN = 1; + public static final int DOULIUZISCORE = 2; + + + public EXScore(EXPlayer owner){ + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/MingTang.java b/game_zp_anxiang/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..5e8674d --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,76 @@ +package extend.zp; + +public class MingTang { + public final static int ST_HUXI_TIMES = 1; + public final static int ST_HUXI= 2; + + + public final static int TYPE_HONGHU = 1; + public final static int TYPE_DUOHONGHU = 2; + public final static int TYPE_WUHU = 3; + public final static int TYPE_WUDUI = 4; + public final static int TYPE_DUIZIHU = 5; + public final static int TYPE_XIAOYISE = 6; + public final static int TYPE_DAYISE = 7; + public final static int TYPE_MANHUAYUAN = 8; + public final static int TYPE_YIDIANHONG = 9; + public final static int TYPE_YINHU = 10; + public final static int TYPE_CHUNYINHU = 11; + public final static int TYPE_ZHUOHU = 12; + public final static int TYPE_JIEMEIZHUO = 13; + public final static int TYPE_LONGBAIWEI = 14; + public final static int TYPE_SANLUANZHUO = 15; + public final static int TYPE_SILUANZHUO = 16; + public final static int TYPE_JIEMEIZHUODAITUO = 17; + public final static int TYPE_DIASUNZHUO = 18; + public final static int TYPE_DIASUNZHUODAITUO = 19; + public final static int TYPE_JIABAPENGTOU = 20; + public final static int TYPE_ZHENBAPENGTOU = 21; + public final static int TYPE_HAIDIHU = 22; + public final static int TYPE_DANDIAO = 23; + public final static int TYPE_BEIKAOBEI = 24; + public final static int TYPE_SHOUQIANSHOU = 25; + public final static int TYPE_QUANQIUREN = 26; + public final static int TYPE_KAWEI = 27; + public final static int TYPE_TIANHU = 28; + public final static int TYPE_DINGDUI = 29; + public final static int TYPE_PIAODUI = 30; + public final static int TYPE_SXWUQIANNIAN = 31; + public final static int TYPE_LINGBIANKAN = 32; + public final static int TYPE_ZHENBEIKAOBEI = 33; + public final static int TYPE_FENGPAIWEI = 34; + public final static int TYPE_KAHU = 35; + public final static int TYPE_ZIMO = 36; + public final static int TYPE_DINGDINGXI = 37; + public final static int TYPE_DUIDAOHU = 38; + public final static int TYPE_ZHUOXIAOSAN = 39; + public final static int TYPE_ERXIMANHUAYUAN = 40; + public final static int TYPE_JIAFENGBAIWEI = 41; + public final static int TYPE_JIALONGBAIWU = 42; + public final static int TYPE_MEINVCAIDANCHE = 43; + public final static int TYPE_ERLONGXIZHU = 44; + public final static int TYPE_YUANYUANDING = 45; + public final static int TYPE_XINLIANXIN = 46; + public final static int TYPE_JIDING = 47; + public final static int TYPE_GSDN = 48; + + public final static int TYPE_QUANHEI = 50; + public final static int TYPE_WUXI = 51; + public final static int TYPE_LIUDUIHONG = 52; + public final static int TYPE_JIUDUI = 53; + public final static int TYPE_SIBIANDUI = 54; + public final static int TYPE_LIANGZHADAN = 55; + public final static int TYPE_REDBOMB = 57; + public final static int TYPE_BLACKBOMB = 58; + + + public int type; + public int v_type; + public int value; + + public MingTang(int type, int v_type, int value) { + this.type = type; + this.v_type = v_type; + this.value = value; + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/OpCard.java b/game_zp_anxiang/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..5978fdf --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,34 @@ +package extend.zp; + +import java.io.Serializable; + +import com.taurus.core.entity.ITArray; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + } + + public OpCard(int type, ITArray opcards, int card) { + this.type = type; + if (opcards.size() > 1) { + this.card2 = opcards.getInt(0); + this.card3 = opcards.getInt(1); + } + this.card1 = card; + } + public OpCard() { + + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/PlayBack.java b/game_zp_anxiang/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..046f0de --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,105 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack{ + + public PlayBack(EXRoom room){ + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer)entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + + public void showCardCommand(int seat,int card,int left_count,boolean discard){ + ITObject data = TObject.newInstance(); + data.putInt("card", card); + data.putInt("left_count", left_count); + data.putBoolean("discard", discard); + addCommand("ShowCard",seat,data); + } + + + public void addCardCommand(int seat,int card){ + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard",seat,data); + } + + public void addOutCardCommand(int seat,int card){ + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard",seat,data); + } + + 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 addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addAddCardCommand(int seat, int card, int leftCount) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + data.putInt("left_count", leftCount); + addCommand("AddCard", seat, data); + } + + public void addActionCommand(int seat,int type,int card,int from_seat,ITArray opcardArray,int huxi){ + 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.putInt("huxi", huxi); + addCommand("Action",seat,cmdData); + } + + public void addWinCardCommand(int seat,boolean zimo){ + ITObject cmdData = TObject.newInstance(); + addCommand("Win",seat,cmdData); + } + + public 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); + } + + public void addResultCommand(ITObject data) { + addCommand("Result",0,data); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_anxiang/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..a980fe4 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,90 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.RuleChow; +import extend.zp.player.rule.RulePong; +import extend.zp.player.rule.RuleWin; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + + + public static final int DRAW_RULE = 1; + + public static final int OTHER_DISCARD_RULE = 2; + + public static final int KONG_HU_RULE = 3; + + public static final int OTHER_DRAW_RULE = 4; + public static final int OTHER_DISCARD21_RULE = 5; + + public static final int WIN_RULE = 6; + + + public static final int ACTION_OTHER_RULE = 7; + + + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + public PlayerRuleManager() { + ruleMap = new HashMap>(); + tipMap = new HashMap(); + + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.WIN_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RulePong()); + drawRuleList.add(new RuleChow()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChow()); + ruleMap.put(PlayerRuleManager.OTHER_DISCARD_RULE, otherDiscardList); + + List asList = new ArrayList(); + asList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.WIN_RULE, asList); + } + + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/RoomCard.java b/game_zp_anxiang/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..f6c2f59 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class RoomCard { + public List cardList; + EXRoom room; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + } + + public void init() { + + this.cardList.clear(); + + this.initCard(); + + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public int pop() { + + if (this.cardList.size() == 0) { + this.room.bankerSeat = this.room.activeSeat; + } + + int card = this.cardList.remove(0); + return card; + + } + + public int getCount() { + return this.cardList.size(); + } + + public List dealFake() { + List dealCards = new ArrayList(); + String cardStr = "209, 205, 103, 106, 206, 202, 203, 101, 210, 101, 110, 104, 208, 108, 108, 110, 206, 110, 107, 207"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + dealCards.add(card); + } + return dealCards; + } + + public List dealFake1() { + List dealCards = new ArrayList(); + //String cardStr = "102, 103, 104, 107, 108, 108, 109, 202, 202, 204, 204, 204, 205, 205, 206, 206, 207, 208, 210"; + String cardStr = "103, 104, 104, 104, 105, 110, 110, 110, 110, 108, 109, 109, 109, 109, 108, 108, 204, 205, 206"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + dealCards.add(card); + } + return dealCards; + } + + public List dealFake2() { + List dealCards = new ArrayList(); + String cardStr = "102, 103, 101, 105, 105, 108, 109, 110, 203, 201, 206, 207, 208, 207, 202, 202, 210, 209, 209"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + dealCards.add(card); + } + return dealCards; + } + + public List dealFake3() { + List dealCards = new ArrayList(); + String cardStr = "102, 102, 107, 107, 110, 109, 202, 202, 207, 207, 210, 201, 201, 101, 107, 210, 107, 103, 101"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + dealCards.add(card); + } + return dealCards; + } + + public List deal(int num) { + List dealCards = new ArrayList(); + + for (int index = 0; index < num; index++) { + dealCards.add(this.pop()); + } + return dealCards; + + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/RuleWeight.java b/game_zp_anxiang/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..34898ac --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,26 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW = 1; + public final static int SELF_CHOW = 2; + public final static int PONG = 3; + + public final static int WIN1 = 6; + public final static int WIN2 = 7; + + public final static int WIN3 = 8; + + public final static int GROUP_CHOW = 1; + public final static int GROUO_PONG = 2; + public final static int GROUO_WIN = 5; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_WIN = 8; + public final static int TYPE_JIANG = 14; + public final static int TYPE_SAN = 15; +} + diff --git a/game_zp_anxiang/src/main/java/extend/zp/SettleLog.java b/game_zp_anxiang/src/main/java/extend/zp/SettleLog.java new file mode 100644 index 0000000..e78711c --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/SettleLog.java @@ -0,0 +1,44 @@ +package extend.zp; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +public class SettleLog { + private Map log; + + public SettleLog() { + log = new HashMap(); + } + + public void put(String key,Integer value) { + log.put(key, value); + } + + public void add(String key) { + if(!log.containsKey(key)) { + return; + } + int value = log.get(key); + value++; + log.put(key, value); + } + + public Integer get(String key) { + if(!log.containsKey(key)) { + return null; + } + return log.get(key); + } + + public ITObject toTObject() { + ITObject obj = TObject.newInstance(); + for (Entry entry : this.log.entrySet()) { + obj.putInt(entry.getKey(), entry.getValue()); + } + return obj; + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleChow.java b/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleChow.java new file mode 100644 index 0000000..f221d2f --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleChow.java @@ -0,0 +1,79 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; + +import extend.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRChowState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.ChowCard; + +/** + * ���Ƽ�� + * + */ +public class RuleChow implements IRuleBase { + + @Override + public boolean condition(EXPlayer player) { + // �й�Ĭ�ϲ���� + if (player.isEntrust() || player.siShou) return false; + EXRoom room = player.getRoom(); + if (!(player.seat == room.activeSeat || player.lastSeat == room.activeSeat)) { + return false; + } + if (room.config.containsKey(Config.ROOM_CONFIG_CHUPAI) && room.draw == 0 + && room.config.getInt(Config.ROOM_CONFIG_CHUPAI) == 1) return false; + if (room.config.containsKey(Config.ROOM_CONFIG_FANPAI) && room.draw > 0 + && room.config.getInt(Config.ROOM_CONFIG_FANPAI) == 1 && player.seat != room.draw) return false; + if(player.cardInhand.size() <= 2 || Util.checkCard(room.showCard, player.cardInhand, 2)) { + return false; + } + + int card = room.showCard; + if(player.chouList.contains(card))return false; + + boolean result = false; + boolean self = player.seat == room.activeSeat; + + ChowCard chow = new ChowCard(player.cardInhand,card); + ITArray list = TArray.newInstance(); + result = chow.tryChow(list); + if(result) { + for(int i=0;i= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + Tip tip = new Tip(card,opcard, RuleWeight.PONG,this, RuleWeight.TYPE_PONG); + tip.group_type = RuleWeight.GROUO_PONG; + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..9d2d8f8 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.PaiXing; + +public class RuleWin implements IRuleBase{ + + @Override + public boolean condition(EXPlayer player) { + if (player.siShou) return false; + EXRoom room = player.getRoom(); + int card = room.showCard; + player.winType = 0; + player.winCard = room.showCard == 0 ? player.actionCard : room.showCard; + player.currentOpCardList.clear(); + for (OpCard opCard : player.opCardList) { + player.currentOpCardList.add(new OpCard(opCard.type, opCard.card1, opCard.card2, opCard.card3, opCard.huXi)); + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.getRoom().draw); + if ((room.tianHu && player.seat == room.bankerSeat) || !room.tianHu) { + if (PaiXing.checkWin(player, card, player.currentOpCardList)) { + player.winType = 2; + } + } + if (room.tianHu && (room.config.getInt(Config.ROOM_CONFIG_WANFA) == 1 || + room.config.getInt(Config.ROOM_CONFIG_WANFA) == 4 || + (room.config.containsKey(Config.ROOM_CONFIG_TH) && room.config.getBoolean(Config.ROOM_CONFIG_TH))) + && PaiXing.checkSpecialWin(player, room.config.getInt(Config.ROOM_CONFIG_WANFA))) { + if (player.winType > 0) { + player.winType = 3; + }else { + player.winType = 1; + } + } + if (player.winType > 0) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(card, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + if (player.seat == activePlayer.seat) { + player.isZiMo = true; + } + Global.logger.info(player + " zimo:"+ player.isZiMo+ ",winType��"+player.winType); + return true; + } + player.winCard = 0; + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRChowState.java b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRChowState.java new file mode 100644 index 0000000..41ea938 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRChowState.java @@ -0,0 +1,74 @@ +package extend.zp.player.rulestate; + + +import java.util.ArrayList; +import java.util.List; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + +/** + * ��Ӧ���ƴ���״̬ + * + */ +public class PRChowState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + int card= room.showCard; + owner.suoCardList.add(card); + room.showCard = 0; + __chow(owner,chowcard1,chowcard2,card,fromseat); + this.toNextState(owner); + } + + private static final void __chow(EXPlayer owner,int chowcard1,int chowcard2,int card,int fromseat) { + int type = RuleWeight.TYPE_CHOW; + ITArray opcards = TArray.newInstance(); + opcards.addInt(chowcard1); + opcards.addInt(chowcard2); + OpCard opc = new OpCard(type, opcards, card); + owner.opCardList.add(opc); + + Util.removeCard(owner.cardInhand, chowcard1, 1); + Util.removeCard(owner.cardInhand, chowcard2, 1); + opc.huXi = 0; + List chowGroup = new ArrayList(); + chowGroup.add(card); + chowGroup.add(chowcard1); + chowGroup.add(chowcard2); + EXMainServer.gameCtr.actionCard(owner, card, type, fromseat,opcards,0 + ,CardUtil.getCardGroupHuxi1(chowGroup, owner.opCardList)); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..0e7f52c --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,50 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.uitl.CardUtil; + +public class PRPongState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = (EXRoom) owner.room; + + EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + owner.cardInhand.add(room.showCard); + + int card = room.showCard; + Util.removeCard(owner.cardInhand, card, 3); + room.showCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + + + OpCard opc = new OpCard(RuleWeight.TYPE_PONG, opcard, card); + opc.huXi = CardUtil.getCardGroupHuxi(card, RuleWeight.TYPE_PONG, owner.opCardList); + owner.opCardList.add(opc); + + EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG, fromseat,opcard,opc.huXi,null); + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..6d33e31 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,65 @@ +package extend.zp.player.rulestate; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.EXScore; + + +public class PRWinState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + owner.winer = 1; + owner.hutype = activePlayer.playerid == owner.playerid ? 1 : 2;//1���� + owner.winCard = room.showCard == 0 ? owner.actionCard : room.showCard; + for (Entry entry : room.playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + int huXi = 0, specialHuXi = 0; + if (owner.winType == 3) { + huXi = room.caclWin(owner, activePlayer.playerid == owner.playerid ? true : false); + specialHuXi = room.caclSpecialScore(owner); + }else if (owner.winType == 2) { + huXi = room.caclWin(owner, activePlayer.playerid == owner.playerid ? true : false); + }else if (owner.winType == 1) { + specialHuXi = room.caclSpecialScore(owner); + } + owner.allHuXi = huXi + specialHuXi; + int score = owner.allHuXi;//CardUtil.huxiToScore(owner.allHuXi); + room.addAllScore(owner,score,EXScore.WIN); + if (room.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN) && owner.huXi >= 18) { + int liuzi_score = 0, dengNum = 1 + (owner.huXi - 18); + int deng = room.config.getInt(Config.ROOM_CONFIG_YIDENG); + if (deng == 0) { + liuzi_score = 80*dengNum; + }else if (deng == 1) { + liuzi_score = 100*dengNum; + }else if (deng == 2) { + liuzi_score = 200*dengNum; + } + room.addDouLiuZiScore(owner, liuzi_score > room.douLiuZi ? -room.douLiuZi : -liuzi_score, EXScore.DOULIUZISCORE); + } + Global.logger.info(owner + " self win! hutype:"+owner.hutype); + + EXMainServer.gameCtr.winEvent(owner,owner.seat); + + owner.room.bankerSeat = owner.seat; + room.endGame(); + } + + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..551357c --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,59 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + + @Override + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + Tip tip = owner.tipMgr.tipMap.get(id); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) {//�Ƿ���ں� + Tip tip1 = entry.getValue(); + if (tip1.type == RuleWeight.TYPE_WIN) { + if (tip == null || tip.type != RuleWeight.TYPE_WIN) { + owner.winType = 0; + break; + } + } + } + owner.tipMgr.choicAction(id); + }else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id); + } + + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..358009c --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,139 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + + owner.getRoom().showCard = 0; + List sList = new ArrayList(); + sList.addAll(owner.suoCardList); + if(sList.containsAll(owner.cardInhand)) { + owner.siShou = true; + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + owner.getRoom().broadCastToClient(0, Config.GAME_EVT_SISHOU, param); + toNextSetp(owner); + return; + } + EXMainServer.gameCtr.ting(owner); + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + + private void toNextSetp(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + + @Override + public void toNextState(EXPlayer owner) { + timer(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void discard(EXPlayer owner, int discard) { + int cardNum = Util.cardNum(discard, owner.cardInhand); + if(cardNum == 0 || cardNum == 3) { + return; + } + if(owner.suoCardList.contains(discard)) return; + owner.chouList.add(discard); + EXRoom room = owner.getRoom(); + room.showCard = discard; + room.currenDiscardSeat = 0; + room.lastPaoSeat = 0; + room.draw = 0; + EXMainServer.gameCtr.outCard(owner, discard); + owner.tingList.clear(); + if (owner.tingMap.containsKey(discard)) { + owner.tingList.addAll(owner.tingMap.get(discard)); + } + owner.tingMap.clear(); + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + this.toNextState(owner); + } + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner,discard ); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + int card=owner.autoDiscard(); + Global.logger.info(owner+" entust auto card :"+card); + discard(owner,card ); + break; + default: + break; + } + + } + + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().showCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + int showCard = owner.getRoom().showCard; + owner.outcardList.add(showCard); + System.out.println("laile================================="); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, showCard); + owner.getRoom().showCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..eab2c3f --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,183 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.EXScore; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDrawState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.card.cardList.size() == 0) { + room.liuju = true; + if (room.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) { + int xianScore = (room.config.getInt(Config.ROOM_CONFIG_ZHUANGXIAN) + 1)*10; + for(Entry entry : room.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + room.addDouLiuZiScore(player, player.seat == room.bankerSeat ? xianScore +10 : xianScore, EXScore.DOULIUZISCORE); + } + } + room.bankerSeat = room.playerMapBySeat.get(room.bankerSeat).nextSeat; + room.endGame(); + return; + } + draw(owner); + } + + void draw(EXPlayer owner) { + EXRoom room = owner.getRoom(); + + int drawCard = room.card.pop(); + //drawCard = 103; + room.showCard = drawCard; + room.lastPaoSeat = 0; + room.isAllPass = false; + room.draw = owner.seat; + int leftCount = room.card.getCount(); + if (!owner.siShou && Util.cardNum(drawCard, owner.cardInhand) >= 2) { + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", room.activeSeat); + param.putInt("left_count", leftCount); + owner.sendEvent(Config.GAME_EVT_DRAW, param); + ITObject otherParam = new TObject(); + Utils.objectCopy(param, otherParam); + otherParam.putInt("card", 0); + room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + room.getPlayBack().addGetCardCommand(room.activeSeat, drawCard, leftCount); + //owner.stateMachine.changeState(Global.getState(EXPlayerWeiState.class)); + timer1(owner); + return; + } + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDisCardTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + timer(owner); + } + + public static void timer1(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(EXPlayerWeiState.class)); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } + + public static void timer(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (room.card.getCount() == 0) { + room.liuju = true; + if (room.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN)) { + int xianScore = (room.config.getInt(Config.ROOM_CONFIG_ZHUANGXIAN) + 1)*10; + for(Entry entry : room.playerMapByPlaying.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + room.addDouLiuZiScore(player, player.seat == room.bankerSeat ? xianScore +10 : xianScore, EXScore.DOULIUZISCORE); + } + } + room.bankerSeat = room.playerMapBySeat.get(room.bankerSeat).nextSeat; + room.endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", room.showCard); + param.putInt("seat", owner.seat); + room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + int showCard = room.showCard; + owner.outcardList.add(showCard); + room.showCard = 0; + room.getPlayBack().addThrowCardCommand(owner.seat, showCard); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject param = new TObject(); + param.putInt("card", room.showCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + int showCard = room.showCard; + owner.outcardList.add(showCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, showCard); + room.showCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } + } + +} + + + + + + + + + + + + + + diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..467bea3 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,50 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + owner.tipMgr.doAction(id); + }else if (cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) { + int id = 0; + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id); + } + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..c6cb132 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,88 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.CardUtil; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.isAllPass = false; + int card = room.card.pop(); + //card = 104; + room.isAllPass = false; + int leftCount = room.card.getCount(); + + owner.cardInhand.add(card); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("left_count", leftCount); + param.putInt("card", card); + param.putInt("seat", owner.room.activeSeat); + owner.sendEvent(Config.GAME_EVT_ADDDRAW, param); + CardUtil.sendSuoCardEvent(owner); + room.getPlayBack().addAddCardCommand(owner.room.activeSeat, card, leftCount); + ITObject param1 = new TObject(); + param1.putInt("left_count", leftCount); + param1.putInt("card", 0); + param1.putInt("seat", owner.room.activeSeat); + room.broadCastToClient(owner.playerid, Config.GAME_EVT_ADDDRAW, param1); + room.draw = owner.seat; + for (Entry entry : room.playerMapBySeat.entrySet()) { + if (entry.getKey() != owner.seat) { + EXPlayer player = (EXPlayer) entry.getValue(); + EXMainServer.gameCtr.qiShouTing(player); + } + } + //EXMainServer.playerRuleMgr.condition(PlayerRuleManager.WIN_RULE, owner); + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().tianHu = false; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WIN_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_WIN, null); + if (owner.getRoom().tipMap.size() == 0) { + toNextState(owner); + } + } + }); + } + }, 300, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..553062b --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,42 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (cmd.equals(ActionEvent.EVENT_ENTRUST)) { + owner.startActionTimer(); + } + } + + public void reload(EXPlayer owner) { + super.reload(owner); + this.enter(owner); + + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..8f93403 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,34 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + + +public class EXPlayerWaitState extends StateBase { + + + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DISCARD_RULE , owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.DRAW_RULE , owner); + break; + case EXActionEvent.EVENT_WIN: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.WIN_RULE , owner); + break; + + default: + break; + } + + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWeiState.java b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWeiState.java new file mode 100644 index 0000000..1cc28b2 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/player/state/EXPlayerWeiState.java @@ -0,0 +1,88 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; + + +public class EXPlayerWeiState extends StateBase { + + @Override + public void enter(EXPlayer owner) { + boolean pass = owner.stateMachine.lastState instanceof EXPlayerDisCardTipState; + if(pass) return; + EXRoom room = owner.getRoom(); + + int fromseat = owner.seat; + int card = room.showCard; + owner.actionCard = card; + Util.removeCard(owner.cardInhand, card, 2); + if (owner.suoCardList.contains(card)) + owner.suoCardList.remove(Integer.valueOf(card)); + room.showCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + //boolean chou = owner.chouList.contains(card); + int type = RuleWeight.TYPE_WEI; + OpCard opc = new OpCard(type, opcard, card); + opc.huXi = CardUtil.getCardGroupHuxi(card, type, owner.opCardList); + owner.opCardList.add(opc); + + + EXMainServer.gameCtr.actionCard(owner, card, type, fromseat,opcard,opc.huXi, null); + owner.kaWei = true; + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.WIN_RULE, owner); + //timer(owner); + } + + + @Override + public void toNextState(EXPlayer owner) { + owner.actionCard = 0; + owner.kaWei = false; + if(CardUtil.checkHandKan(owner.cardInhand)) { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + return; + } + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.WIN_RULE, owner); + } + }); + } + }, 900, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..9514066 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,40 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.player.state.EXPlayerPreDrawState; + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } + + deal(owner); + } + + private void deal(EXRoom owner) { + EXMainServer.gameCtr.dealCard(owner); + owner.playBackData = new PlayBack(owner); + toNextState(owner); + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + } + + @Override + public void toNextState(EXRoom owner) { + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..71b6e5b --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,37 @@ +package extend.zp.room.state; + + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + + +public class EXRoomSetpState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + + Player player; + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + + } + + EXMainServer.gameCtr.changeActiveSeat(owner,player.seat); + + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + + + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..b8b93f7 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,24 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.state.StateBase; + +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.startGame(); + + this.toNextState(owner); + + } + + @Override + public void toNextState(EXRoom owner) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/tip/Action.java b/game_zp_anxiang/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..b8140bf --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,23 @@ +package extend.zp.tip; + + +import extend.zp.EXPlayer; + + +public class Action { + + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.tip.rule.action(this.player); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_anxiang/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..4f0a822 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player ); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/tip/Tip.java b/game_zp_anxiang/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..21a1481 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,36 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public int group_type; + + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", group_type); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + return tipMp; + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/tip/TipManager.java b/game_zp_anxiang/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..4f44026 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,139 @@ +package extend.zp.tip; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; + +public class TipManager { + + private int id = 0; + + public Map tipMap = null; + public Tip actionTip; + public EXPlayer owner = null; + public EXRoom room; + public boolean isWin; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + room = this.owner.getRoom(); + } + + public void addTip(Tip tip) { + int id = this.getId(); + tip.id = id; + this.tipMap.put(id, tip); + } + + + @SuppressWarnings("unchecked") + public void choicAction(int id) { + if (id == 0) { + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if(tip.type == RuleWeight.TYPE_PONG || tip.type == RuleWeight.TYPE_CHOW) { + owner.chouList.add(tip.card); + } + } + if(room.activeSeat == owner.seat) { + //this.owner.stateMachine.toLastState(); + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + }else { + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + room.checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + room.addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + + @SuppressWarnings("unchecked") + public void doAction(int id) { + if (id == 0) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_CHOW || tip.type == RuleWeight.TYPE_PONG) { + owner.chouList.add(tip.card); + } + } + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + room.checkAction(); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + + public void cleanWeightest(int weight) { + List list = new ArrayList(this.tipMap.values()); + for (Tip tip : list) { + if (tip.weight < weight) { + this.tipMap.remove(tip.id); + } + } + } + + public void clean() { + this.id = 0; + this.isWin = false; + this.tipMap = new HashMap(); + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_anxiang/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7b45a35 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,825 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.Stack; + +import com.game.Util; +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.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class CardUtil { + + + public static void sendSuoCardEvent(EXPlayer owner) { + Map cardNumMap = Util.getCardNumMap(owner.cardInhand); + for (Entry entry : cardNumMap.entrySet()) { + int keyCard = entry.getKey(); + int num = entry.getValue(); + if (num == 3) { + owner.suoCardList.add(keyCard); + } + } + ITArray paramArray = TArray.newInstance(); + for (int suoCard : owner.suoCardList) { + paramArray.addInt(suoCard); + } + ITObject param = new TObject(); + param.putTArray("suoCard", paramArray); + owner.sendEvent(Config.GAME_PLAYER_SUOPAI, param); + } + + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int checkQingyise(List opCards, Stack cgList) { + int se = 0; + for (OpCard card : opCards) { + if(se==0) { + se = card.card1 / 100; + continue; + } + if (se != card.card1 / 100) { + return 0; + } + } + for (OpCard cg : cgList) { + if(se==0) { + se = cg.card1 / 100; + continue; + } + if (se != cg.card1 / 100) { + return 0; + } + } + return se; + } + + + static public boolean checkContainHong(List opCards, Stack cgList) { + boolean hong = true; + for (OpCard card : opCards) { + List list = new ArrayList(); + list.add(card.card1 % 100); + list.add(card.card2 % 100); + list.add(card.card3 % 100); + if(!list.contains(2) && !list.contains(7) && !list.contains(10)) { + hong = false; + break; + } + } + if(!hong) + return hong; + for (OpCard cg : cgList) { + List list = new ArrayList(); + list.add(cg.card1 % 100); + list.add(cg.card2 % 100); + if (cg.card3 > 0) list.add(cg.card3 % 100); + if(!list.contains(2) && !list.contains(7) && !list.contains(10)) { + hong = false; + break; + } + } + return hong; + } + + /** + * @return 1.������ 2.��ǣ�� 3.�汳���� 4.���β 5.�ٷ��β + */ + public static int checkSpecialDuiDaoHu(List opCards, Stack cgList, int winCard) { + int card = 0, jiangCard = 0; + for (OpCard opCard : cgList) { + if (opCard.type == RuleWeight.TYPE_JIANG) { + jiangCard = opCard.card1; + }else if (opCard.type == RuleWeight.TYPE_PONG && winCard == opCard.card1) { + card = winCard; + } + } + if (card == 0) { + for (OpCard opCard : opCards) { + if (opCard.type == RuleWeight.TYPE_WEI + && winCard == opCard.card1 ) { + card = winCard; + break; + } + } + } + if (jiangCard % 100 == card % 100) { + if (jiangCard % 100 == 8) return 3; + return 1; + }else if (Math.abs(jiangCard % 100 - card % 100) == 1 && jiangCard / 100 == card / 100) { + return 2; + }else if ((jiangCard % 100 == 1 || jiangCard % 100 == 10) && (card % 100 == 1 || card % 100 == 10)) { + if ((jiangCard % 100 == 1 && card % 100 == 10) || (jiangCard % 100 == 10 && card % 100 == 1)) { + if (card / 100 == jiangCard / 100) { + return 4; + }else { + return 5; + } + } + } + return 0; + } + + public static boolean checkYuanYuanDing(List opCards, Stack cgList, int winCard) { + List cardList = new ArrayList(); + for (OpCard opCard : cgList) { + if (opCard.type == RuleWeight.TYPE_JIANG && opCard.card1 != winCard) return false; + cardList.add(opCard.card1); + cardList.add(opCard.card2); + if (opCard.card3 > 0) cardList.add(opCard.card3); + } + for (OpCard opCard : opCards) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + cardList.add(opCard.card2); + cardList.add(opCard.card3); + } + } + if (Util.checkCard(winCard, cardList, 4)) return true; + return false; + } + + public static boolean checkPiaoDui(List opCards, Stack cgList) { + for (OpCard opCard : opCards) { + if (checkHongCard(opCard.card1)) { + return true; + } + } + for (OpCard opCard : cgList) { + if (opCard.type == RuleWeight.TYPE_PONG && checkHongCard(opCard.card1)) { + return true; + } + } + return false; + } + + public static boolean checkXinLianXin(List opCards, Stack cgList) { + List> shunZiList = new ArrayList<>(); + for (OpCard opCard : cgList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + List list = new ArrayList<>(); + list.add(opCard.card1); + list.add(opCard.card2); + list.add(opCard.card3); + shunZiList.add(list); + } + } + for (OpCard opCard : opCards) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + List list = new ArrayList<>(); + list.add(opCard.card1); + list.add(opCard.card2); + list.add(opCard.card3); + shunZiList.add(list); + } + } + while (true) { + if (shunZiList.size() <= 1) break; + List remove = shunZiList.remove(0); + for (List sz : shunZiList) { + int min = Collections.min(remove); + int min2 = Collections.min(sz); + if (min + (min < min2 ? 2 : -2) == min2) return true; + } + } + return false; + } + + public static boolean checkJiDing(Stack cgList, int winCard) { + List list = new ArrayList<>(); + for (OpCard opCard : cgList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + list.clear(); + list.add(opCard.card1); + list.add(opCard.card2); + list.add(opCard.card3); + if (Collections.min(list) + 1 == winCard) return true; + } + } + return false; + } + + static public Set checkTuanYuan(List opCards, Stack cgList) { + Set threeCard = new HashSet(); + Set otherCard = new HashSet(); + for (OpCard card : opCards) { + Set set = new HashSet(); + set.add(card.card1); + set.add(card.card2); + set.add(card.card3); + if(set.size() == 1) { + threeCard.addAll(set); + } else { + otherCard.addAll(set); + } + } + for (OpCard cg : cgList) { + Set set = new HashSet(); + set.add(cg.card1); + set.add(cg.card2); + if (cg.card3 == 0) continue; + set.add(cg.card3); + if(set.size() == 1) { + threeCard.addAll(set); + } else { + otherCard.addAll(set); + } + } + threeCard.retainAll(otherCard); + return threeCard; + } + + static public boolean checkErXiManHuaYuan(List opCards, List cgList) { + List cards = new ArrayList(); + boolean result = true; + int pairCard = 0; + for (OpCard card : opCards) { + Set set = new HashSet(); + set.add(card.card1); + set.add(card.card2); + set.add(card.card3); + boolean hong = false; + for(int ca : set) { + if(checkHongCard(ca)) { + cards.add(ca); + hong = true; + } + } + if(!hong) + result = false; + } + if(!result) + return result; + for (OpCard cg : cgList) { + Set set = new HashSet(); + set.add(cg.card1); + set.add(cg.card2); + if (cg.card3 > 0)set.add(cg.card3); + boolean hong = false; + for(int ca : set) { + if(checkHongCard(ca)) { + cards.add(ca); + hong = true; + } + } + if(!hong) + result = false; + } + if(!result) + return result; + if(!checkHongCard(pairCard)) + return false; + if(cards.contains(pairCard)) { + Integer num = Util.getCardNumMap(cards).get(pairCard); + if(num != 3) { + return true; + } else { + return false; + } + } else { + return true; + } + } + + static public int getHongCardNum(List cardInhand,List opCards) { + int count = 0; + for(Integer card : cardInhand) { + if(checkHongCard(card))count++; + } + for(OpCard opc : opCards) { + if(checkHongCard(opc.card1))count++; + if(checkHongCard(opc.card2))count++; + if(checkHongCard(opc.card3))count++; + } + return count; + } + + static public final boolean checkHongCard(int card) { + int mod_card = card % 100; + if(mod_card == 2 || mod_card == 7 || mod_card == 10)return true; + return false; + } + + public static int checkHieHongZhaDan(List cardList) { + int result = 0; + Map cardNumMap = Util.getCardNumMap(cardList); + for (Entry entry : cardNumMap.entrySet()) { + if (entry.getValue() == 4) { + int bomb = entry.getKey(), temp = 0; + for (Integer card : cardList) { + if (card != bomb && Math.abs(bomb - card) <= 2) { + temp++; + break; + } + } + if (temp == 0) { + if (CardUtil.checkHongCard(bomb)) return 2; + result = 1; + } + } + } + return result; + } + + public static boolean checkManYuanHua(List opCards) { + for (OpCard opCard : opCards) { + int hongNum = 0; + if (checkHongCard(opCard.card1)) hongNum++; + if (checkHongCard(opCard.card2)) hongNum++; + if (opCard.card3 > 0 && checkHongCard(opCard.card3)) hongNum++; + if (hongNum == 0) return false; + } + return true; + } + + static public List getCardGroupHuxi1(List chowGroup, List opCardList) { + int self = 0, others = 0; + List result = new ArrayList<>(); + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_WEI ) { + if (chowGroup.contains(opCard.card1)) { + int huxi = checkHongCard(opCard.card1) ? 8 : 6; + self += huxi - opCard.huXi; + opCard.huXi = huxi; + } + }else if (opCard.type == RuleWeight.TYPE_PONG) { + if (chowGroup.contains(opCard.card1)) { + int huxi = checkHongCard(opCard.card1) ? 7 : 5; + self += huxi - opCard.huXi; + others += huxi - opCard.huXi; + opCard.huXi = huxi; + } + } + } + result.add(self); + result.add(others); + return result; + } + + static public int getCardGroupHuxi(int card,int type, List opCardList) { + int huXi = 0; + switch(type) { + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW && + (opCard.card1 == card || opCard.card2 == card || opCard.card3 == card)) { + huXi = checkHongCard(card) ? 8 : 6; + } + } + if (huXi == 0) huXi = checkHongCard(card) ? 4 : 3; + return huXi; + case RuleWeight.TYPE_KAN: + return huXi = checkHongCard(card) ? 4 : 3; + case RuleWeight.TYPE_PONG: + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW && + (opCard.card1 == card || opCard.card2 == card || opCard.card3 == card)) { + huXi = checkHongCard(card) ? 7 : 5; + break; + } + } + if (huXi == 0) huXi = checkHongCard(card) ? 3 : 2; + return huXi; + } + return huXi; + } + + static public int huxiToScore(int huxi) { + int xi = 0; + /*if(huxi > 21) return 3 + (huxi - 21) /3; + if(huxi == 21) return 3; + if(huxi >= 16) return 2; + if(huxi >= 10) return 1;*/ + xi = huxi /10; + return xi; + } + + static public boolean checkHandKan(List cardInhand) { + Map cardMap = Util.getCardNumMap(cardInhand); + for(Integer num : cardMap.values()) { + if(num != 3) return false; + } + return true; + } + + public final static Random random = new Random(); + static { + random.setSeed(System.currentTimeMillis()); + } + static public int randomDiceNum() { + int result = random.nextInt(5); + return result + 1; + } + + + public static boolean checkWuXi(List cardList) { + Map cardNumMap = Util.getCardNumMap(cardList); + List twoList = new ArrayList<>(), cCardList = new ArrayList<>(); + int hong = 0; + for (Entry entry : cardNumMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 2) { + if (checkHongCard(card)) hong++; + twoList.add(card); + }else { + //if (checkHongCard(card)) other += num; + cCardList.add(card); + } + } + if (twoList.size() == 0) { + return true; + }else if (twoList.size() == 1) { + if (hong == 1) { + int card = twoList.get(0); + int frequency = Collections.frequency(cardList, card); + if (frequency > 2) { + for (Integer c : cCardList) { + int abs = Math.abs(card - c); + if (abs > 0 && abs <= 2) return false; + } + }else if (kaoCard(card, cardList)) { + return false; + } + } + return true; + }else if (twoList.size() == 2) { + if (hong == 0) { + for (Integer c : twoList) { + int frequency = Collections.frequency(cardList, c); + if (frequency > 2) { + for (Integer card : cCardList) { + int abs = Math.abs(card - c); + if (abs > 0 && abs <= 2) return false; + } + }else if (kaoCard(c, cardList)) { + return false; + } + } + return true; + } + } + return false; + } + + public static boolean kaoCard(int card, List cardList) { + if ((CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) || + (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) || + (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1)) + return true; + return false; + } + + + public static boolean removeCard(List cardList, List removeCardList) { + List list = new ArrayList<>(cardList); + int removeNum = 0; + for (int i = 0; i < removeCardList.size(); i++) { + for (int j = 0; j < cardList.size(); j++) { + if (cardList.get(j).equals(removeCardList.get(i))) { + cardList.remove(j); + removeNum++; + break; + } + } + } + if (removeNum < removeCardList.size()) { + cardList.clear(); + cardList.addAll(list); + return false; + } + return true; + } + + + static public List seekAppropriate(int eventCard, List cardList) { + List result = new ArrayList<>(); + for (Integer card : cardList) { + if (Math.abs(eventCard - card) <= 2 && card != eventCard) { + result.add(card); + result.add(eventCard); + Collections.sort(result); + break; + } + } + return result; + } + + + static public List> seekAppropriate2(int eventCard, List cardList) { + List> result = new ArrayList<>(); + if (!(eventCard % 100 == 2 || eventCard % 100 == 7 || eventCard % 100 == 10)) return result; + if (eventCard % 100 == 2) { + if (CardUtil.cardNum(eventCard + 5, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard + 5); + result.add(list); + } + if (CardUtil.cardNum(eventCard + 8, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard + 8); + result.add(list); + } + }else if (eventCard % 100 == 7) { + if (CardUtil.cardNum(eventCard - 5, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard - 5); + result.add(list); + } + if (CardUtil.cardNum(eventCard + 3, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard + 3); + result.add(list); + } + }else if (eventCard % 100 == 10) { + if (CardUtil.cardNum(eventCard - 3, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard - 3); + result.add(list); + } + if (CardUtil.cardNum(eventCard - 8, cardList) > 0) { + List list = new ArrayList<>(); + list.add(eventCard); + list.add(eventCard - 8); + result.add(list); + } + } + + return result; + } + + + static public List seekAppropriate1(int eventCard, List cardList) { + List result = new ArrayList<>(); + if (!(eventCard % 100 == 2 || eventCard % 100 == 7 || eventCard % 100 == 10)) return result; + if (eventCard % 100 == 2) { + if (CardUtil.cardNum(eventCard + 5, cardList) > 0) { + result.add(eventCard); + result.add(eventCard + 5); + }else if (CardUtil.cardNum(eventCard + 8, cardList) > 0) { + result.add(eventCard); + result.add(eventCard + 8); + } + }else if (eventCard % 100 == 7) { + if (CardUtil.cardNum(eventCard - 5, cardList) > 0) { + result.add(eventCard); + result.add(eventCard - 5); + }else if (CardUtil.cardNum(eventCard + 3, cardList) > 0) { + result.add(eventCard); + result.add(eventCard + 3); + } + }else if (eventCard % 100 == 10) { + if (CardUtil.cardNum(eventCard - 3, cardList) > 0) { + result.add(eventCard); + result.add(eventCard - 3); + }else if (CardUtil.cardNum(eventCard - 8, cardList) > 0) { + result.add(eventCard); + result.add(eventCard - 8); + } + } + + return result; + } + + + static public int discardNum(List cardList, HashSet suoList) { + int result = 0; + for (Integer card : cardList) { + if (suoList != null && suoList.contains(card)) { + continue; + } + result++; + } + return result; + } + + + public static Set getCardNumSet(List cardList, int num) { + Set cardNum = new HashSet<>(); + Map cardMap = Util.getCardNumMap(cardList); + for (Entry card : cardMap.entrySet()) { + if (card.getValue() >= num) { + cardNum.add(card.getKey()); + } + } + return cardNum; + } + + + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + if (card == 0) { + return true; + } + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } + + public static boolean isHeiHong(OpCard opCard) { + int hei = 0, hong = 0; + if (opCard != null) { + if (opCard.card1 != 0) { + if (isRedCard(opCard.card1)) { + hong += 1; + } else { + hei += 1; + } + } + if (opCard.card2 != 0) { + if (isRedCard(opCard.card2)) { + hong += 1; + } else { + hei += 1; + } + } + if (opCard.card3 != 0) { + if (isRedCard(opCard.card3)) { + hong += 1; + } else { + hei += 1; + } + } + } + return hei > 0 && hong > 0; + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void removeOpCard(List cardList, OpCard opcard) { + if (opcard != null) { + Util.checkCardAndRomve(opcard.card1, cardList, 1); + Util.checkCardAndRomve(opcard.card2, cardList, 1); + Util.checkCardAndRomve(opcard.card3, cardList, 1); + } + } + + public static boolean findOpCard(List cardList, OpCard opcard) { + boolean result = false; + if (opcard != null) { + int card1 = opcard.card1; + int card2 = opcard.card2; + int card3 = opcard.card3; + List list = new ArrayList<>(); + list.add(card1); + list.add(card2); + list.add(card3); + Map mapNum = Util.getCardNumMap(list); + for (Entry map : mapNum.entrySet()) { + result = Util.checkCard(map.getKey(), cardList, map.getValue()); + if (!result) { + break; + } + } + } + return result; + } + + + + + public static void main(String[] args) { + List cardList = new ArrayList<>(); + cardList.add(110); + //cardList.add(103); + /*cardList.add(105); + cardList.add(104); + cardList.add(107); + cardList.add(110); + cardList.add(108); + cardList.add(210); + cardList.add(202); + cardList.add(209); + cardList.add(205); + cardList.add(205); + cardList.add(206); + cardList.add(204); + cardList.add(203); + cardList.add(203);*/ + List seekAppropriate = seekAppropriate(108, cardList); + //System.out.println(checkHongCard(202)); + //System.out.println(checkTuanYuan(cardList,)); + System.out.println(seekAppropriate.toString()); + /*String str=""; + for (Integer integer : cardList) { + str+=integer+", "; + } + System.out.println(str); + Set chiSet = getCardChiGroup(cardList, 207); + Set canChiSet=new HashSet<>(); + canChiSet.addAll(chiSet); + for (Chi chi : chiSet) { + canChiSet.remove(chi); + System.out.println(chi.toString()); + } + System.out.println("--------------------------"); + for (Chi chi : canChiSet) { + System.out.println(chi.toString()); + }*/ + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_anxiang/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..cbc7d9b --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,100 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + @SuppressWarnings("unused") + private int eventCardType; + @SuppressWarnings("unused") + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + /*List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + }*/ + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + obj.putTArray("opcard", opcard); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + /*int type = this.eventCardType; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + }*/ + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + cardInhand.add(102); + cardInhand.add(102); + cardInhand.add(105); + cardInhand.add(105); + cardInhand.add(106); + cardInhand.add(106); + cardInhand.add(107); + cardInhand.add(107); + cardInhand.add(108); + cardInhand.add(108); + cardInhand.add(109); + cardInhand.add(109); + cardInhand.add(110); + cardInhand.add(110); + cardInhand.add(207); + cardInhand.add(207); + + ChowCard chow = new ChowCard(cardInhand, 110); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/uitl/PaiXing.java b/game_zp_anxiang/src/main/java/extend/zp/uitl/PaiXing.java new file mode 100644 index 0000000..291317e --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/uitl/PaiXing.java @@ -0,0 +1,103 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.util.Logger; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; + +public class PaiXing { + + private static Logger logger = Logger.getLogger(PaiXing.class); + public static boolean checkWin(EXPlayer player, int drawCard, List opCardList) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard, player.AEhuXi, true, opCardList, player); + try { + if (win.checkHu()) { + if (win.maxHuXi >= 10 || win.maxHuXi == 2) { + isWin = true; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + if (!isWin) { + player.resetHuXi(); + } + if (isWin) { + player.huXi = win.maxHuXi; + logger.info(player+"��maxHuXi:" + win.maxHuXi); + logger.info("maxOpCard:" + win.maxOpCardToString()); + + player.handCard.clear(); + for (OpCard opcard : win.maxOpCard) { + player.handCard.push(opcard); + } + } + return isWin; + } + public static boolean checkSpecialWin(EXPlayer player, int wanFa) { + boolean quanHei = true, wuXi = false, SiBianDui = false,daYi = false, + daShi = false, xiaoYi = false, xiaoShi = false; + List cardList = new ArrayList(player.cardInhand); + Map cardNumMap = Util.getCardNumMap(cardList); + int duiZiNum = 0, hongDuiNum = 0, fourNum = 0; + for (Entry entry : cardNumMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (num >= 2) { + if (CardUtil.checkHongCard(card)) { + hongDuiNum += 1 ; + } + duiZiNum += 1; + if (card % 100 == 1 && num == 2) { + if (card / 100 == 1) { + xiaoYi = true; + }else { + daYi = true; + } + }else if (card % 100 == 10 && num == 2) { + if (card / 100 == 1) { + xiaoShi = true; + }else { + daShi = true; + } + } + } + } + for (Integer card : cardList) { + if (CardUtil.checkHongCard(card)) { + quanHei = false; + break; + } + } + if (xiaoYi && daYi && xiaoShi && daShi) SiBianDui = true; + wuXi = CardUtil.checkWuXi(cardList); + int bomb = CardUtil.checkHieHongZhaDan(cardList); + player.specialList.add(quanHei ? 1 : 0); + player.specialList.add(wuXi ? 1 : 0); + player.specialList.add(hongDuiNum >= 6 ? 1 : 0); + player.specialList.add(duiZiNum >= 9 ? 1 : 0); + player.specialList.add(SiBianDui ? 1 : 0); + player.specialList.add(fourNum >= 2 ? 1 : 0);// ��ը�� + player.specialList.add(bomb == 2 ? 1 : 0);// ��ը�� + player.specialList.add(bomb == 1 ? 1 : 0);// ��ը�� + boolean result = (quanHei || wuXi || hongDuiNum >= 6 + || duiZiNum >= 9 || SiBianDui || bomb > 0); + return result; + } +} + + + + + + + + diff --git a/game_zp_anxiang/src/main/java/extend/zp/uitl/TingCard.java b/game_zp_anxiang/src/main/java/extend/zp/uitl/TingCard.java new file mode 100644 index 0000000..bb7572a --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/uitl/TingCard.java @@ -0,0 +1,401 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import com.game.Util; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + + +public class TingCard { + private boolean isJiang = false; + private List cardList; + private List cardhand; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int wanfa; + public List maxOpCard; + public int maxHuXi = -1; + public int allHuXi = -1; + private int huxi = 0; + private List opCardList; + + public boolean checkHu() throws ClassNotFoundException, IOException { + boolean existHandCard = this.cardList.size() > 0; + int card = addCard == 0 ? (existHandCard ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else { + maxHuXi = huxi; + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + return maxHuxi(); + } + + private void addCheckTyCardList(List opmty, List opaty, List tyCardList) { + tyCardList.addAll(cardList); + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + tyCardList.add(opCard.card1); + tyCardList.add(opCard.card2); + tyCardList.add(opCard.card3); + } + } + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_WEI && opCard.huXi < 5) { + opaty.add(opCard.card1); + }else if (opCard.type == RuleWeight.TYPE_PONG && opCard.huXi < 5) { + opmty.add(opCard.card1); + } + } + } + + private int changeHuXi(List tempOpCardList, List opCards, int totalHuXi, int huXi, int card) { + for (OpCard opCard : opCards) { + if ((opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_PONG) + && opCard.card1 == card) { + totalHuXi += huXi - opCard.huXi; + opCard.huXi = huXi; + return totalHuXi; + } + } + for (OpCard opCard : tempOpCardList) { + if ((opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_PONG) + && opCard.card1 == card) { + totalHuXi += huXi - opCard.huXi; + opCard.huXi = huXi; + } + } + return totalHuXi; + } + + + private boolean maxHuxi() { + List tempCardList = new ArrayList<>(), opmty = new ArrayList<>(), + opaty = new ArrayList<>(), tyCardList = new ArrayList<>(); + boolean hu; + addCheckTyCardList(opmty, opaty, tyCardList); + for (List opCards : this.lastOpCard) { + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + List mty = new ArrayList<>(), aty = new ArrayList<>(), tempTyCardList = new ArrayList<>(tyCardList); + mty.addAll(opmty); + aty.addAll(opaty); + List tempOpCardList = new ArrayList<>(this.opCardList); + boolean isZhuanWan = false; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + for (OpCard opCard : opCards) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + if (opCard.card1 == tempOpCard.card1 || opCard.card2 == tempOpCard.card1 + || opCard.card3 == tempOpCard.card1) { + tempOpCard.huXi = tempOpCard.huXi == 0 ? 2 : 3; + isZhuanWan = true; + break; + } + } + } + if (!isZhuanWan) { + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + if (opCard.card1 == tempOpCard.card1 || opCard.card2 == tempOpCard.card1 + || opCard.card3 == tempOpCard.card1) { + tempOpCard.huXi = tempOpCard.huXi == 0 ? 2 : 3; + isZhuanWan = true; + break; + } + } + } + } + }else if (tempOpCard.type == RuleWeight.TYPE_PONG) { + mty.add(tempOpCard.card1); + Util.removeCard(tempTyCardList, tempOpCard.card1, 3); + }else if (tempOpCard.type == RuleWeight.TYPE_KAN) { + aty.add(tempOpCard.card1); + Util.removeCard(tempTyCardList, tempOpCard.card1, 3); + } + huxi += tempOpCard.huXi; + } + if (tempCardList.size() == 0) { + hu = true; + for (Integer anCard : aty) { + if (tempTyCardList.contains(anCard)) { + huxi = changeHuXi(tempOpCardList, opCards, huxi, CardUtil.checkHongCard(anCard) ? 8 : 6, anCard); + } + } + for (Integer mingCard : mty) { + if (tempTyCardList.contains(mingCard)) // ����Բ + huxi =changeHuXi(tempOpCardList, opCards, huxi, CardUtil.checkHongCard(mingCard) ? 7 : 5, mingCard); + } + } + if (hu) { + if (huxi == 2 && (this.wanfa != 0 ) && !isZhuanWan ) { + List allOpCard = new ArrayList<>(); + allOpCard.addAll(opCardList); + allOpCard.addAll(opCards); + if (CardUtil.checkManYuanHua(allOpCard)) + return true; + }else { + if (huxi >= 10) + return true; + } + } + } + return false; + } + + + private boolean pair(List cards) { + if (cards.size() == 2) { + if (CardUtil.cardNum(cards.get(0), cards) == 2) { + return true; + } + } + return false; + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard != null) { + + } + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + + return true; + + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + //shunzi2710(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, tempList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + if (card%100 == 2 || card%100 == 7 || card%100 == 10) { + opCard.huXi = 2; + } + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int type = card == this.addCard ? RuleWeight.TYPE_WEI : RuleWeight.TYPE_KAN; + int huxi = CardUtil.getCardGroupHuxi(card, type, this.opCardList); + OpCard opCard = new OpCard(type, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "102, 103, 101, 105, 105, 108, 109, 110, 203, 201, 206, 207, 208"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List currentOpCardList = new ArrayList(); + currentOpCardList.add(new OpCard(RuleWeight.TYPE_PONG, 202, 202, 202, 3)); + currentOpCardList.add(new OpCard(RuleWeight.TYPE_PONG, 209, 209, 209, 2)); + + TingCard winCard2 = new TingCard(list, 202, 5, true, currentOpCardList, 0); + System.out.println(winCard2.checkHu()); + System.out.println(winCard2.maxOpCardToString()); + + } + + public String maxOpCardToString() { + StringBuffer sb = new StringBuffer(); + for (OpCard opCard : maxOpCard) { + if (opCard.type == RuleWeight.TYPE_JIANG) { + sb.append("jiangcard:" + opCard.card1 + " "); + sb.append(opCard.card2); + sb.append(",huxi=" + opCard.huXi + " | "); + } else { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3); + sb.append(",huxi=" + opCard.huXi + " | "); + } + } + return sb.toString(); + } + + + public TingCard(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList, int wf) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(); + this.maxOpCard = new ArrayList<>(); + this.opCardList = new ArrayList<>(); + this.cardhand = new ArrayList<>(); + this.cardList.addAll(cardInhand); + this.cardhand.addAll(cardInhand); + this.opCardList.addAll(opCardList); + this.wanfa = wf; + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + } + +} diff --git a/game_zp_anxiang/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_anxiang/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..f16a1d0 --- /dev/null +++ b/game_zp_anxiang/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,452 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import com.game.Util; + +import extend.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + + +public class WinCard { + private boolean isJiang = false; + private List cardList; + private List cardhand; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private EXPlayer player; + public List maxOpCard; + public int maxHuXi = -1; + public int allHuXi = -1; + private int huxi = 0; + private List opCardList; + + public boolean checkHu() throws ClassNotFoundException, IOException { + + boolean existHandCard = this.cardList.size() > 0; + int card = addCard == 0 ? (existHandCard ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else { + maxHuXi = huxi; + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + return maxHuxi(); + } + + private void addCheckTyCardList(List opmty, List opaty, List tyCardList) { + tyCardList.addAll(cardList); + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + tyCardList.add(opCard.card1); + tyCardList.add(opCard.card2); + tyCardList.add(opCard.card3); + } + } + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_WEI && opCard.huXi < 5) { + opaty.add(opCard.card1); + }else if (opCard.type == RuleWeight.TYPE_PONG && opCard.huXi < 5) { + opmty.add(opCard.card1); + } + } + } + + private int changeHuXi(List tempOpCardList, List opCards, int totalHuXi, int huXi, int card) { + for (OpCard opCard : opCards) { + if ((opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_PONG) + && opCard.card1 == card) { + totalHuXi += huXi - opCard.huXi; + opCard.huXi = huXi; + return totalHuXi; + } + } + for (OpCard opCard : tempOpCardList) { + if ((opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_PONG) + && opCard.card1 == card) { + totalHuXi += huXi - opCard.huXi; + opCard.huXi = huXi; + } + } + return totalHuXi; + } + + private void checkKan() { + List tempCardList = new ArrayList<>(); + List> OpCardList = new ArrayList<>(); + for (List opCards : this.lastOpCard) { + tempCardList.clear(); + tempCardList.addAll(cardList); + boolean chi = false , pong = false; + for (OpCard tempOpCard : opCards) { + if (tempOpCard.type == RuleWeight.TYPE_CHOW && (tempOpCard.card1 == addCard || + tempOpCard.card2 == addCard || tempOpCard.card3 == addCard)) { + chi = true; + }else if (tempOpCard.type == RuleWeight.TYPE_PONG && tempOpCard.card1 == addCard) { + pong = true; + } + removeOpCard(tempCardList, tempOpCard); + } + if (tempCardList.size() == 0 && chi && pong) { + List opCard = new ArrayList<>(); + for (OpCard tempOpCard : opCards) { + if (tempOpCard.type == RuleWeight.TYPE_PONG && tempOpCard.card1 == addCard) { + opCard.add(new OpCard(RuleWeight.TYPE_KAN, addCard, addCard, + addCard, CardUtil.checkHongCard(addCard) ? 4 : 3)); + }else { + opCard.add(tempOpCard); + } + } + OpCardList.add(opCard); + } + } + if (OpCardList.size() > 0 ) + this.lastOpCard.addAll(OpCardList); + } + + + private boolean maxHuxi() { + List tempCardList = new ArrayList<>(), opmty = new ArrayList<>(), + opaty = new ArrayList<>(), tyCardList = new ArrayList<>(); + boolean hu; + addCheckTyCardList(opmty, opaty, tyCardList); + checkKan(); + for (List opCards : this.lastOpCard) { + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + List mty = new ArrayList<>(), aty = new ArrayList<>(), tempTyCardList = new ArrayList<>(tyCardList); + mty.addAll(opmty); + aty.addAll(opaty); + List tempOpCardList = new ArrayList<>(this.opCardList); + boolean isZhuanWan = false; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + for (OpCard opCard : opCards) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + if (opCard.card1 == tempOpCard.card1 || opCard.card2 == tempOpCard.card1 + || opCard.card3 == tempOpCard.card1) { + tempOpCard.huXi = tempOpCard.huXi == 0 ? 2 : 3; + isZhuanWan = true; + break; + } + } + } + if (!isZhuanWan) { + for (OpCard opCard : opCardList) { + if (opCard.type == RuleWeight.TYPE_CHOW) { + if (opCard.card1 == tempOpCard.card1 || opCard.card2 == tempOpCard.card1 + || opCard.card3 == tempOpCard.card1) { + tempOpCard.huXi = tempOpCard.huXi == 0 ? 2 : 3; + isZhuanWan = true; + break; + } + } + } + } + }else if (tempOpCard.type == RuleWeight.TYPE_PONG) { + mty.add(tempOpCard.card1); + Util.removeCard(tempTyCardList, tempOpCard.card1, 3); + }else if (tempOpCard.type == RuleWeight.TYPE_KAN) { + aty.add(tempOpCard.card1); + Util.removeCard(tempTyCardList, tempOpCard.card1, 3); + } + huxi += tempOpCard.huXi; + } + if (tempCardList.size() == 0) { + hu = true; + for (Integer anCard : aty) { + if (tempTyCardList.contains(anCard)) { + huxi = changeHuXi(tempOpCardList, opCards, huxi, CardUtil.checkHongCard(anCard) ? 8 : 6, anCard); + } + } + for (Integer mingCard : mty) { + if (tempTyCardList.contains(mingCard)) + huxi = changeHuXi(tempOpCardList, opCards, huxi, CardUtil.checkHongCard(mingCard) ? 7 : 5, mingCard); + } + } + if (hu) { + if (huxi == 2 && (this.player.getRoom().config.getInt(Config.ROOM_CONFIG_WANFA) != 0 ) && !isZhuanWan) { + List allOpCard = new ArrayList<>(); + allOpCard.addAll(opCardList); + allOpCard.addAll(opCards); + if (CardUtil.checkManYuanHua(allOpCard)) { + player.huXi = huxi; + int caclWin = player.getRoom().caclWin(player, player.seat == player.getRoom().draw); + if (allHuXi < caclWin) { + allHuXi = caclWin; + maxHuXi = huxi; + this.maxOpCard.clear(); + this.maxOpCard.addAll(opCards); + } + } + }else { + player.handCard.clear(); + for (OpCard opcard : opCards) { + player.handCard.push(opcard); + } + if (huxi >= 10) { + player.huXi = huxi; + int caclWin = player.getRoom().caclWin(player, player.seat == player.getRoom().draw); + if (allHuXi < caclWin) { + allHuXi = caclWin; + maxHuXi = huxi; + this.maxOpCard.clear(); + this.maxOpCard.addAll(opCards); + } + } + } + } + } + return this.maxOpCard.size() > 0; + } + + + private boolean pair(List cards) { + if (cards.size() == 2) { + if (CardUtil.cardNum(cards.get(0), cards) == 2) { + return true; + } + } + return false; + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard != null) { + + } + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + + return true; + + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + //shunzi2710(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, tempList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + if (card%100 == 2 || card%100 == 7 || card%100 == 10) { + opCard.huXi = 2; + } + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int type = card == this.addCard ? RuleWeight.TYPE_PONG : RuleWeight.TYPE_KAN; + int huxi = CardUtil.getCardGroupHuxi(card, type, this.opCardList); + OpCard opCard = new OpCard(type, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "107, 110, 110, 110"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + WinCard winCard2 = new WinCard(list, 107, 10, true, new ArrayList(), null); + + System.out.println(winCard2.checkHu()); + System.out.println(winCard2.maxOpCardToString()); + System.out.println(winCard2.maxHuXi); + + } + + public String maxOpCardToString() { + StringBuffer sb = new StringBuffer(); + for (OpCard opCard : maxOpCard) { + if (opCard.type == RuleWeight.TYPE_JIANG) { + sb.append("jiangcard:" + opCard.card1 + " "); + sb.append(opCard.card2); + sb.append(",huxi=" + opCard.huXi + " | "); + } else { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3); + sb.append(",huxi=" + opCard.huXi + " | "); + } + } + return sb.toString(); + } + + public WinCard(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList, EXPlayer owner) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(); + this.maxOpCard = new ArrayList<>(); + this.opCardList = new ArrayList<>(); + this.cardhand = new ArrayList<>(); + this.cardList.addAll(cardInhand); + this.cardhand.addAll(cardInhand); + this.opCardList.addAll(opCardList); + this.player = owner; + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + } + +} diff --git a/game_zp_changdepaohuzi/.idea/compiler.xml b/game_zp_changdepaohuzi/.idea/compiler.xml new file mode 100644 index 0000000..7ab05ba --- /dev/null +++ b/game_zp_changdepaohuzi/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/.idea/encodings.xml b/game_zp_changdepaohuzi/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_zp_changdepaohuzi/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/.idea/jarRepositories.xml b/game_zp_changdepaohuzi/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_zp_changdepaohuzi/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/.idea/misc.xml b/game_zp_changdepaohuzi/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_zp_changdepaohuzi/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/.idea/vcs.xml b/game_zp_changdepaohuzi/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/game_zp_changdepaohuzi/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/config/game-config.xml b/game_zp_changdepaohuzi/config/game-config.xml new file mode 100644 index 0000000..800b818 --- /dev/null +++ b/game_zp_changdepaohuzi/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.3.7 + 192.168.3.7 + 8811 + 8990 + 15 + true + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/config/log4j.properties b/game_zp_changdepaohuzi/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_changdepaohuzi/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_changdepaohuzi/config/taurus-core.xml b/game_zp_changdepaohuzi/config/taurus-core.xml new file mode 100644 index 0000000..6562b02 --- /dev/null +++ b/game_zp_changdepaohuzi/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_changdepaohuzi/config/taurus-permanent.xml b/game_zp_changdepaohuzi/config/taurus-permanent.xml new file mode 100644 index 0000000..9cdaab3 --- /dev/null +++ b/game_zp_changdepaohuzi/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_changdepaohuzi/pom.xml b/game_zp_changdepaohuzi/pom.xml new file mode 100644 index 0000000..4468d38 --- /dev/null +++ b/game_zp_changdepaohuzi/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_changdepaohuzi + game_zp_changdepaohuzi + 1.0.0 + jar + game_zp_changdepaohuzi + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_changdepaohuzi_zipai + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/Config.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..01e8b50 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/Config.java @@ -0,0 +1,89 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 15; + + public static final String GAME_MODE = "mode"; + + public static final String GAME_TUN = "tun"; + + public static final String GAME_FENGDING = "fengding"; + + public static final String GAME_TUANYUAN = "tuanyuan"; + + public static final String GAME_HANGHANGXI = "hanghangxi"; + + public static final String GAME_SHUAHOU = "shuahou"; + + public static final String GAME_HUANGFAN = "huangfan"; + + public static final String GAME_JIAXINGXING = "jiaxingxing"; + + public static final String GAME_TINGHU = "tinghu"; + + public static final String GAME_SIQI = "siqi"; + + public static final String GAME_DUIZIFU = "duizifu"; + + public static final String GAME_YUAN = "yuan"; + + public static final String GAME_BEIKAOBEI = "back"; + + public static final String GAME_TIANHU = "tianhu"; + + public static final String GAME_DIHU = "dihu"; + + public static final String GAME_HAIHU = "haihu"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + 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 int ANCHOU_SCORE = 10; + + + // 1.��ׯ 2.��ׯ + // public static final String GAME_ZHUANG = "zhuang"; + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXActionEvent.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..ee5df29 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,27 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXGameController.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..a1729b2 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,311 @@ +package extend.zp; + +import java.util.Collections; +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.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; + + +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + public EXGameController() { + super(); + } + + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender,ITObject params,int gid,Player owner) { + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player, params); + } + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + 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 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.getRoom().getPlayBack().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(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + +// if (2 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 102, 102, 103, 103, 109, 201, 201, 202, 202, 203, 203, 204, 204, 204, 206, 207, 208, 209, 210"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (3 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 101, 201, 201, 202, 202, 203, 203, 103, 104, 105, 106, 204, 207, 207, 107, 208, 209, 110, 110"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (1 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "102, 103, 103, 104, 104, 104, 107, 107, 107, 108, 110, 201, 202, 204, 205, 205, 206, 206, 206, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } + + Collections.sort(player.cardInhand); + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + player.cardInhand); + } +// owner.card.cardList.clear(); +// String cardStr = "210, 105, 101, 209, 106, 203, 109, 109, 204, 109, 108, 207, 110, 103, 203, 201, 107, 106, 110, 201, 210, 208, 101, 201, 105, 210, 205, 102, 108, 208, 105, 108, 102, 207, 202, 103, 106, 210, 202, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// owner.card.cardList.add(card); +// } + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + logger.info(param.toString()); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("xipai_score", owner.xi_pai_score); + //mp.putInt("anchou_score", owner.an_chou_score); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.huXi); + param.putInt("tun", player.winScore); + player.hp_info(param); + if (owner.maxPlayers == 2) { + param.putInt("total_tun", player.score.round_score); + } else { + param.putInt("total_tun", player.score.round_score / 2); + } + + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + + if (player.winer == 1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + cardList.addTObject(obj); + } + param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + ITArray opCardList = TArray.newInstance(); + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); + param.putInt("win_count", player.winCount); + param.putInt("total_score", player.score.total_score); + player.hp_info(param); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + if (!dissmiss) { + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXMainServer.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..c88c4c0 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,96 @@ +package extend.zp; + +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.zp.player.rulestate.PRChiState; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerPreDrawState; +import extend.zp.player.state.EXPlayerWaitState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + + Global.registerState(PRTiState.class, new PRTiState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXPlayer.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..b9f9c70 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,256 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.zp.player.rule.RuleChi; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public Stack handCard; + public List handCardEx; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashSet chouPongSet; + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public List mingtangList; + + public int kongCount = 0; + public int tiCount = 0; + // ��Ϣ + public int huXi = 0; + + public int total_huxi = 0; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", this.cardInhand.size()); + playerData.putInt("score", this.score.total_score); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (!self) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI) { + continue; + } + } else { + if (opCard.type == RuleWeight.TYPE_KAN) { + continue; + } + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 0; + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + } + + public void clear() { + this.cardInhand.clear(); + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.kongCount = 0; + this.tiCount = 0; + this.huXi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.tiGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouPongSet.clear(); + this.mingtangList.clear(); + this.score.resetRound(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + return card.getKey(); + } + } + return 0; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + if (this.cardInhand.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + // ���� + if (this.chouChiSet.contains(eventCard)) { + return false; + } + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + return false; + } + + ChowCard chow = new ChowCard(this.cardInhand, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + } + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXRoom.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..b4cdf91 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1236 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +import com.game.Global; +import com.game.Router; +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.*; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCard; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; + public boolean isTianHu = true; + public boolean isDiHu = true; + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public int typeface = 1; + + public ITObject paiXing; + public int adminSeat; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + 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_ANCHOU_SCORE)) + { + this.config.putFloat(Config.ROOM_CONFIG_ANCHOU_SCORE, 0); + this.an_chou_score = 1; + }else { + this.an_chou_score = this.config.getInt(Config.ROOM_CONFIG_ANCHOU_SCORE); + }*/ + + if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI)) + { + this.config.putBoolean(Config.ROOM_CONFIG_XIPAI, false); + } + this.adminSeat = 0; + } + + public void changePaiXing(EXPlayer player, ITObject params) { + ITArray paixing = null; + try { + paixing = params.getTArray("card_list"); + } + catch(Exception e) + { + + } + + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < paixing.size(); i++) + { + TDataWrapper card = paixing.get(i); + TObject map = (TObject)card.getObject(); + tmpCardList.add(map.getInt("card")); + } + + Collections.sort(tmpCardList); + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(player.cardInhand); + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + } + } + Collections.sort(tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2)) + { + ITObject param = new TObject(); + player.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + + paiXing.putTArray(player.seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", player.seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(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); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat == player.seat) { + self = true; + } + info_list.addTObject(tempPlayer.getReloadInfo(self)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + + player.score.round_score += score; + player.score.total_score += score; + } + + public void addScore(EXPlayer destPlayer) { + int score = caclScore(destPlayer); + //先判断分够不够 + int tmp_all_score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + if (!entry.getKey().equals(destPlayer.playerid)) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + tmp_all_score += reMultipleScore((int)fromPlayer.hp.cur_hp); + this.addScore(fromPlayer, -reMultipleScore((int)fromPlayer.hp.cur_hp), EXScore.WIN); + }else { + tmp_all_score += score; + this.addScore(fromPlayer, -score, EXScore.WIN); + } + } + } + // + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + this.addScore(destPlayer, tmp_all_score, EXScore.WIN); + } + } + + //// +// for (Entry entry : this.playerMapById.entrySet()) { +// if (entry.getKey().equals(destPlayer.playerid)) { +// if (this.maxPlayers == 2) { +// this.addScore(destPlayer, score, EXScore.WIN); +// } else { +// this.addScore(destPlayer, score * 2, EXScore.WIN); +// } +// } else { +// EXPlayer fromPlayer = (EXPlayer) entry.getValue(); +// this.addScore(fromPlayer, -score, EXScore.WIN); +// } +// } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 0; + int huXiNum = 0; + boolean isDuzi = true; + int huangFan = 0; + if (!player.handCardEx.isEmpty()) { + isDuzi = false; + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (opCard.type == 2) { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + isDuzi = false; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (opCard.type == RuleWeight.TYPE_CHOW) { + isDuzi = false; + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + player.mingtangList.clear(); + player.winFan = 0; + player.huXi = huXi; + player.total_huxi += huXi; + player.winScore = (huXi - 15) / 3 + 1; + + int score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (!player.isMingTang) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + if (player.seat == this.bankerSeat) { + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } else { + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + player.winFan += 6; + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 + redCard - 10; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 5; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 3; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + } else if (player.room.config.getInt(Config.GAME_MODE) == 3) { + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + + return score; + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 + redCard - 10; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 5; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 3; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���Ӻ� + if (isDuzi) { + if (this.config.getInt(Config.GAME_MODE) == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 8)); + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (this.config.getInt(Config.GAME_DUIZIFU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } else { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } + // ���� + if (this.winSeat == player.seat) { + player.winScore += 1; + player.mingtangList.add(new MingTang(RuleWeight.ZI_MO, 2, 1)); + } + // ȫ���� + if (this.config.getInt(Config.GAME_MODE) == 1) { + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } + // �غ� + else { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + } + // ���� + if (this.card.getCount() == 0) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 6)); + } + // ���� + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + if (player.isTingHu) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 6)); + } + } + // ��� + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + // С�� + if (smallCard >= 16) { + int fan = 10 + smallCard - 16; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + // ����Բ + if (this.config.getInt(Config.GAME_TUANYUAN) == 1) { + int duan = 0; + for (int i = 1; i <= 10; i++) { + int num = 0; + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + if (opCard.card1 % 100 == i) { + num++; + } + } + if (num == 2) { + duan++; + } + } + if (duan > 0) { + int fan = duan * 8; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_TUAN_YUAN, 1, fan)); + } + } + // ����Ϣ + if (this.config.getInt(Config.GAME_HANGHANGXI) == 1) { + if (huXiNum == 7) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 8)); + } + } + // ������Ϣ + if (this.config.getInt(Config.GAME_JIAXINGXING) == 1) { + if ((player.tiCount + player.kongCount) > 0) { + if (huXiNum == 6) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.JIA_XING_XING, 1, 4)); + } + } + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + // ˣ�� + if (this.config.getInt(Config.GAME_SHUAHOU) == 1) { + if (player.kanGroup.isEmpty() && player.cardInhand.size() == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.SHUA_HOU, 1, 8)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // Բ + if (this.config.getInt(Config.GAME_YUAN) == 1) { + List cardList = new ArrayList<>(); + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + cardList.add(opCard.card1); + } + if (!cardList.isEmpty()) { + Collections.sort(cardList); + int yuan = 0; + int num = cardList.get(0); + for (int i = 1; i < cardList.size(); i++) { + if (num + 1 == cardList.get(i)) { + yuan++; + } + num = cardList.get(i); + } + if (yuan > 0) { + int fan = yuan * 6; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.YUAN, 1, fan)); + } + } + } + // ������ + if (this.config.getInt(Config.GAME_BEIKAOBEI) == 1) { + boolean kezi1 = false; + boolean kezi2 = false; + boolean isBeiKaoBei = true; + for (OpCard opCard : player.handCard) { + if (opCard.type == 1) { + if (opCard.card1 != player.winCard && opCard.card1 % 100 == player.winCard % 100) { + kezi1 = true; + continue; + } + break; + } else { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + if (opCard.card1 == player.winCard || opCard.card2 == player.winCard || opCard.card3 == player.winCard) { + isBeiKaoBei = false; + break; + } + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (isBeiKaoBei) { + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_WEI && opCard.type != RuleWeight.TYPE_CHOUWEI && opCard.type != RuleWeight.TYPE_KAN) { + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (kezi1 && kezi2) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.BEI_KAO_BEI, 1, 8)); + } + } + } + // ���෬ + if (this.config.getInt(Config.GAME_MODE) == 3) { + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } + // �غ� + else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + } + // ���� + if (this.config.getInt(Config.GAME_HAIHU) == 1) { + if (this.card.getCount() == 0) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 4)); + } + } + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + // ���� + if (player.isTingHu) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 4)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 3) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 300); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 4) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 500); + } + } + + return score; + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + // public void settleRound() { + // saveMilitaryRound(playBackData.getData(this)); + // if (this.liuju == true) { + // this.bankerSeat = this.playerMapBySeat.get(this.bankerSeat).nextSeat; + // } + // boolean total = this.round >= this.maxRound; + // int result = this.nonNegative(false); + // if (!total) { + // EXMainServer.gameCtr.roomResult(this); + // if (result == 4) { + // total = true; + // this.saveMilitaryTotal(false); + // } + // } else { + // this.saveMilitaryTotal(false); + // } + // this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + // this.winCount = 0; + // + // if (total) { + // this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + // return; + // } + // } + + public void win(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + player.winCard = player.getRoom().drawCard; + } + player.winer = 1; + int scoreSrc = caclScore(player); + if (player.handCard.isEmpty()) { + scoreSrc = 0; + } + player.resetHuXi(); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + + Stack handCard = new Stack(); + List handCardEx = new ArrayList<>(); + handCard.addAll(player.handCard); + handCardEx.addAll(player.handCardEx); + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (activePlayer.drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.pongGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] pongGroup = new int[3]; + pongGroup[0] = activePlayer.drawCard; + pongGroup[1] = activePlayer.drawCard; + pongGroup[2] = activePlayer.drawCard; + + player.pongGroup.add(pongGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (activePlayer.drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.kanGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] kanGroup = new int[3]; + kanGroup[0] = activePlayer.drawCard; + kanGroup[1] = activePlayer.drawCard; + kanGroup[2] = activePlayer.drawCard; + + player.kanGroup.add(kanGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (activePlayer.drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.weiGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] weiGroup = new int[3]; + weiGroup[0] = activePlayer.drawCard; + weiGroup[1] = activePlayer.drawCard; + weiGroup[2] = activePlayer.drawCard; + + player.weiGroup.add(weiGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + } + this.addScore(player); + // this.liuju = false; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(player.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + EXMainServer.gameCtr.winEvent(player, player.seat); + // if (owner.room.config.getInt(Config.GAME_ZHUANG) == 1) { + // if (room.bankerSeat != owner.seat) { + // room.bankerSeat = owner.lastSeat; + // } + // } else { + // room.bankerSeat = owner.seat; + // } + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + } + + @Override + public void endGame() { + super.endGame(); + } + + + public void saveRecRound() { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.saveRecRound(); + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + } + // public void destroy() { + // super.destroy(); + // } + + /** + * 开启倍数后 体力值消耗= 倍数*分数 + */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/EXScore.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/MingTang.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..82b8723 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,13 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; + public int score; + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/OpCard.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..bbd5df6 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,35 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + public boolean pailie; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = false; + } + + public OpCard(int type, int card1, int card2, int card3, int huXi, boolean pailei) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = pailei; + } + + public OpCard() { + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayBack.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..74f6ad7 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..86ffaef --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,121 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.RuleChi; +import extend.zp.player.rule.RuleDealKan; +import extend.zp.player.rule.RuleDealTi; +import extend.zp.player.rule.RuleDiscardPao; +import extend.zp.player.rule.RuleDrawChi; +import extend.zp.player.rule.RuleDrawPao; +import extend.zp.player.rule.RuleDrawPong; +import extend.zp.player.rule.RuleKan; +import extend.zp.player.rule.RulePong; +import extend.zp.player.rule.RuleTi; +import extend.zp.player.rule.RuleWei; +import extend.zp.player.rule.RuleWin; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + drawPaoList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List otherHuList = new ArrayList(); + otherHuList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/RoomCard.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..abe4238 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,104 @@ +package extend.zp; + +import java.util.*; + +public class RoomCard { + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + this.subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + +// private void initCard2() { +// List list = Arrays.asList(102, 103, 105, 106, 106, 107, 108, 108, 109, 110, 110, 110, 110, 201, 202, 207, 209, 209, 210, 210); +// List list2 = Arrays.asList(101, 101, 104, 104, 105, 107, 107, 109, 201, 201, 203, 203, 203, 203, 204, 206, 207, 208, 209, 210); +// List list3 = Arrays.asList(205, 106, 108, 208, 209, 105, 106, 206, 102, 105, 104, 108, 102, 107, 202, 106, 206, 202, 104, 204, 102, 108, 208, 207, 208, 205, 205, 201, 202, 101, 103, 206, 103, 209, 208, 210, 102, 105, 109, 108); +// +// this.cardList.addAll(list2); +// this.cardList.addAll(list); +// this.cardList.addAll(list3); +// } + + private void shuffle() { + for(int i = 0;i < 100;i++) { + Collections.shuffle(this.cardList); + } + } + + public int pop() { + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/RuleWeight.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..49e19fa --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,45 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10; + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; + public final static int WU_HU = 2; + public final static int DIAN_HU = 3; + public final static int DUIZI_HU = 4; + public final static int TIAN_HU = 5; + public final static int DI_HU = 6; + public final static int HAI_HU = 7; + public final static int TING_HU = 8; + public final static int DA_HU = 9; + public final static int XIAO_HU = 10; + public final static int DA_TUAN_YUAN = 11; + public final static int XING_XING_XI = 12; + public final static int SI_QI_HONG = 13; + public final static int SHUA_HOU = 14; + public final static int HUANG_FAN = 15; + public final static int ZI_MO = 16; + public final static int JIA_XING_XING = 17; + public final static int HONG_WU = 18; + public final static int YUAN = 19; + public final static int BEI_KAO_BEI = 20; +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..c2f74ac --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,29 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..5fb46b6 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,75 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 2 && card == player.drawCard) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + } + if (num == 3) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..3a22847 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 3) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..c3a82db --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,54 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..f33f88f --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,32 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..5b33794 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..b2fa1cc --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,55 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..df87829 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..0ad7640 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java new file mode 100644 index 0000000..96cb028 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java @@ -0,0 +1,56 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRTiState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..9084b70 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,34 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleWei implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..5fffee6 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,48 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isLaoYe) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + if (Paixing.checkWin(player, activePlayer.drawCard)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..6c91519 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,66 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +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 extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + + public static void prChi(int card, EXPlayer owner) { + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + __chow(owner, chowcard1, chowcard2, card, activePlayer, false); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + if (bi) { + CardUtil.removeCard(player.cardInhand, card, 1); + } + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..ed30148 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,42 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + + +public class PRChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..96900b8 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,98 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..7441809 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,41 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + +public class PRDrawChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java new file mode 100644 index 0000000..2710a3e --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java @@ -0,0 +1,106 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDrawPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + int fromseat = activePlayer.seat; + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..8478789 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,81 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRDrawPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + CardUtil.removeCard(owner.cardInhand, card, 2); + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..3274942 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,82 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + CardUtil.removeCard(owner.cardInhand, card, 2); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + this.toNextState(owner); + ; + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java new file mode 100644 index 0000000..46ebf74 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java @@ -0,0 +1,85 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRTiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + int card = owner.opCard.getInt(0); + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.tiGroup.add(tiGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..b834338 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,77 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + int card = owner.opCard.getInt(0); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + owner.weiGroup.add(weiGroup); + + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..7050ece --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,38 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + room.win(owner, activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..dc571a9 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,53 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..9cedf04 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,141 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.getRoom().tipMap.clear(); + if (owner.cardInhand.isEmpty()) { + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + logger.info("discard,player:" + owner + ",card:" + discard); + if (owner.seat == owner.room.bankerSeat) { + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + owner.outcardExList.add(discard); + exit(owner); + EXMainServer.gameCtr.outCard(owner, discard); + + owner.getRoom().isDiHu = false; + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + } else { + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().isAllPass) { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..81a0368 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,433 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } + else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else { + Global.logger.info("dealcards playerid:"+owner.playerid+ " general player"); + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + } + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..1f4e455 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,52 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..48344a0 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,109 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.Paixing; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.isAllPass = false; + owner.drawCard = room.card.pop(); + // owner.drawCard = 110; + + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + int drawCard = owner.drawCard; + owner.drawCard = 0; + owner.getRoom().isTianHu = false; + if (drawCard != 0) { + owner.cardInhand.add(drawCard); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } else { + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, owner.getRoom().drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + boolean win = false; + for (Entry entry : owner.getRoom().playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer player = (EXPlayer) entry.getValue(); + if(Paixing.checkWin(player, owner.drawCard)) { + win = true; + } + } + if(!win) + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..af786e1 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,40 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..c3abb79 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..a64e58c --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,54 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + // + owner.bankerSeat = 1; + } + EXMainServer.gameCtr.dealCard(owner); + Boolean qupaiV = owner.config.getBoolean(Config.ROOM_CONFIG_QUPAI); + boolean qupai = (qupaiV == null) ? false : qupaiV; + if (owner.maxPlayers == 2 && qupai) { + for (int index = 0; index < 20; index++) { + owner.throwCardsList.add(owner.card.pop()); + } + } + // owner.isplaying = true; + // owner.round += 1; + owner.playBackData = new PlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..32697d3 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,35 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + // TODO Auto-generated method stub + //owner.readyCount = 0; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + } + // if (owner.round == 0) { + owner.startGame(); + // } + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + // TODO Auto-generated method stub + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Action.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Tip.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/TipManager.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..852e597 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,179 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.RuleWeight; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + public int getUid(){ + return this.uid; + } + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass discardtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7608fca --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..976354f --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + } + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + result = handle(list,bi_card,bi_card) || result; + } + if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + result = handle(list,eventCard,bi_card) || result; + CardUtil.addCard(eventCard, cardMap, 1); + } + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..b1d1a40 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,151 @@ +package extend.zp.uitl; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class Paixing { + public static boolean checkWin(EXPlayer player, int drawCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (win.tryWin(player)) { + if (player.huXi >= 15) { + isWin = true; + } + } + if (!isWin) { + player.resetHuXi(); + if (player.getRoom().isTianHu) { + if (player.tiCount >= 3) { + player.isMingTang = false; + isWin = true; + } + if (player.kanGroup.size() >= 5) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 1 && player.kanGroup.size() >= 4) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 2 && player.kanGroup.size() >= 3) { + player.isMingTang = false; + isWin = true; + } + } + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + } + } + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + for (int i = 0; i < win.stack.size(); i++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(i).get(0); + opcard.card2 = win.stack.get(i).get(1); + opcard.type = 1; + if (win.stack.get(i).size() > 2) { + opcard.card3 = win.stack.get(i).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(i); + + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + + } + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 9; + } else { + huXi = 12; + } + break; + case RuleWeight.TYPE_PAO: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 6; + } else { + huXi = 9; + } + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + case RuleWeight.TYPE_KAN: + case RuleWeight.TYPE_CHOW: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 3; + } else { + huXi = 6; + } + break; + case RuleWeight.TYPE_PONG: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 1; + } else { + huXi = 3; + } + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..4de2c60 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,328 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard && player.getRoom().bankerSeat == player.seat) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + } + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.tiCount + player.kongCount > 0) { + if (this.pair_count == 1) { + return true; + } + return false; + } else { + if (this.pair_count > 0) { + return false; + } + return true; + } + } + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..aea44ac --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,381 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCardNew winCard2 = new WinCardNew(list, 106, 9, true, op); + /* op = winCard2.groupCard(207); */ + System.out.println(winCard2.checkHu()); + winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + + } + + /** + * + * @param cardInhand + * :����,�������� + * @param addCard + * : �Ӵ����Ƿ��ܺ���������������������Ҫ��0 + * @param huxi + * ��������еĺ�Ϣ + * @param isJiang + * ���Ƿ���Ҫ�� + */ + public WinCardNew(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + } +} diff --git a/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_changdepaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_changdepaohuzi/src/test/java/game_zp_changdepaohuzi/Main.java b/game_zp_changdepaohuzi/src/test/java/game_zp_changdepaohuzi/Main.java new file mode 100644 index 0000000..3fd68c6 --- /dev/null +++ b/game_zp_changdepaohuzi/src/test/java/game_zp_changdepaohuzi/Main.java @@ -0,0 +1,9 @@ +package game_zp_changdepaohuzi; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_zp_fangpaofa/.idea/compiler.xml b/game_zp_fangpaofa/.idea/compiler.xml new file mode 100644 index 0000000..4a81e37 --- /dev/null +++ b/game_zp_fangpaofa/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/deployment.xml b/game_zp_fangpaofa/.idea/deployment.xml new file mode 100644 index 0000000..61a4476 --- /dev/null +++ b/game_zp_fangpaofa/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/encodings.xml b/game_zp_fangpaofa/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_zp_fangpaofa/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/jarRepositories.xml b/game_zp_fangpaofa/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_zp_fangpaofa/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/misc.xml b/game_zp_fangpaofa/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_zp_fangpaofa/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/sshConfigs.xml b/game_zp_fangpaofa/.idea/sshConfigs.xml new file mode 100644 index 0000000..5a227ed --- /dev/null +++ b/game_zp_fangpaofa/.idea/sshConfigs.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/uiDesigner.xml b/game_zp_fangpaofa/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/game_zp_fangpaofa/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/vcs.xml b/game_zp_fangpaofa/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/game_zp_fangpaofa/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/.idea/webServers.xml b/game_zp_fangpaofa/.idea/webServers.xml new file mode 100644 index 0000000..4e56dc2 --- /dev/null +++ b/game_zp_fangpaofa/.idea/webServers.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/config/game-config.xml b/game_zp_fangpaofa/config/game-config.xml new file mode 100644 index 0000000..bb438de --- /dev/null +++ b/game_zp_fangpaofa/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.3.9 + 192.168.3.9 + 8017 + 8917 + 17 + true + \ No newline at end of file diff --git a/game_zp_fangpaofa/config/log4j.properties b/game_zp_fangpaofa/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_fangpaofa/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_fangpaofa/config/taurus-core.xml b/game_zp_fangpaofa/config/taurus-core.xml new file mode 100644 index 0000000..66501c3 --- /dev/null +++ b/game_zp_fangpaofa/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_fangpaofa/config/taurus-permanent.xml b/game_zp_fangpaofa/config/taurus-permanent.xml new file mode 100644 index 0000000..6661fdd --- /dev/null +++ b/game_zp_fangpaofa/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_fangpaofa/pom.xml b/game_zp_fangpaofa/pom.xml new file mode 100644 index 0000000..e06f1d3 --- /dev/null +++ b/game_zp_fangpaofa/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_fangpaofa + game_zp_fangpaofa + 1.0.0 + jar + game_zp_fangpaofa + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_fangpaofa_zipai + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/Config.java b/game_zp_fangpaofa/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..94adfe2 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/Config.java @@ -0,0 +1,93 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 17; + + public static final String GAME_MODE = "mode";//0:百息,1局数 + + public static final String GAME_SHOUPAI = "shoupai"; //手牌 0:20张, 1:14张 + public static final String GAME_CHOUPAI = "choupai";//抽牌 0:20张 1:10张,2:不抽牌 + public static final String GAME_HUNUM = "hunum";//胡息算法 1 15胡息,10胡 + + public static final String GAME_DANIAO = "daniao";//打鸟 0不打,1:10,2:20,3:50 + + public static final String GAME_TIANDIHU = "tiandihu";//天地胡 + + public static final String GAME_HONGHU = "honghu"; + + public static final String GAME_SHISANHONG = "shisanhong"; + + public static final String GAME_WUHU = "wuhu"; + + public static final String GAME_YIDIANHONG = "yidianhong"; + + public static final String GAME_YIKUAIBIAN = "yikuaibian"; + + public static final String GAME_HAIDIHU = "haidihu"; + + public static final String GAME_KAHU = "kahu"; + + public static final String GAME_MINGWEI = "mingwei"; + + public static final String GAME_FENGDING = "fengding"; + + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + + public static final String GAME_EVT_FANGPAO_TIP = "822"; //放跑提示 + + public static final String GAME_EVT_FANGPAO = "823"; //确定放跑 + + public static final String GAME_EVT_FANGPAO_RSP = "824"; //放跑回复 + + public static final String GAME_NIAO = "831"; + + public static final String GAME_EVT_DANIAO_TIP = "832"; + + public static final String GAME_EVT_DANIAO = "833";//action + + + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXActionEvent.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..5d9b6b7 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,29 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + public static final String EVENT_DA_NIAO = "da_niao"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXGameController.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..60be87a --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,439 @@ +package extend.zp; + +import java.util.Collections; +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.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; + + +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + public EXGameController() { + super(); + } + + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender,ITObject params,int gid,Player owner) { + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player, params); + } + + + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + 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 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.getRoom().getPlayBack().addGetCardCommand(player.room.activeSeat, player.drawCard, leftCount); + } + + + @ActionKey(Config.GAME_EVT_FANGPAO) + public void RouterFangwei(Session sender,ITObject params,int gid,Player owner){ + EXPlayer player = (EXPlayer) owner; + int discard = params.getInt("card"); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + response.putInt("card", discard); + logger.info("jefe GAME_EVT_FANGPAO:" + discard+";player:"+player.playerid); + owner.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + player.banChiPeng = true; + EXRoom room = player.getRoom(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + + //回复放跑成功 + ITObject param = new TObject(); + param.putInt("card", discard); + param.putInt("seat", player.seat); + player.sendEvent(Config.GAME_EVT_FANGPAO_RSP, param); + + } + + + public void outCard(EXPlayer player, int discard) { + //判断是否 放跑 + //1 获取当前房间的wei + int outflag = 0; + if (player.getRoom().weiRoomGroup.size()>0){ + //2 遍历偎 + for (int i = 0; i < player.getRoom().weiRoomGroup.size(); i++) { + if (discard == player.getRoom().weiRoomGroup.get(i)[0]) { + //3,如果存在 提示放跑 + //判断是否是托管 + + if (!player.isEntrust()){ + EXMainServer.gameCtr.fangPaoTipEvent(player,0,discard); + outflag = 1; + } + + } + } + } + + if (outflag==0){ + 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(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + CardUtil.removeCard(player.cardInhand, discard, 1); + + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + //放跑不能吃碰等 + + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + + Collections.sort(player.cardInhand); + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + player.cur_huxi = 0; + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + player.cardInhand); + } + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + + /** + * @param owner + */ + public void fangPaoTipEvent(EXPlayer owner,int reload,int card) { + ITObject response = new TObject(); + response.putInt("card", card); + response.putInt("reload", reload); + response.putInt("seat", owner.seat); + ////System.outln("niao"); + owner.sendEvent(Config.GAME_EVT_FANGPAO_TIP, response); + } + + + /** + * @param owner + */ + public void daNiaoTipEvent(EXPlayer owner,int reload) { + ITObject response = new TObject(); + response.putInt("niao", owner.room.config.getInt(Config.GAME_DANIAO)); + response.putInt("reload", reload); + ////System.outln("niao"); + owner.sendEvent(Config.GAME_EVT_DANIAO_TIP, response); + } + + /** + * @param owner + * 打鸟事件 + */ + public void daNiaoEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("niao", owner.niaoValue*owner.daNiao); + ////System.outln("daniao 回复"+owner.daNiao); + owner.getRoom().daniaoflag = owner.getRoom().daniaoflag+1; + owner.room.broadCastToClient(0, Config.GAME_EVT_DANIAO, param); + } + + /** + * @param owner + * 放跑协议事件 + */ + public void sendFangPaoEvent(EXPlayer owner) { + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("pao", owner.daNiao); + ////System.outln("fangpao 回复"+owner.daNiao); + owner.room.broadCastToClient(0, Config.GAME_EVT_FANGPAO, param); + } + + @ActionKey(Config.GAME_NIAO) + public void RouterNiao(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_DA_NIAO, 0, params); + } + + public void sendNiaoEvt(EXPlayer owner, int seat) { + EXRoom room = owner.getRoom(); + ITObject param = new TObject(); + ITArray array = new TArray(); + param.putInt("start_seat", seat); + + room.broadCastToClient(0, Config.GAME_EVT_DANIAO, param); + ((PlayBack)room.playBackData).addNiaoCommand(owner.seat, param); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + + owner.getRoom().getPlayBack().addTipActionCommand(owner.room.activeSeat, param); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + public ITObject getRoomResultData(EXRoom owner) { + //System.out.println("getRoomResultData"); + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("xipai_score", owner.xi_pai_score/100); + //mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + + ////System.out.println("getRoomResultData:::"); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + + //累计后 + + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.cur_huxi); + param.putInt("tun", player.winScore); + + player.hp_info(param); + + + param.putInt("round_score", player.score.round_score); //当前分数 + param.putInt("fangpaoscore", player.getRoom().fangpaosubvalue); //当前分数 + param.putInt("total_score", player.total_huxi); //单局 累计战绩 + + player.huType = 1; + if (player.getRoom().isFanPao){ + player.huType = 2; + } + param.putInt("hu_type", player.huType); //胡牌类型 + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + ITArray opCardList = TArray.newInstance(); + if (player.winer == 1&&player.newcalc==1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + cardList.addTObject(obj); + //opCardList.addTObject(obj); + } + // param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + + if (player.tmpopCardList.size()>0){ + for (OpCard opCard : player.tmpopCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + }else { + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + //System.out.println("Fule roomResult"); + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + //总结算 + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + //System.out.println("roomTotalResult"); + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + ////System.out.println("roomTotalResult:"+dissmiss); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); //当前胡息 + param.putInt("win_count", player.winCount); + int niaofen = player.niaoValue*player.daNiao; + //player.score.total_score = player.score.total_score + niaofen; + + param.putInt("total_score", player.score.total_score);//总战绩 + + ////System.out.println("niaoscore:"+player.niaoValue*player.daNiao); + player.hp_info(param); + param.putInt("hupai_count", player.hupai_count); //胡次数 + param.putInt("dianpao_count", player.dianpao_count); //点炮次数 + param.putInt("tipai_count", player.tipai_count); //提牌总数 + param.putInt("paopai_count", player.paopai_count); //跑牌总数 + + param.putInt("niaoscore",niaofen); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + //if (!dissmiss) { + ITObject result = getRoomResultData(owner); + ////System.out.println(result); + mp.putTObject("result", result); + //} + + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXMainServer.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..975bd41 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,94 @@ +package extend.zp; + +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.zp.player.rulestate.PRChiState; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.*; +import extend.zp.room.state.EXRoomDaNiaoState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomDaNiaoState.class, new EXRoomDaNiaoState()); + //Global.registerState(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + Global.registerState(EXPlayerDaNiaoTipState.class,new EXPlayerDaNiaoTipState()); + + Global.registerState(PRTiState.class, new PRTiState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXPlayer.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..12c65ee --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,315 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.zp.player.rule.RuleChi; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public List tmpopCardList; + + public Stack handCard; + public List handCardEx; + + public boolean paozihu = false; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashSet chouPongSet; + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public boolean ispengchiwin = false; + public boolean guohupao = false; + public List mingtangList; + public List mingtangListtmp;//临时 + + public int kongCount = 0; + public int tiCount = 0; + + public boolean isPaotohu = false; + // ��Ϣ + public int huXi = 0; + + public int cur_huxi = 0; + public int total_huxi = 0; //总胡息 + + + public int daNiao = 0; //是否打鸟 + + public int niaoValue = 0; //鸟分数 + + public int pao = 0; //放炮状态 + + public boolean popaohu = false; + + + public int huType = 0; //胡牌类型1,胡,2:点炮 + + public int bupaicount = 0; + + public boolean banChiPeng = false; //放跑禁吃碰 + + public boolean paoqiflag = false; + + + public int hupai_count = 0; + public int dianpao_count = 0; + public int tipai_count = 0; + public int paopai_count = 0; + + + public int newcalc = 0; + + public boolean checkguohu = false; + + public boolean huipaoflag = false; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + tmpopCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + mingtangListtmp = new ArrayList<>(); + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(self); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", this.cardInhand.size()); + //playerData.putInt("score", this.score.total_score); + playerData.putInt("score",this.total_huxi); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + playerData.putInt("total_score",this.total_huxi); + + playerData.putInt("niaoValue",this.niaoValue*this.daNiao); + ////System.out.println(this.playerid); + ////System.out.println(this.daNiao); + ////System.out.println(this.niaoValue); + ////System.out.println(playerData); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (!self) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI) { + continue; + } + } else { + if (opCard.type == RuleWeight.TYPE_KAN) { + continue; + } + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 0; + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + } + + public void clear() { + this.cardInhand.clear(); + this.popaohu = false; + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.ispengchiwin = false; + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.paozihu = false; + this.kongCount = 0; + this.tiCount = 0; + this.newcalc = 0; + this.bupaicount = 0; + this.huXi = 0; + //this.total_huxi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.banChiPeng = false; + this.tiGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.tmpopCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouPongSet.clear(); + this.mingtangList.clear(); + this.mingtangListtmp.clear(); + this.score.resetRound(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + return card.getKey(); + } + } + return 0; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + if (this.cardInhand.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + // ���� + if (this.chouChiSet.contains(eventCard)) { + return false; + } + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + return false; + } + + ChowCard chow = new ChowCard(this.cardInhand, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + } + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXRoom.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..ed0c4a1 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1443 @@ +package extend.zp; + +import java.util.*; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.data.Hp; +import com.game.data.Player; +import com.game.data.Room; +import com.game.player.state.PlayerWaitState; +import com.game.room.state.RoomDestoryGameState; +import com.game.room.state.RoomEndState; +import com.taurus.core.entity.*; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.Logger; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCard; +import extend.zp.uitl.WinCardNew; +import redis.clients.jedis.Jedis; + +public class EXRoom extends Room { + Logger logger = Logger.getLogger(getClass()); + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; // 过牌 + public boolean isTianHu = true; // 天胡是否 + public boolean isDiHu = true; // 地胡 + + public boolean isFanPao = false; + + public int tiandiflag = 0; + + public int baiXi = 0; + + public boolean pingju = false; + + public boolean yikuaibianflag = false; + public boolean yikuaibiandes = false; + + public int daNiaoCount = 0; + + public int fangpaosubvalue = 0;// 放炮扣除的分数 + + public boolean endflag = false; + + public boolean endrecord = false; + public int daniaoflag = 0; // 当前是否参与打鸟事件 + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public List roomoutcardlist; + + public List paochucardlist; + + public int typeface = 1; + public boolean endsendflag = false; + + public List weiRoomGroup; // 记录当前已经偎过的牌 为了确定放跑 + + public ITObject paiXing; + public int adminSeat; + + public boolean jiesanflag = false; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.weiRoomGroup = new ArrayList<>(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.roomoutcardlist = new ArrayList<>(); + this.paochucardlist = new ArrayList<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI_SCORE)) { + this.config.putFloat(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); + } + this.adminSeat = 0; + } + + public void changePaiXing(EXPlayer player, ITObject params) { + ITArray paixing = null; + try { + paixing = params.getTArray("card_list"); + } catch (Exception e) { + + } + + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for (int i = 0; i < paixing.size(); i++) { + TDataWrapper card = paixing.get(i); + TObject map = (TObject) card.getObject(); + tmpCardList.add(map.getInt("card")); + } + + Collections.sort(tmpCardList); + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(player.cardInhand); + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + } + } + Collections.sort(tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2)) { + // ITObject param = new TObject(); + // player.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + // return; + } + + paiXing.putTArray(player.seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", player.seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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() { + //// System.out.println("isWeightestAction"); + if (this.isAllPass()) { + return true; + } + if (this.actionList.size() == 0) { + return false; + } + Action curaction = this.actionList.get(0); + //// System.out.println("isWeightestAction2"); + for (Entry entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState + || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(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); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat == player.seat) { + self = true; + } + info_list.addTObject(tempPlayer.getReloadInfo(self)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + player.score.round_score += score; + player.score.total_score += score; + } + + public void finalsettle() { + int winid = 0; + int maxCount = 0;// 最大赢家分 + int otherCount = 0; // 输家 + int allniaofen = 0; // 总鸟分 + int tmp_all_score = 0; + + int[] tmparrs = { 0, 0 }; + int i = 0; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmparrs[i] = player.total_huxi; + allniaofen = allniaofen + player.niaoValue * player.daNiao; + } + Arrays.sort(tmparrs); + maxCount = tmparrs[1]; + otherCount = tmparrs[0]; + + // 四舍五入 + double maxc = 0; + maxc = (double) maxCount / 10; + maxCount = (int) Math.round(maxc) * 10; + double maxo = 0; + if (otherCount < 0) { + maxo = (double) -otherCount / 10L; + otherCount = -(int) Math.round(maxo) * 10; + } else { + maxo = (double) otherCount / 10L; + otherCount = (int) Math.round(maxo) * 10; + } + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + + if (player.playerid == winid) { + // 加分 + if (maxCount < otherCount + 10) { + this.pingju = true; + // 平局 + player.score.round_score = 0;// allniaofen*this.hpData.getInt("times"); + player.score.total_score = 0;// allniaofen*this.hpData.getInt("times"); + // player.score.round_log.put(EXScore.WIN, + // player.score.round_log.get(EXScore.WIN) + player.score.round_score); + player.hp.total_hp = 0;// allniaofen*this.hpData.getInt("times"); + } else { + player.score.round_score = (maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + player.score.total_score = (maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + player.score.round_log.put(EXScore.WIN, + player.score.round_log.get(EXScore.WIN) + player.score.round_score); + player.hp.total_hp = (maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + } + + } else { + // 输分 + if (maxCount < otherCount + 10) { + // player.score.round_log.put(EXScore.WIN, + // player.score.round_log.get(EXScore.WIN) -(maxCount - otherCount + + // allniaofen)); + player.score.round_score = 0;// - allniaofen*this.hpData.getInt("times"); + player.score.total_score = 0;// -allniaofen*this.hpData.getInt("times"); + player.hp.total_hp = 0;// -allniaofen*this.hpData.getInt("times"); + } else { + player.score.round_log.put(EXScore.WIN, + player.score.round_log.get(EXScore.WIN) - (maxCount - otherCount + allniaofen)); + player.score.round_score = -(maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + player.score.total_score = -(maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + player.hp.total_hp = -(maxCount - otherCount + allniaofen) * this.hpData.getInt("times"); + } + + } + } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 0; + int huXiNum = 0; + int huangFan = 0; + int kuaibiannum = 0; + int checkbn = 0; + boolean mingtangflag = false; + // 结算 + if (!player.handCardEx.isEmpty()) { + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.isRedCard(opCard.card3) && opCard.card3 != 0) { + redCard++; + } + if (opCard.type == 2) { + + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + if (CardUtil.isRedCard(opCard.card2) && CardUtil.isRedCard(opCard.card1)) { + kuaibiannum++; + } + + if (CardUtil.isRedCard(opCard.card2) || CardUtil.isRedCard(opCard.card1) + || CardUtil.isRedCard(opCard.card3)) { + checkbn++; + } + + } + + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (opCard.type == RuleWeight.TYPE_CHOW) { + + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.isRedCard(opCard.card1) && CardUtil.isRedCard(opCard.card2) + && CardUtil.isRedCard(opCard.card3)) { + kuaibiannum++; + } + if (CardUtil.isRedCard(opCard.card1) || CardUtil.isRedCard(opCard.card2) + || CardUtil.isRedCard(opCard.card3)) { + checkbn++; + } + + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN + || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + kuaibiannum++; + checkbn++; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + kuaibiannum++; + checkbn++; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN + || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN + || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + + player.mingtangList.clear(); + player.winFan = 1; + int score = 0; + + if (this.isTianHu) { + // 天胡 + if (player.seat == this.bankerSeat) { + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 100)); + } else { + // 地胡 + this.isDiHu = true; + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + } + // 判断房间是否有出牌 + + if (player.getRoom().roomoutcardlist.size() == 1 && player.outcardList.size() == 0) { + if (player.getRoom().activeCard == player.getRoom().roomoutcardlist.get(0)) { + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + } + if (this.isTianHu || this.isDiHu) { + + } else { + // 看看十三红 + if (redCard >= 13) { + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.SHISANHONG_HU, 1, 100)); + } + + // 乌胡 + if (redCard == 0) { + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, 100)); + } + + // 红胡 + if (redCard >= 10 && redCard < 13) { + player.winFan = player.winFan * 2; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 2, 2)); + } + + // 一点朱 + if (redCard == 1) { + player.winFan = player.winFan * 2; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 2, 2)); + } + // 一块扁 + if (kuaibiannum == 1 && redCard >= 2 && redCard <= 4 && checkbn == 1) { + player.winFan = player.winFan * 2; + this.yikuaibiandes = true; + player.mingtangList.add(new MingTang(RuleWeight.YIKUAIBIAN_HU, 2, 2)); + } + + // 30胡 + if (huXi == 30) { + mingtangflag = true; + player.mingtangList.add(new MingTang(RuleWeight.KA30_HU, 1, 100)); + } + + // 20胡 + if (huXi == 20) { + player.winFan = player.winFan * 2; + player.mingtangList.add(new MingTang(RuleWeight.KA20_HU, 2, 2)); + } + + // 海底胡 + if (this.card.getCount() == 0 && !this.isFanPao) { + player.winFan = player.winFan * 2; + player.mingtangList.add(new MingTang(RuleWeight.HAIDI_HU, 2, 2)); + } + + // 自摸 + if (this.winSeat == player.seat && player.ispengchiwin == false && !this.isFanPao) { + player.winFan = player.winFan * 2; + player.mingtangList.add(new MingTang(RuleWeight.ZI_MO, 2, 2)); + } + } + + if (player.mingtangList.size() > 0) { + if (mingtangflag) { + for (MingTang mingTang : player.mingtangList) { + if (mingTang.type == 1) { + // 计算息 + score = score + mingTang.score; + } + } + } + } + if (mingtangflag) { + if (player.winFan > 0) { + score = score * player.winFan; + } + } else { + if (player.winFan > 0) { + score = huXi * player.winFan; + } else { + score = huXi; + } + } + + if (this.isFanPao) { + this.fangpaosubvalue = score; + } + if (player.winer == 1) { + player.cur_huxi = score; // 当前胡息 + } + + if (this.isFanPao) { + score = Math.min(score, 100); + } else { + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + score = Math.min(score, 200); + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + score = Math.min(score, 400); + } + if (this.config.getInt(Config.GAME_FENGDING) == 3) { + score = Math.min(score, 800); + } + } + + player.winScore = score; + return score; + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + public int caclScoreNew(EXPlayer player, int eventcard, boolean isjiang) { + int huxi = 0; + int tmpscore = 0; + + List huxiScore = new ArrayList<>(); + + WinCardNew winCard2 = new WinCardNew(player.cardInhand, eventcard, huxi, isjiang, player.opCardList); + if (winCard2.checkHu()) { + + if (winCard2.opCardsList.size() == 0) { + return 0; + } + List> st = new ArrayList<>(); + // 计算名堂 + player.mingtangListtmp.clear(); + int okop = 0; + for (int i = 0; i < winCard2.opCardsList.size(); i++) { + int score = 0; + int redCard = 0; + int kuaibiannum = 0; + this.yikuaibianflag = false; + if (winCard2.opCardsList.size() > 0) { + for (int j = 0; j < winCard2.opCardsList.get(i).size(); j++) { + OpCard tmpopcard = winCard2.opCardsList.get(i).get(j); + + huxi += tmpopcard.huXi; + if (CardUtil.isRedCard(tmpopcard.card1)) { + if (tmpopcard.type == RuleWeight.TYPE_JIANG) { + redCard = redCard + 2; + kuaibiannum++; + } + if (tmpopcard.type == RuleWeight.TYPE_TI || tmpopcard.type == RuleWeight.TYPE_PAO) { + redCard = redCard + 4; + kuaibiannum++; + } + if (tmpopcard.type == RuleWeight.TYPE_KAN || tmpopcard.type == RuleWeight.TYPE_CHOUWEI + || tmpopcard.type == RuleWeight.TYPE_WEI + || tmpopcard.type == RuleWeight.TYPE_PONG) { + redCard = redCard + 3; + kuaibiannum++; + } + } + if (tmpopcard.type == RuleWeight.TYPE_CHOW) { + if (CardUtil.isRedCard(tmpopcard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(tmpopcard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(tmpopcard.card3)) { + redCard++; + } + if (CardUtil.isRedCard(tmpopcard.card1) || CardUtil.isRedCard(tmpopcard.card2) + || CardUtil.isRedCard(tmpopcard.card3)) { + kuaibiannum++; + } + } + + // + } + + player.winFan = 1; + List tmpmt = new ArrayList<>(); + boolean mingtangflag = false; + + if (this.isTianHu) { + // 天胡 + if (player.seat == this.bankerSeat) { + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.TIAN_HU, 1, 100)); + } else { + // 地胡 + this.isDiHu = true; + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + } + // 判断房间是否有出牌 + + if (player.getRoom().roomoutcardlist.size() == 1 && player.outcardList.size() == 0) { + if (player.getRoom().activeCard == player.getRoom().roomoutcardlist.get(0)) { + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + } + if (this.isTianHu || this.isDiHu) { + + } else { + // 看看十三红 + if (redCard >= 13) { + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.SHISANHONG_HU, 1, 100)); + } + + // 乌胡 + if (redCard == 0) { + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.WU_HU, 1, 100)); + } + + // 红胡 + if (redCard >= 10 && redCard < 13) { + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.HONG_HU, 2, 2)); + } + + // 一点朱 + if (redCard == 1) { + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.DIAN_HU, 2, 2)); + } + // 一块扁 + if (redCard >= 2 && redCard <= 4 && kuaibiannum == 1) { + this.yikuaibianflag = true; + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.YIKUAIBIAN_HU, 2, 2)); + } + + // 30胡 + if (huxi == 30) { + mingtangflag = true; + tmpmt.add(new MingTang(RuleWeight.KA30_HU, 1, 100)); + } + + // 20胡 + if (huxi == 20) { + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.KA20_HU, 2, 2)); + } + + // 海底胡 + if (this.card.getCount() == 0 && !this.isFanPao) { + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.HAIDI_HU, 2, 2)); + } + + // 自摸 + if (this.winSeat == player.seat && player.ispengchiwin == false && !this.isFanPao) { + player.winFan = player.winFan * 2; + tmpmt.add(new MingTang(RuleWeight.ZI_MO, 2, 2)); + } + } + + if (tmpmt.size() > 0) { + if (mingtangflag) { + for (MingTang mingTang : tmpmt) { + if (mingTang.type == 1) { + // 计算息 + score = score + mingTang.score; + } + } + } + } + if (mingtangflag) { + if (player.winFan > 0) { + score = score * player.winFan; + } + } else { + if (player.winFan > 0) { + score = huxi * player.winFan; + } else { + score = huxi; + } + } + st.add(tmpmt); + + if (tmpscore < score && score > 0) { + okop = i; + tmpscore = score; + player.tmpopCardList = winCard2.opCardsList.get(i); + player.mingtangListtmp.clear(); + player.mingtangListtmp = st.get(i); + } + + huxi = 0; + } + } + + if (tmpscore > 0) { + player.mingtangListtmp = st.get(okop); + } + + st.clear(); + } + + return tmpscore; + } + + // 胜利操作 + public void winnew(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + if (player.winCard == 0) { + player.winCard = player.getRoom().drawCard; + } + } + player.winer = 1; + // 记录小结算 + int scoreSrc = caclScore(player); + if (player.handCard.isEmpty()) { + scoreSrc = 0; + } + player.resetHuXi(); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + // System.out.println("activePlayer.drawCard:"+activePlayer.drawCard); + // 计算胡息 + + Stack handCard = new Stack(); + List handCardEx = new ArrayList<>(); + handCard.addAll(player.handCard); + handCardEx.addAll(player.handCardEx); + + boolean checkpaoflag = false; + + for (int i = 0; i < player.pongGroup.size(); i++) { + + if (activePlayer.drawCard == player.pongGroup.get(i)[0] + && !this.paochucardlist.contains(activePlayer.drawCard)) { + player.kongCount++; + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + checkpaoflag = true; + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.pongGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + if (opcard.card1 == opcard.card2 && opcard.card1 == opcard.card3 + && opcard.card3 == opcard.card2) { + opcard.type = 2; + } + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, + activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] pongGroup = new int[3]; + pongGroup[0] = activePlayer.drawCard; + pongGroup[1] = activePlayer.drawCard; + pongGroup[2] = activePlayer.drawCard; + + player.pongGroup.add(pongGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (activePlayer.drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + checkpaoflag = true; + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.kanGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, + activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + if (opcard.card1 == opcard.card2 && opcard.card1 == opcard.card3 + && opcard.card3 == opcard.card2) { + opcard.type = 2; + } + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, + activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] kanGroup = new int[3]; + kanGroup[0] = activePlayer.drawCard; + kanGroup[1] = activePlayer.drawCard; + kanGroup[2] = activePlayer.drawCard; + + player.kanGroup.add(kanGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (activePlayer.drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + checkpaoflag = true; + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.weiGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, + activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + if (opcard.card1 == opcard.card2 && opcard.card1 == opcard.card3 + && opcard.card3 == opcard.card2) { + opcard.type = 2; + } + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, + activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] weiGroup = new int[3]; + weiGroup[0] = activePlayer.drawCard; + weiGroup[1] = activePlayer.drawCard; + weiGroup[2] = activePlayer.drawCard; + + player.weiGroup.add(weiGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, + activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + } + + // System.out.println("scoreSrc:"); + // 记录小结算 + scoreSrc = caclScore(player); + // System.out.println("scoreSrc:"+scoreSrc); + + // 用于标识一块扁 + int scoreSrcnew = caclScoreNew(player, + checkpaoflag ? 0 : (this.activeCard == 0 ? activePlayer.drawCard : this.activeCard), false); + if (scoreSrcnew == 0) { + scoreSrcnew = caclScoreNew(player, + checkpaoflag ? 0 : (this.activeCard == 0 ? activePlayer.drawCard : this.activeCard), true); + } + if (scoreSrcnew < scoreSrc || scoreSrcnew < 15) { + scoreSrcnew = caclScoreNew(player, + !checkpaoflag ? 0 : (this.activeCard == 0 ? activePlayer.drawCard : this.activeCard), false); + if (scoreSrcnew == 0) { + scoreSrcnew = caclScoreNew(player, + !checkpaoflag ? 0 : (this.activeCard == 0 ? activePlayer.drawCard : this.activeCard), true); + } + } + + if (scoreSrcnew >= 15) { + + player.newcalc = 1; + // if (scoreSrc == 0){ + // scoreSrc = scoreSrcnew; + // player.mingtangList = player.mingtangListtmp; + // } + // if (this.yikuaibiandes==false&&this.yikuaibianflag){ + scoreSrc = scoreSrcnew; + player.mingtangList = player.mingtangListtmp; + // } + // scoreSrc = scoreSrcnew; + // player.mingtangList = player.mingtangListtmp; + player.cur_huxi = scoreSrc; // 当前胡息 + player.opCardList = player.tmpopCardList; + player.handCardEx.clear(); + player.handCard.clear(); + player.cardInhand.clear(); + } else { + for (OpCard opCard : player.handCard) { + player.opCardList.add(opCard); + } + } + + if (this.isFanPao) { + scoreSrc = Math.min(scoreSrc, 100); + } else { + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + scoreSrc = Math.min(scoreSrc, 200); + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + scoreSrc = Math.min(scoreSrc, 400); + } + if (this.config.getInt(Config.GAME_FENGDING) == 3) { + scoreSrc = Math.min(scoreSrc, 800); + } + } + if (this.isFanPao) { + this.fangpaosubvalue = scoreSrc; + } + player.winScore = scoreSrc; + player.cur_huxi = scoreSrc; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + if (fromPlayer.winer == 1) { + fromPlayer.total_huxi = fromPlayer.total_huxi + scoreSrc; + } else { + fromPlayer.winer = 2; + // 如果是放炮,则罚分 + if (this.isFanPao) { + fromPlayer.total_huxi = fromPlayer.total_huxi - scoreSrc; + fromPlayer.cur_huxi = -scoreSrc; + } + } + + } + // 推送胡牌 + EXMainServer.gameCtr.winEvent(player, player.seat); + + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + + } + + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return score / this.hpData.getInt("times"); + } + } + return score; + } + + public void addScoreInto(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) { + if (score <= 0) { + return; + } + if (multipleScore(score) > fromPlayer.hp.cur_hp) { + score = reMultipleScore((int) fromPlayer.hp.cur_hp); + // fromPlayer.hp.cur_hp -= multipleScore(score); //不能在这里扣 + } + + 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; + fromPlayer.score.round_score -= score; + destPlayer.score.total_score += score; + fromPlayer.score.total_score -= score; + + } + + public void finalScore() { + + int winid = 0; + int maxCount = 0;// 最大赢家分 + int otherCount = 0; // 输家 + int allniaofen = 0; // 总鸟分 + int tmp_all_score = 0; + + int[] tmparrs = { 0, 0 }; + int i = 0; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + tmparrs[i] = player.total_huxi; + allniaofen = allniaofen + player.niaoValue * player.daNiao; + i++; + } + Arrays.sort(tmparrs); + maxCount = tmparrs[1]; + otherCount = tmparrs[0]; + // 获取赢家 + if (maxCount == 0 && otherCount == 0) { + return; + } + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.total_huxi == maxCount) { + player.winer = 1; + } + } + // 四舍五入 + double maxc = 0; + maxc = (double) maxCount / 10; + maxCount = (int) Math.round(maxc) * 10; + double maxo = 0; + if (otherCount < 0) { + maxo = (double) -otherCount / 10L; + otherCount = -(int) Math.round(maxo) * 10; + } else { + maxo = (double) otherCount / 10L; + otherCount = (int) Math.round(maxo) * 10; + } + EXPlayer destPlayer = null; + EXPlayer fromPlayer = null; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.winer == 1) { + destPlayer = player; + } else { + fromPlayer = player; + } + } + + this.addScoreInto(destPlayer, fromPlayer, allniaofen + maxCount - otherCount, EXScore.WIN); + } + + public void overHuxi() { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.total_huxi >= 100) { + this.endflag = true; + this.maxRound = this.round; + } + } + } + + public void endGame() { + // this.endflag = this.entrustTotal(); + // 如果是流局则:给庄家-10 + if (this.liuju) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat == this.bankerSeat) { + player.total_huxi = player.total_huxi - 10; + player.cur_huxi = -10; + } else { + player.cur_huxi = 0; + } + } + } + this.overHuxi(); + this.jiesanflag = true; + // this.maxRound = this.round; + + super.endGame(); + if (!this.endrecord) { + updateRecresult(); + } + + } + + /* + * 更新当前记录 + */ + public void updateRecresult() { + // System.out.println("updateRecresult"); + ITArray plist = TArray.newInstance(); + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + TObject pdata; + for (Iterator var10 = this.playerMapBySeat.entrySet().iterator(); var10.hasNext(); plist + .addTObject(pdata)) { + Map.Entry entry = (Map.Entry) var10.next(); + EXPlayer player = (EXPlayer) entry.getValue(); + pdata = TObject.newInstance(); + pdata.putUtfString("nick", player.nick); + if (jiesanflag) { + pdata.putInt("score", player.cur_huxi * 100); + pdata.putInt("hp", player.cur_huxi * 100); + } else { + pdata.putInt("score", 0); + pdata.putInt("hp", 0); + } + // player.cur_huxi = 0; + } + + jedis5.hset(this.military_key, "round_" + this.round, plist.toJson()); + } finally { + jedis5.close(); + } + + } + + public void saveRecRound() { + if (this.getPlayBack() != null) { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + } + + super.saveRecRound(); + + } + + @Override + protected void roomResult() { + // 小结算 + if (!endsendflag) { + endsendflag = true; + EXMainServer.gameCtr.roomResult(this); + } + + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + + this.endrecord = true; + // 桌子结算时候调用 + this.finalScore(); + // 强行解散 + boolean settlement = this.redisUpdateHp(); + // 计算是否有发牌 + boolean isdrawCard = false; + for (Entry entry : this.playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.cardInhand.size() != 0) { + isdrawCard = true; + } + } + if (this.round == 1 && !isdrawCard) { + // 如果第一轮所有玩家没抓牌则不计入记录 + } else { + super.saveMilitaryTotal(dissmiss); + updateRecresult(); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + + } + } + + public PlayBack getPlayBack() { + return (PlayBack) this.playBackData; + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + this.weiRoomGroup.clear(); + this.roomoutcardlist.clear(); + this.paochucardlist.clear(); + + this.isFanPao = false; + this.endflag = false; + this.fangpaosubvalue = 0; + this.yikuaibianflag = false; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/EXScore.java b/game_zp_fangpaofa/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/MingTang.java b/game_zp_fangpaofa/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..8dd25f2 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,15 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; //名堂类型,1:息,2,番,3,倍 + public int score; + + + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/OpCard.java b/game_zp_fangpaofa/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..bbd5df6 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,35 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + public boolean pailie; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = false; + } + + public OpCard(int type, int card1, int card2, int card3, int huXi, boolean pailei) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = pailei; + } + + public OpCard() { + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/PlayBack.java b/game_zp_fangpaofa/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..fe62081 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,115 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + obj.putInt("total_score",player.total_huxi); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addTipActionCommand(int seat,ITObject param){ + addCommand("Tips",seat,param); + } + + public void addNiaoCommand(int seat,ITObject param){ + addCommand("Niao",seat,param); + } + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_fangpaofa/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..6b1c0c4 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,122 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.*; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + // tipMap.put(PlayerRuleManager.DRAW_PAO_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + //otherDrawRuleList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + drawPaoList.add(new RuleDrawPao()); + //drawPaoList.add(new RuleWin()); //如果能胡则跑和胡提示 + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleDrawWin());//放炮 + otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + huList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List otherHuList = new ArrayList(); + //otherHuList.add(new RuleDrawPao()); + otherHuList.add(new RuleWin()); + + //otherHuList.add(new RuleDrawWin());//放炮 + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + if (result) { + if (this.tipMap.get(type)==null){ + + }else{ + player.stateMachine.changeState(this.tipMap.get(type)); + } + + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/RoomCard.java b/game_zp_fangpaofa/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..b80988c --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,493 @@ +package extend.zp; + +import java.util.*; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TObject; +import com.taurus.core.plugin.redis.Redis; +import redis.clients.jedis.Jedis; + +public class RoomCard { + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + + this.subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + //this.sanlong(); + this.initCard(); + this.shuffle(); + this.subCard(); //抽牌 + this.shuffle(); + + //this.testhuxi(); + + //this.guopaokahu(); + //this.checkpaowei(); + //this.guochicard(); + //this.paohuCard(); + // + //this.tieshuPai(); + //this.paohuKazi(); + //this.pengCard(); + //this.xiaohucard(); + //this.tianhuCard(); + //this.ka20Card(); + //this.guopaobuhu(); + //this.ka30Card(); + //this.paohucard2(); + //this.yikuaibian(); + //this.initCard2(); + //this.paoqihu(); + //this.guohuchitech(); + //this.qishouliangti(); + //this.weiqidong(); + //this.yanpai(); + //this.testpai(); + + + } + + public void sanlong(){ + List list = Arrays.asList(103, 102, 103, 103, 105, 105, 105, 105, 110, 110, 110, 202, 203, 204, 205, 205, 207, 208, 208, 209); + List list2 = Arrays.asList(101, 101, 104, 104, 105, 105, 106, 108, 108, 109, 109, 110, 201, 202, 203, 206, 208, 208, 209, 210); + List list3 = Arrays.asList(110, 106, 203, 201, 109, 104, 110, 102, 210, 103, 204, 107, 206, 202, 210, 104, 210, 206, 201, 206); + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + + public void testpai(){ + List list = Arrays.asList(101, 103, 103, 103, 105, 105, 106, 107, 108, 110, 110, 202, 203, 204, 205, 205, 207, 208, 208, 209); + List list2 = Arrays.asList(101, 101, 104, 104, 105, 105, 106, 108, 108, 109, 109, 110, 201, 202, 203, 206, 208, 208, 209, 210); + List list3 = Arrays.asList(207, 106, 203, 201, 109, 104, 110, 102, 210, 103, 204, 107, 206, 202, 210, 104, 210, 206, 201, 206); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + public void testpai2(){ + List list = Arrays.asList(102, 102, 104, 104, 105, 108, 110, 102, 110, 201, 202, 202, 203, 203, 204, 204, 205, 206, 206, 210); + List list2 = Arrays.asList(103, 104, 105, 106, 106, 107, 107, 107, 108, 109, 205, 206, 207, 208, 208, 208, 208, 209, 209, 209); + List list3 = Arrays.asList( 110,203,204, 103,208,104, 209, 206, 207, 206, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void yanpai(){ + List list = Arrays.asList(205,205, 105, 102, 102, 101, 101, 101, 201, 201, 204, 104, 204, 103, 203, 203, 106, 105, 108,110); + List list2 = Arrays.asList(201,201, 202, 202, 203, 203, 204, 204, 105, 205, 206, 206, 207, 207, 208, 208, 209, 209, 210,210); + List list3 = Arrays.asList( 205,205,102,202, 103,104, 203, 204, 205, 206, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void weiqidong(){ + List list = Arrays.asList(101,101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110,110); + List list2 = Arrays.asList(201,201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 206, 207, 207, 208, 208, 209, 209, 210,210); + List list3 = Arrays.asList( 101,210,102,202, 103,104, 203, 204, 205, 206, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void qishouliangti(){ + List list = Arrays.asList(110,202, 202, 203, 110, 103, 204, 204, 205, 205, 205, 106, 107, 107, 207, 203, 205, 110, 110,201); + List list2 = Arrays.asList(105,102, 105, 101, 202, 103, 107, 110, 206, 207, 101, 102, 208, 209, 102, 109, 210, 110, 203,210); + List list3 = Arrays.asList( 201,105,202,208, 105,104, 109, 101, 206, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void guohuchitech(){ + List list = Arrays.asList(110,202, 202, 203, 203, 103, 204, 204, 205, 205, 105, 106, 107, 107, 207, 208, 209, 110, 110,210); + List list2 = Arrays.asList(105,102, 105, 101, 202, 103, 107, 110, 206, 207, 207, 206, 208, 209, 209, 109, 210, 110, 203,210); + List list3 = Arrays.asList( 201,105,202,208, 105,104, 109, 101, 206, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + public void guohuchitech2(){ + List list = Arrays.asList(109,109, 109, 109, 103, 203, 203, 204, 204, 203, 205, 205, 209, 209, 209, 110, 110, 210, 210,210); + List list2 = Arrays.asList(105,102, 105, 101, 102, 103, 107, 110, 206, 207, 207, 206, 208, 209, 209, 109, 210, 110, 203,210); + List list3 = Arrays.asList( 201,105,202,208, 105,104, 109, 101, 206, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void paoqihu(){ + List list = Arrays.asList(101,102, 103, 201, 202, 203, 205, 105, 106, 206, 107, 107, 207, 207, 110, 109,108,208, 209,210); + List list2 = Arrays.asList(101,102, 201, 201, 201, 103, 103, 203, 204, 204, 104, 106, 106, 207, 207, 108, 110, 210, 209,208); + List list3 = Arrays.asList( 205,109,206, 107,104, 205, 102, 101, 107, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void paoqihu2(){ + List list = Arrays.asList(208,208, 207, 107, 107, 104, 105, 106, 202, 207, 210, 102, 102, 103, 110, 110,202,202, 206,203); + List list2 = Arrays.asList(101,102, 103, 101, 102, 103, 107, 110, 206, 207, 207, 206, 208, 209, 209, 109, 210, 110, 203,210); + List list3 = Arrays.asList( 101,110,102,103, 206,104, 109, 101, 206, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void checkpaowei(){ + List list = Arrays.asList(103,101, 201, 202, 203, 104, 104, 204, 204, 204, 105, 105, 106, 206, 107, 110, 207, 210, 109,109); + List list2 = Arrays.asList(101,103, 201, 203, 202, 205, 106, 106, 206, 207, 207, 107, 208, 209, 209, 109, 110, 110, 210,210); + List list3 = Arrays.asList( 204,104,203,201, 201,104, 109, 101, 206, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105); + + this.cardList.addAll(list); + this.cardList.addAll(list2); + this.cardList.addAll(list3); + } + + public void checkhupai(){ + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + String list = jedis5.hget("military_testcheck", "rec_1" ); + TObject data = (TObject) TObject.newFromJsonData(list); + + TObject hand1 = (TObject) data.getTObject("info").getTArray("playerData").getTObject(0); + ITArray list1 =(ITArray) hand1.getTArray("hand_card"); + + TObject hand2 = (TObject) data.getTObject("info").getTArray("playerData").getTObject(1); + ITArray list2 =(ITArray) hand2.getTArray("hand_card"); + + for (int i=0;i 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + //this.shuffle(); + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + return dealCards; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/RuleWeight.java b/game_zp_fangpaofa/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..08c6df4 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,49 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + + public final static int WINPAO = 7; + + public final static int PAO = 8; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10;// + + public final static int TYPE_DIANPAO = 11; //点炮 + + public final static int TYPE_HUANGZHUANG = 12; //荒庄 + + public final static int TYPE_PINGHU = 13;//平胡 + + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; //2番 + public final static int WU_HU = 2; //100胡 + public final static int DIAN_HU = 3; //一点朱 + public final static int SHISANHONG_HU = 4; //十三红 + public final static int TIAN_HU = 5; //天胡 + public final static int DI_HU = 6; //地胡 + public final static int HAIDI_HU = 7;//海底胡 + public final static int YIKUAIBIAN_HU = 8; //一块扁 + public final static int KA20_HU = 9;//卡胡20 + public final static int KA30_HU = 10; //卡胡30 + public final static int ZI_MO = 11;//自摸 + + public final static int HUANG_ZHUANG = 12; +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..37c033f --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,34 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..5fb46b6 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,75 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 2 && card == player.drawCard) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + } + if (num == 3) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..5b28665 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,121 @@ +package extend.zp.player.rule; + +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; + +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 extend.zp.*; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import redis.clients.jedis.Jedis; + + +public class RuleDealTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 3) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + + + } + } + + //判断是否是补牌 + if(player.tiGroup.size()>=2&&player.outcardList.size()==0&&player.bupaicount==0) { + //随机取一张牌 + System.out.println("补牌:"+player.tiGroup.size()); + if (player.tiGroup.size()==2){ + EXRoom room = (EXRoom) player.room; + int drawCard = room.card.cardList.remove(1); + player.cardInhand.add(drawCard); + Collections.sort(player.cardInhand); + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", player.seat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + int leftCount = room.card.getCount(); + param.putInt("left_count", leftCount); + player.room.broadCastToClient(0, Config.GAME_EVT_DRAW, param); + player.getRoom().getPlayBack().addAddCardCommand(player.room.activeSeat, drawCard); + player.bupaicount = player.bupaicount+1; + }else if(player.tiGroup.size()==3){ + for (int i=0;i<2;i++) { + EXRoom room = (EXRoom) player.room; + int drawCard = room.card.cardList.remove(1); + player.cardInhand.add(drawCard); + Collections.sort(player.cardInhand); + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", player.seat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + int leftCount = room.card.getCount(); + param.putInt("left_count", leftCount); + player.room.broadCastToClient(0, Config.GAME_EVT_DRAW, param); + player.getRoom().getPlayBack().addAddCardCommand(player.room.activeSeat, drawCard); + player.bupaicount = player.bupaicount + 1; + } + + } + + + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..bc9a4c9 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,63 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + ////System.out.println("RuleDiscardPao"); + //第一张牌不能跑 + if (player.getRoom().isFanPao){ + return false; + } + + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.paoqiflag = true; + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..c58451a --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,37 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..6ed866a --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,77 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + ////System.out.println("RuleDrawPao"); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0||player.getRoom().roomoutcardlist.size()==0) { + return false; + } + ////System.out.println(player.popaohu); + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..86ec903 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,62 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + ////System.outln("draw碰"); + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + if (player.cardInhand.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawWin.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawWin.java new file mode 100644 index 0000000..3866b50 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleDrawWin.java @@ -0,0 +1,63 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.game.Util; +import com.game.data.Player; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.zp.*; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCardNew; + +import java.util.Map; + + +public class RuleDrawWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isLaoYe) { + return false; + } + EXRoom room = player.getRoom(); + ////System.out.println("RuleDrawWin:"); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + int eventCard = room.activeCard; + activePlayer.drawCard = eventCard; + + if (Paixing.checkWin(player, eventCard)) { + + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + int weight = RuleWeight.WINPAO; + player.winCard = eventCard; + + + Tip tip = new Tip(room.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + player.getRoom().isFanPao = true; + for (Map.Entry entry : player.getRoom().playerMapById.entrySet()) { + EXPlayer rplayer = (EXPlayer) entry.getValue(); + if (rplayer.playerid!=player.playerid){ + rplayer.dianpao_count = rplayer.dianpao_count +1; + } + } + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..df87829 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..75919df --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,62 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + //System.outln("碰"); + //判断是否可以偎 + ////System.out.println("RulePong"); + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + if (player.cardInhand.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleTi.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleTi.java new file mode 100644 index 0000000..48d5d74 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleTi.java @@ -0,0 +1,60 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + + + int eventCard = player.drawCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRTiState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..7d3f9a4 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,38 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleWei implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.getRoom().roomoutcardlist.size()==0&&player.seat!=activePlayer.seat){ + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..0eb1386 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,64 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + ////System.out.println("RuleWin"); + if (player.isLaoYe) { + + return false; + } + + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + + if (player.getRoom().roomoutcardlist.size()==0&&player.seat!=activePlayer.seat){ + return false; + } + if (activePlayer == null) { + return false; + } + + + if (Paixing.checkWin(player, activePlayer.drawCard)) { + player.guohupao = true; + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + player.hupai_count = player.hupai_count + 1; + + player.winCard = activePlayer.drawCard; + return true; + } + + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRCheck.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRCheck.java new file mode 100644 index 0000000..628bbb5 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRCheck.java @@ -0,0 +1,15 @@ +package extend.zp.player.rulestate; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; + +public class PRCheck { + public static final Logger logger = Logger.getLogger(PRCheck.class); + + public static boolean check(EXPlayer owner) { + //判断是否可以吃碰 + return !owner.banChiPeng; + } + + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..5263030 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,70 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +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.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static void prChi(int card, EXPlayer owner) { + ////System.out.println("prchi"); + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + + __chow(owner, chowcard1, chowcard2, card, activePlayer, false); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + if (bi) { + CardUtil.removeCard(player.cardInhand, card, 1); + } + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + logger.info("jefe chowGroup,player:" + player.playerid + ",card1:" + chowcard1+",card2:"+card+",card3:"+chowcard2); + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..838a6a6 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,36 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + + +public class PRChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..1acd24f --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,101 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.*; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + if (!owner.getRoom().isFanPao){ + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + owner.paopai_count = owner.paopai_count + 1; + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + + if (count == 1) { + //EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + //if (owner.tiCount == 2) { + //重跑 + // //owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + //} else { + timer(owner); + //} + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..b388b9e --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,36 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + +public class PRDrawChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + ////System.out.println("drawchi"); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java new file mode 100644 index 0000000..1c41725 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java @@ -0,0 +1,112 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDrawPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + owner.kongCount++; + int fromseat = activePlayer.seat; + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + int count = owner.tiCount + owner.kongCount; + if (count<2&&!owner.guohupao){ + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + }else{ + this.toNextState(owner); + } + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + owner.guohupao = false;//重置 + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + owner.paopai_count = owner.paopai_count + 1; + owner.paoqiflag =true; + + if (count == 1) { + //判断是否能胡牌 1跑出牌 + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + + } else if (count == 2) { + //二跑 不出牌 + timer(owner); + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..3ccbaf4 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,74 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + + */ +public class PRDrawPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + ////System.out.println("PRDrawPongState"); + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + CardUtil.removeCard(owner.cardInhand, card, 2); + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(owner.getRoom().paochucardlist,card,1); + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + owner.ispengchiwin = true; + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.ispengchiwin = false; + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..835fa38 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,78 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + ////System.out.println("PRPongState"); + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + + CardUtil.removeCard(owner.cardInhand, card, 2); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + CardUtil.removeCard(owner.getRoom().paochucardlist,card,1); + this.toNextState(owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRTiState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRTiState.java new file mode 100644 index 0000000..bcb7193 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRTiState.java @@ -0,0 +1,85 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRTiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + int card = owner.opCard.getInt(0); + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.tiGroup.add(tiGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + owner.tipai_count = owner.tipai_count + 1; + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + //if (owner.tiCount == 2) { + // owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + //} else { + timer(owner); + // } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..156c871 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,92 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + int card = owner.opCard.getInt(0); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + + owner.weiGroup.add(weiGroup); + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + if (type==RuleWeight.TYPE_WEI){ + owner.getRoom().weiRoomGroup.add(weiGroup); + } + + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + ////System.out.println("ok1"); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + ////System.out.println("ok2"); + //if (owner.tiCount > 1) { + // owner.tiCount--; + // owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + // owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + //} else { + //timer(owner); + //} + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..638a71a --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,41 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + //System.out.println(activePlayer.drawCard); + room.winnew(owner,activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + //System.out.println("过胡"); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDaNiaoTipState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDaNiaoTipState.java new file mode 100644 index 0000000..ab253f9 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDaNiaoTipState.java @@ -0,0 +1,81 @@ +package extend.zp.player.state; + + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + +/** + * + */ +public class EXPlayerDaNiaoTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.daNiaoTipEvent(owner,0); + } + //owner.stopActionTimer(); + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.daNiaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + + private void _action(EXPlayer owner,int id,int gid) { + //记录打鸟 + if (owner.room.config.getInt(Config.GAME_DANIAO)==1){ + //10分 + owner.niaoValue = 10; + }else if(owner.room.config.getInt(Config.GAME_DANIAO)==2){ + //20分 + owner.niaoValue = 20; + }else if(owner.room.config.getInt(Config.GAME_DANIAO)==3){ + //30分 + owner.niaoValue = 30; + } + owner.daNiao = id; + ////System.out.println(owner.playerid); + ////System.out.println(id); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().daNiaoCount --; + EXMainServer.gameCtr.daNiaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_DA_NIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_DA_NIAO)) { + ITObject netParam = (ITObject) param; + int niaoflag = netParam.getInt("niaoflag"); + _action(owner, niaoflag, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + + } + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..5d8e746 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,55 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + ////System.out.println("discardtip:"); + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..7c3d513 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,152 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.*; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.getRoom().tipMap.clear(); + if (owner.cardInhand.isEmpty()) { + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + ////System.out.println("tonextstate:"+owner.getRoom().isFanPao); + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + //System.outln("discard"); + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + logger.info("discard,player:" + owner + ",card:" + discard); + + ////System.out.println("discard:"); + ////System.out.println(owner.playerid); + if (owner.seat == owner.room.bankerSeat) { + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + owner.outcardExList.add(discard); + exit(owner); + ////System.out.println("discards:"); + owner.getRoom().roomoutcardlist.add(discard); + owner.getRoom().paochucardlist.add(discard); + EXMainServer.gameCtr.outCard(owner, discard); + + owner.getRoom().isDiHu = false; + + + if (owner.getRoom().tipMap.size() != 0) { + ////System.out.println("dddssssssss11111"); + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + } else { + ////System.out.println("dddssssssss1111122"); + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + ////System.out.println("dddssssssss1111122222"); + if (owner.getRoom().isAllPass) { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + ////System.out.println("dddssssssss11111444444"); + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 100, TimeUnit.MILLISECONDS); + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..8f1ead2 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,417 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + + if (owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:" + owner.playerid + " adminseat"); + if (room.while_list) { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) { + Global.logger.info("dealcards playerid:" + owner.playerid + " xingyuhao:" + owner.is_white + " white_value:" + room.white_value); + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else { + if (owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:" + owner.playerid + " white player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else if (owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:" + owner.playerid + " black player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } else { + Global.logger.info("dealcards playerid:" + owner.playerid + " general player"); + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while (true); + room.card.cardList.addAll(tempCardList); + } else { + owner.drawCard = room.card.pop(); + } + } + } + } + + + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + //owner.drawCard = room.card.pop(); + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + /* + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + }*/ + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 500, TimeUnit.MILLISECONDS); + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..c8c85be --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,58 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + ////System.out.println("outs DI enter"); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + ////System.out.println("outs DI exit"); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + + super.execute(owner, cmd, gid, param); + ////System.out.println("outs DI execute"); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ////System.out.println("drawtip:"); + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..0af63ad --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,114 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.Paixing; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.isAllPass = false; + owner.drawCard = room.card.pop(); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + //判断是否可以进行地胡 + ////System.out.println("owner seat:"+owner.seat); + ////System.out.println("owner id:"+owner.playerid); + ////System.out.println("beakseat:"+owner.getRoom().bankerSeat); + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + //EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.OTHER_HU_RULE, owner);//点炮 + + int drawCard = owner.drawCard; + owner.drawCard = 0; + owner.getRoom().isTianHu = false; + ////System.out.println("istianhu "+owner.getRoom().isTianHu); + if (drawCard != 0) { + owner.cardInhand.add(drawCard); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } else { + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, owner.getRoom().drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + boolean win = false; + for (Entry entry : owner.getRoom().playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer player = (EXPlayer) entry.getValue(); + if(Paixing.checkWin(player, owner.drawCard)) { + win = true; + } + } + if(!win) + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..9302374 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,54 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + + if (!owner.isEntrust()) { + _tipEvent(owner); + owner.startActionTimer(); + } else { + owner.startActionTimer(500); + } + + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + protected void _tipEvent(EXPlayer owner) { + + EXMainServer.gameCtr.tipEvent(owner); + } + + protected void _action(EXPlayer owner, int id, int gid) { + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..c3abb79 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDaNiaoState.java b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDaNiaoState.java new file mode 100644 index 0000000..6fdfdec --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDaNiaoState.java @@ -0,0 +1,34 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.zp.*; +import extend.zp.player.state.EXPlayerDaNiaoTipState; + +import java.util.Map.Entry; + +public class EXRoomDaNiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } + owner.daNiaoCount = owner.maxPlayers; + + //owner.playBackData = new PlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerDaNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_DA_NIAO)) { + if(owner.daNiaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..422a41e --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,101 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.zp.*; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + + this.toNextState(owner); + } + + //this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + //owner.bankerSeat = 1; + //随机定庄 + Random random = new Random(); + owner.bankerSeat = random.nextInt(2) + 1; + } + EXMainServer.gameCtr.dealCard(owner); + //System.out.println("isdianpao:"+owner.isFanPao); + + + //if (owner.playBackData==null){ + owner.playBackData = new PlayBack(owner); + //发起返佣开始 + owner.endsendflag = false; + + //} + + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 500, TimeUnit.MILLISECONDS); + } + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..523ba85 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,40 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.Config; +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + // TODO Auto-generated method stub + //owner.readyCount = 0; + //暂停托管 + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + } + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + // TODO Auto-generated method stub + if(owner.config.containsKey(Config.GAME_DANIAO) && owner.config.getInt(Config.GAME_DANIAO) != 0 &&owner.daniaoflag<2) { + owner.stateMachine.changeState(Global.getState(EXRoomDaNiaoState.class)); + }else { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/tip/Action.java b/game_zp_fangpaofa/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_fangpaofa/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/tip/Tip.java b/game_zp_fangpaofa/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/tip/TipManager.java b/game_zp_fangpaofa/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..ce0328a --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,249 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.*; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + public int getUid(){ + return this.uid; + } + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + // + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + + } + this.owner.isMingTang = true; + + + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + "choicAction pass discardtip, id: " + id + " passcard: " + card); + + + //this.owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + //this.owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else if (this.tipMap.containsKey(id)) { + + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + ////System.out.println("typesttteee"); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + //异常下轮 + //owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + Global.logger.info(this.owner + "choicAction pass EXPlayerDiscardState, id: " + id + " passcard: " ); + //EXMainServer.gameCtr.changeActiveSeat(owner.getRoom(), owner.seat); + //this.owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + //throw new Error("tip map has no id" + id); + } + } + + public boolean checkPao(EXPlayer player,int eventCard){ + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + return true; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + + + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + + return true; + } + } + } + return false; + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + + } + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..a4c0462 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,120 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public boolean isBlackCard(int card) { + return card % 100 != 2 && card % 100 != 7 && card % 100 != 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..93c6208 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + } + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + result = handle(list,bi_card,bi_card) || result; + } + if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + result = handle(list,eventCard,bi_card) || result; + CardUtil.addCard(eventCard, cardMap, 1); + } + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + //System.out.println(list); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..db6b881 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,163 @@ +package extend.zp.uitl; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRChi; + + +public class Paixing { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static boolean checkWin(EXPlayer player, int drawCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard); + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + + //原始算法计算 + if (win.tryWin(player)&&!isWin) { + if (player.huXi >= 15) { + isWin = true; + } + } + + if (!isWin) { + player.resetHuXi(); + /*if (player.getRoom().isTianHu) { + if (player.tiCount >= 3) { + player.isMingTang = false; + isWin = true; + } + if (player.kanGroup.size() >= 5) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 1 && player.kanGroup.size() >= 4) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 2 && player.kanGroup.size() >= 3) { + player.isMingTang = false; + isWin = true; + } + }*/ + + + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (drawCard == player.pongGroup.get(i)[0]&&!player.getRoom().paochucardlist.contains(drawCard)) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + } + } + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + for (int i = 0; i < win.stack.size(); i++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(i).get(0); + opcard.card2 = win.stack.get(i).get(1); + opcard.type = 1; + if (win.stack.get(i).size() > 2) { + opcard.card3 = win.stack.get(i).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(i); + + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + + } + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 9; + } else { + huXi = 12; + } + break; + case RuleWeight.TYPE_PAO: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 6; + } else { + huXi = 9; + } + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + case RuleWeight.TYPE_KAN: + case RuleWeight.TYPE_CHOW: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 3; + } else { + huXi = 6; + } + break; + case RuleWeight.TYPE_PONG: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 1; + } else { + huXi = 3; + } + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..4692f22 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,380 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.*; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, CardUtil.cardNum(card, this.cardList)); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard && player.getRoom().bankerSeat == player.seat) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + } + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.tiCount + player.kongCount > 0) { + if (this.pair_count == 1) { + return true; + } + return false; + } else { + if (this.pair_count > 0) { + return false; + } + return true; + } + } + + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + + + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + Map redis_room_map = new HashMap<>(); + + redis_room_map.put("id","749322"); + redis_room_map.put("game","17"); + redis_room_map.put("maxPlayers","2"); + redis_room_map.put("players","[168168,791309]"); + redis_room_map.put("group","532196"); + redis_room_map.put("owner","{user}:123456"); + redis_room_map.put("create_time","1749539730"); + redis_room_map.put("options","{\"tuoguan_active_time\":0,\"daniao\":2,\"pid\":17,\"shoupai\":0,\"honghu\":true,\"yikuaibian\":true,\"tiandihu\":true,\"isvip\":0,\"mode\":1,\"hpData\":{\"limitloot\":0,\"limitInRoom\":0,\"type\":1,\"times\":3000,\"maxRound\":100,\"xipai_rewardType\":3,\"limitPump\":0,\"limitPlay\":1000,\"robot_room\":0,\"basePump\":0,\"anchou_rewardType\":3,\"tex_times_room\":1000,\"rewards_list\":[{\"UpperLimitReward\":0,\"pumpProportion\":0,\"UpperLimit\":0}]},\"kahu\":true,\"maxRound\":100,\"mingwei\":true,\"hp_no_limit\":0,\"isNonnegative\":1,\"wuhu\":true,\"game_id\":17,\"maxPlayers\":2,\"hunum\":0,\"fengding\":1,\"haidiliao\":false,\"tuoguan\":false,\"isHidden\":0,\"xi_pai\":true,\"yidianhong\":true,\"shisanhong\":true,\"tuoguan_active_timeIndex\":1,\"tuoguan_result_type\":0,\"xi_pai_score\":1000,\"choupai\":0}"); + redis_room_map.put("cache_ver","12345"); + redis_room_map.put("times","100"); + redis_room_map.put("pay","2"); + redis_room_map.put("payer","2"); + redis_room_map.put("AA","1"); + redis_room_map.put("agent","true"); + redis_room_map.put("status","1"); + redis_room_map.put("isActive","true"); + redis_room_map.put("opt","1"); + redis_room_map.put("round","1"); + redis_room_map.put("gpid","17"); + redis_room_map.put("open","0"); + redis_room_map.put("kick_time","30"); + redis_room_map.put("seats","[1,2]"); + + ; + EXRoom room = new EXRoom("749322",redis_room_map); + EXPlayer player = new EXPlayer(168168,room,"ddddddd"); + + + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + player.cardInhand = list; + + + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCard win = new WinCard(list, 106); + boolean res = win.tryWin(player); + } + +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..896eddb --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,436 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.*; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public List> opCardsList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWinnew(List cardList) throws ClassNotFoundException, IOException { + + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + opCardsList.add(opCard); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "203,204,205,103,103,103,207,208,209,207,208,209,107,108,109,104,104"; + for (String card : str.split(",")) { + list.add(Integer.parseInt(card)); + } + //List op = new ArrayList(); + //OpCard opCard=new OpCard(RuleWeight.TYPE_TI, 206, 206, 206, 12); + //op.add(opCard); + + //WinCardNew winCard2 = new WinCardNew(list, 0, 0, true, op); + int[] arrs = {0,0}; + + //System.out.println(arrs); + for(int i=0;i<2;i++){ + if (i==0){ + arrs[i] = -190; + }else{ + arrs[i] = 80; + } + //System.out.println(arrs[i]); + } + Arrays.sort(arrs); + int max = arrs[1]; + int oth = arrs[0]; + //System.out.println(max+"==="+oth); + + + /* op = winCard2.groupCard(207); */ + //System.out.println(winCard2.checkHu()); + //winCard2.checkWin(list); + //winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + //System.out.println(winCard2.opCardsList); + + /*int maxCount = 34; + int otherCount = -15; + double maxc = 0; + maxc =(double) maxCount / 10; + maxCount = (int) Math.round(maxc)*10; + double maxo = 0; + if (otherCount<0){ + maxo =(double)-otherCount/10L; + otherCount = -(int) Math.round(maxo)*10; + }else{ + maxo =(double)otherCount/10L; + otherCount = (int) Math.round(maxo)*10; + } + List redcards = new ArrayList<>(); + redcards.add(207); + redcards.add(202); + redcards.add(207); + List tmp = redcards; + int a=0; + int f= 0; + for(int i=0;i cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + this.opCardsList = new ArrayList<>(); + } +} diff --git a/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_fangpaofa/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_fangpaofa/src/test/java/game_zp_fangpaofa/Main.java b/game_zp_fangpaofa/src/test/java/game_zp_fangpaofa/Main.java new file mode 100644 index 0000000..e356711 --- /dev/null +++ b/game_zp_fangpaofa/src/test/java/game_zp_fangpaofa/Main.java @@ -0,0 +1,9 @@ +package game_zp_fangpaofa; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_zp_hspaohuzi/config/game-config.xml b/game_zp_hspaohuzi/config/game-config.xml new file mode 100644 index 0000000..06de7fc --- /dev/null +++ b/game_zp_hspaohuzi/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 127.0.0.1 + 192.168.1.213 + 4050 + 8803 + 14 + true + \ No newline at end of file diff --git a/game_zp_hspaohuzi/config/log4j.properties b/game_zp_hspaohuzi/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_hspaohuzi/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_hspaohuzi/config/taurus-core.xml b/game_zp_hspaohuzi/config/taurus-core.xml new file mode 100644 index 0000000..ecb4a54 --- /dev/null +++ b/game_zp_hspaohuzi/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_hspaohuzi/config/taurus-permanent.xml b/game_zp_hspaohuzi/config/taurus-permanent.xml new file mode 100644 index 0000000..6547939 --- /dev/null +++ b/game_zp_hspaohuzi/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_hspaohuzi/pom.xml b/game_zp_hspaohuzi/pom.xml new file mode 100644 index 0000000..1475a69 --- /dev/null +++ b/game_zp_hspaohuzi/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_hspaohuzi + game_zp_hspaohuzi + 1.0.0 + jar + game_zp_hspaohuzi + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_zp_hspaohuzi + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/Config.java b/game_zp_hspaohuzi/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..4f69b44 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/Config.java @@ -0,0 +1,84 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 14; + + public static final String GAME_MODE = "mode"; + + public static final String GAME_TUN = "tun"; + + public static final String GAME_FENGDING = "fengding"; + + public static final String GAME_TUANYUAN = "tuanyuan"; + + public static final String GAME_HANGHANGXI = "hanghangxi"; + + public static final String GAME_SHUAHOU = "shuahou"; + + public static final String GAME_HUANGFAN = "huangfan"; + + public static final String GAME_JIAXINGXING = "jiaxingxing"; + + public static final String GAME_TINGHU = "tinghu"; + + public static final String GAME_SIQI = "siqi"; + + public static final String GAME_DUIZIFU = "duizifu"; + + public static final String GAME_YUAN = "yuan"; + + public static final String GAME_BEIKAOBEI = "back"; + + public static final String GAME_TIANHU = "tianhu"; + + public static final String GAME_DIHU = "dihu"; + + public static final String GAME_HAIHU = "haihu"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + // 1.��ׯ 2.��ׯ + // public static final String GAME_ZHUANG = "zhuang"; + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXActionEvent.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..ee5df29 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,27 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXGameController.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..4e3a8cd --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,326 @@ +package extend.zp; + +import java.util.Collections; +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.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; + +/** + * + * */ +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender, ITObject params, int gid, Player owner) { + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender, ITObject params, int gid, Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player.seat, params); + } + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender, ITObject params, int gid, Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + public void changeActiveSeat(EXRoom owner, int activeSeat) { + owner.activeSeat = activeSeat; + ITObject param = new TObject(); + param.putInt("seat", activeSeat); + Player player = owner.playerMapBySeat.get(activeSeat); + param.putLong("outoftime", player.offlineTime); + //param.putInt("firsttime", owner.tuoguan_reduce); + owner.broadCastToClient(0, Config.GAME_EVT_CHANGE_ACTIVE_PLAYER, param); + } + + /** + * 玩家摸牌 + * + * @param player + * @param leftCount + */ + public void getCard(EXPlayer player, int 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.getRoom().getPlayBack().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(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + CardUtil.removeCard(player.cardInhand, discard, 1); + + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + /** + * 玩家对牌操作 + * + * @param player + * @param active_card + * @param card + * @param type + * @param from_seat + * @param opcardArray + */ + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } + + /** + * 发牌 + * + * @param owner + */ + public void dealCard(EXRoom owner) { + + for (Entry entry : owner.playerMapById.entrySet()) { + + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + + // if (1 == player.seat) { + // player.cardInhand.clear(); + // // String cardStr = "209, 209, 109, 109, 210, 210, 110, 208, 208, 108, 101, + // 102, 103, 207, 207, 207, 104, 104, 104, 107"; + // String cardStr = "209, 209, 209, 102, 102, 102, 202, 202, 202, 110, 110, 110, + // 207, 207, 207, 104, 107, 107, 201, 201, 206"; + // String[] cards = cardStr.split(", "); + // for(String c : cards) { + // Integer card = Integer.valueOf(c); + // player.cardInhand.add(card); + // } + // } + + Collections.sort(player.cardInhand); + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + + player.cardInhand); + } + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + // 如果可以不出 + owner.start_auto = System.currentTimeMillis() / 1000; + + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + /** + * + * */ + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putTArray("left_card", Util.toTArray(owner.card.getAllResult())); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + /// + for (Entry 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("hu_xi", player.huXi); + param.putInt("tun", player.winScore); + player.hp_info(param); + //// + if (owner.maxPlayers == 2) { + param.putInt("total_tun", player.score.round_score); + } else { + param.putInt("total_tun", player.score.round_score / 2); + } + //// + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + + if (player.winer == 1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + cardList.addTObject(obj); + } + param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + ITArray opCardList = TArray.newInstance(); + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); + param.putInt("win_count", player.winCount); + param.putInt("total_score", player.score.total_score); + player.hp_info(param); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + if (!dissmiss) { + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXMainServer.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..c88c4c0 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,96 @@ +package extend.zp; + +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.zp.player.rulestate.PRChiState; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerPreDrawState; +import extend.zp.player.state.EXPlayerWaitState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + + Global.registerState(PRTiState.class, new PRTiState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXPlayer.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..9cbe22f --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,258 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.zp.player.rule.RuleChi; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public Stack handCard; + public List handCardEx; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashSet chouPongSet; + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public List mingtangList; + + public int kongCount = 0; + public int tiCount = 0; + // ��Ϣ + public int huXi = 0; + + public int total_huxi = 0; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public Long start_auto = 0l; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", this.cardInhand.size()); + playerData.putInt("score", this.score.total_score); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (!self) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI) { + continue; + } + } else { + if (opCard.type == RuleWeight.TYPE_KAN) { + continue; + } + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 0; + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + } + + public void clear() { + this.cardInhand.clear(); + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.kongCount = 0; + this.tiCount = 0; + this.huXi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.tiGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouPongSet.clear(); + this.mingtangList.clear(); + this.score.resetRound(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + return card.getKey(); + } + } + return 0; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + if (this.cardInhand.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + // ���� + if (this.chouChiSet.contains(eventCard)) { + return false; + } + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + return false; + } + + ChowCard chow = new ChowCard(this.cardInhand, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + } + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXRoom.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..9c69ced --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1227 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCard; + +public class EXRoom extends Room { + Logger logger = Logger.getLogger(EXRoom.class); + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; + public boolean isTianHu = true; + public boolean isDiHu = true; + + public boolean hh = false; + public boolean dh = false; + public boolean hw = false; + public boolean wh = false; + public boolean hd = false; + public boolean wd = false; + public boolean jhd = false; + + public boolean dhdf =false; + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public int typeface = 1; + public int adminSeat; + + public ITObject paiXing; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + hh = config.containsKey("hh") ? (config.getInt("hh") == 0 ? true : false) : true; + dh = config.containsKey("dh") ? (config.getInt("dh") == 0 ? true : false) : true; + hw = config.containsKey("hw") ? (config.getInt("hw") == 0 ? true : false) : true; + wh = config.containsKey("wh") ? (config.getInt("wh") == 0 ? true : false) : true; + hd = config.containsKey("hd") ? (config.getInt("hd") == 0 ? true : false) : true; + wd = config.containsKey("wd") ? (config.getInt("wd") == 0 ? true : false) : true; + jhd = config.containsKey("jhd") ? (config.getInt("jhd") == 0 ? true : false) : true; + + dhdf = config.containsKey("dhdf") ? (config.getInt("dhdf") == 0 ? false : true) : false; + this.adminSeat = 0; + } + + public void changePaiXing(int seat, ITObject params) { + ITArray paixing = params.getTArray("card_list"); + if (paixing == null) { + paixing = TArray.newInstance(); + } + paiXing.putTArray(seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(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); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat == player.seat) { + self = true; + } + info_list.addTObject(tempPlayer.getReloadInfo(self)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + + player.score.round_score += score; + player.score.total_score += score; + } + + public void addScore(EXPlayer destPlayer) { + int score = caclScore(destPlayer); + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + if (this.maxPlayers == 2) { + this.addScore(destPlayer, score, EXScore.WIN); + } else { + this.addScore(destPlayer, score * 2, EXScore.WIN); + } + } else { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + this.addScore(fromPlayer, -score, EXScore.WIN); + } + } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 0; + int huXiNum = 0; + boolean isDuzi = true; + int huangFan = 0; + if (!player.handCardEx.isEmpty()) { + isDuzi = false; + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (opCard.type == 2) { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + isDuzi = false; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (opCard.type == RuleWeight.TYPE_CHOW) { + isDuzi = false; + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + player.mingtangList.clear(); + player.winFan = 0; + player.huXi = huXi; + player.total_huxi += huXi; + player.winScore = (huXi - 15) / 3 + 1; + int score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (!player.isMingTang) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + if (player.seat == this.bankerSeat) { + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } else { + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + player.winFan += 6; + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // ��� + if (redCard >= 10) { + int fan = 0; + fan = 3 + redCard - 10; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + + + if (redCard == 0) { + int fan = 8; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + + } + + if (redCard == 1) { + int fan = 6; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + } +// else if(player.room.config.getInt(Config.GAME_MODE) == 2) { +// // 红胡 +// if (redCard >= 10) { +// int fan = 0; +// fan = 3 + redCard - 10; +// player.winFan += fan; +// player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); +// } +// +// +// if (redCard == 0) { +// int fan = 8; +// player.winFan += fan; +// player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); +// +// } +// +// if (redCard == 1) { +// int fan = 6; +// player.winFan += fan; +// player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); +// } +// +// } + else if (player.room.config.getInt(Config.GAME_MODE) == 3) { + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + return score; + } + /// + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2 ) { + if(hh == true) { + if (redCard < 13) { + + fan = 2; + } + + if(dhdf) { + player.winFan += redCard - 10; + player.mingtangList.add(new MingTang(RuleWeight.DHDF, 1, redCard - 10)); + } + } + } else { + fan = 2 + redCard - 10; + } + if(fan > 0) { + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13 && hw == true) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if(wh == true) { + fan = 4; + } + } else { + fan = 5; + } + if(fan > 0) { + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 1) { + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if(dh == true) { + fan = 3; + } + } else { + fan = 3; + } + if(fan > 0) { + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + + } + logger.info("isDuzi==>"+isDuzi); + //对子胡 + if (isDuzi) { + if (this.config.getInt(Config.GAME_MODE) == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 8)); + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + + if (this.config.getInt(Config.GAME_DUIZIFU) == 0) { + + boolean bExist = false; + + if(hd ) { + + for(MingTang mt : player.mingtangList) { + if(mt.mingTang == RuleWeight.HONG_HU) { + bExist = true; + player.mingtangList.remove(mt); + break; + } + } + + if(bExist) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_DUI, 1, 6)); + } + } + + if(wd && bExist == false) { + + for(MingTang mt : player.mingtangList) { + if(mt.mingTang == RuleWeight.WU_HU) { + bExist = true; + player.mingtangList.remove(mt); + break; + } + } + + if(bExist) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.WU_DUI, 1, 8)); + } + } + + if(jhd && bExist == false) { + //// + for(MingTang mt : player.mingtangList) { + if(mt.mingTang == RuleWeight.HONG_WU) { + bExist = true; + player.mingtangList.remove(mt); + break; + } + } + //// + if(bExist) { + logger.info("jiahong-======>"+RuleWeight.JIAHONG_DUI); + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.JIAHONG_DUI, 1, 8)); + } + } + /// + if(bExist == false) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } + } else { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } + // + if (this.config.getInt(Config.GAME_MODE) == 1 || this.config.getInt(Config.GAME_MODE) == 3) { + + if (this.winSeat == player.seat) { + player.winScore += 1; + player.mingtangList.add(new MingTang(RuleWeight.ZI_MO, 2, 1)); + } + } + + // + if (this.config.getInt(Config.GAME_MODE) == 1) { + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } + // �غ� + else { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + } + // ���� + if (this.card.getCount() == 0) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 6)); + } + // ���� + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + if (player.isTingHu) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 6)); + } + } + // ��� + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + // С�� + if (smallCard >= 16) { + int fan = 10 + smallCard - 16; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + // ����Բ + if (this.config.getInt(Config.GAME_TUANYUAN) == 1) { + int duan = 0; + for (int i = 1; i <= 10; i++) { + int num = 0; + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + if (opCard.card1 % 100 == i) { + num++; + } + } + if (num == 2) { + duan++; + } + } + if (duan > 0) { + int fan = duan * 8; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_TUAN_YUAN, 1, fan)); + } + } + // ����Ϣ + if (this.config.getInt(Config.GAME_HANGHANGXI) == 1) { + if (huXiNum == 7) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 8)); + } + } + // ������Ϣ + if (this.config.getInt(Config.GAME_JIAXINGXING) == 1) { + if ((player.tiCount + player.kongCount) > 0) { + if (huXiNum == 6) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.JIA_XING_XING, 1, 4)); + } + } + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + // ˣ�� + if (this.config.getInt(Config.GAME_SHUAHOU) == 1) { + if (player.kanGroup.isEmpty() && player.cardInhand.size() == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.SHUA_HOU, 1, 8)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // Բ + if (this.config.getInt(Config.GAME_YUAN) == 1) { + List cardList = new ArrayList<>(); + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + cardList.add(opCard.card1); + } + if (!cardList.isEmpty()) { + Collections.sort(cardList); + int yuan = 0; + int num = cardList.get(0); + for (int i = 1; i < cardList.size(); i++) { + if (num + 1 == cardList.get(i)) { + yuan++; + } + num = cardList.get(i); + } + if (yuan > 0) { + int fan = yuan * 6; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.YUAN, 1, fan)); + } + } + } + // ������ + if (this.config.getInt(Config.GAME_BEIKAOBEI) == 1) { + boolean kezi1 = false; + boolean kezi2 = false; + boolean isBeiKaoBei = true; + for (OpCard opCard : player.handCard) { + if (opCard.type == 1) { + if (opCard.card1 != player.winCard && opCard.card1 % 100 == player.winCard % 100) { + kezi1 = true; + continue; + } + break; + } else { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + if (opCard.card1 == player.winCard || opCard.card2 == player.winCard || opCard.card3 == player.winCard) { + isBeiKaoBei = false; + break; + } + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (isBeiKaoBei) { + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_WEI && opCard.type != RuleWeight.TYPE_CHOUWEI && opCard.type != RuleWeight.TYPE_KAN) { + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (kezi1 && kezi2) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.BEI_KAO_BEI, 1, 8)); + } + } + } + // ���෬ + if (this.config.getInt(Config.GAME_MODE) == 3) { + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } + // �غ� + else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + } + // ���� + if (this.config.getInt(Config.GAME_HAIHU) == 1) { + if (this.card.getCount() == 0) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 4)); + } + } + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + // ���� + if (player.isTingHu) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 4)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 1) { + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + return score; + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + // public void settleRound() { + // saveMilitaryRound(playBackData.getData(this)); + // if (this.liuju == true) { + // this.bankerSeat = this.playerMapBySeat.get(this.bankerSeat).nextSeat; + // } + // boolean total = this.round >= this.maxRound; + // int result = this.nonNegative(false); + // if (!total) { + // EXMainServer.gameCtr.roomResult(this); + // if (result == 4) { + // total = true; + // this.saveMilitaryTotal(false); + // } + // } else { + // this.saveMilitaryTotal(false); + // } + // this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + // this.winCount = 0; + // + // if (total) { + // this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + // return; + // } + // } + + public void win(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + player.winCard = player.getRoom().drawCard; + } + player.winer = 1; + int scoreSrc = caclScore(player); + if (player.handCard.isEmpty()) { + scoreSrc = 0; + } + player.resetHuXi(); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + + Stack handCard = new Stack(); + List handCardEx = new ArrayList<>(); + handCard.addAll(player.handCard); + handCardEx.addAll(player.handCardEx); + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (activePlayer.drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.pongGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] pongGroup = new int[3]; + pongGroup[0] = activePlayer.drawCard; + pongGroup[1] = activePlayer.drawCard; + pongGroup[2] = activePlayer.drawCard; + + player.pongGroup.add(pongGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (activePlayer.drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.kanGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] kanGroup = new int[3]; + kanGroup[0] = activePlayer.drawCard; + kanGroup[1] = activePlayer.drawCard; + kanGroup[2] = activePlayer.drawCard; + + player.kanGroup.add(kanGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (activePlayer.drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.weiGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] weiGroup = new int[3]; + weiGroup[0] = activePlayer.drawCard; + weiGroup[1] = activePlayer.drawCard; + weiGroup[2] = activePlayer.drawCard; + + player.weiGroup.add(weiGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + } + this.addScore(player); + // this.liuju = false; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(player.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + EXMainServer.gameCtr.winEvent(player, player.seat); + // if (owner.room.config.getInt(Config.GAME_ZHUANG) == 1) { + // if (room.bankerSeat != owner.seat) { + // room.bankerSeat = owner.lastSeat; + // } + // } else { + // room.bankerSeat = owner.seat; + // } + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + } + + @Override + public void endGame() { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.endGame(); + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + } + // public void destroy() { + // super.destroy(); + // } + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/EXScore.java b/game_zp_hspaohuzi/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/MingTang.java b/game_zp_hspaohuzi/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..82b8723 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,13 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; + public int score; + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/OpCard.java b/game_zp_hspaohuzi/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..b894d9d --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,24 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + } + + public OpCard() { + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/PlayBack.java b/game_zp_hspaohuzi/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..74f6ad7 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_hspaohuzi/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..86ffaef --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,121 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.RuleChi; +import extend.zp.player.rule.RuleDealKan; +import extend.zp.player.rule.RuleDealTi; +import extend.zp.player.rule.RuleDiscardPao; +import extend.zp.player.rule.RuleDrawChi; +import extend.zp.player.rule.RuleDrawPao; +import extend.zp.player.rule.RuleDrawPong; +import extend.zp.player.rule.RuleKan; +import extend.zp.player.rule.RulePong; +import extend.zp.player.rule.RuleTi; +import extend.zp.player.rule.RuleWei; +import extend.zp.player.rule.RuleWin; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + drawPaoList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List otherHuList = new ArrayList(); + otherHuList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/RoomCard.java b/game_zp_hspaohuzi/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..f070997 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,104 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class RoomCard { + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + this.subCardList = new ArrayList<>(); + } + + public List getAllResult(){ + List all = new ArrayList<>(); + if(subCardList.size() > 0) + all.addAll(subCardList); + all.addAll(cardList); + return all; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public int pop() { + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + /** + * 发牌 + * */ + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + return dealCards; + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/RuleWeight.java b/game_zp_hspaohuzi/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..46d82be --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,49 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10; + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; + public final static int WU_HU = 2; + public final static int DIAN_HU = 3; + public final static int DUIZI_HU = 4; + public final static int TIAN_HU = 5; + public final static int DI_HU = 6; + public final static int HAI_HU = 7; + public final static int TING_HU = 8; + public final static int DA_HU = 9; + public final static int XIAO_HU = 10; + public final static int DA_TUAN_YUAN = 11; + public final static int XING_XING_XI = 12; + public final static int SI_QI_HONG = 13; + public final static int SHUA_HOU = 14; + public final static int HUANG_FAN = 15; + public final static int ZI_MO = 16; + public final static int JIA_XING_XING = 17; + public final static int HONG_WU = 18; + public final static int YUAN = 19; + public final static int BEI_KAO_BEI = 20; + public final static int HONG_DUI =21; + public final static int WU_DUI = 22; + public final static int JIAHONG_DUI = 23; + public final static int DHDF = 24; +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..c2f74ac --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,29 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..655d7b4 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,79 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + + if(num == 2 && card == player.drawCard) { + + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + player.getRoom().getPlayBack().addAddCardCommand(player.room.activeSeat, card); + } + if (num == 3) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..8b64bd0 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,82 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + int num = entry.getValue(); + + // 如果抓的牌 手中刚好有三张 + if (card == player.drawCard && num == 3) { + + player.winCard = player.drawCard; + player.drawCard = 0; + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + + + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..c3a82db --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,54 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..f33f88f --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,32 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..5b33794 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..b2fa1cc --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,55 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..df87829 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..0ad7640 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java new file mode 100644 index 0000000..96cb028 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleTi.java @@ -0,0 +1,56 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRTiState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..9084b70 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,34 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleWei implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..5fffee6 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,48 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isLaoYe) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + if (Paixing.checkWin(player, activePlayer.drawCard)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..6c91519 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,66 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +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 extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + + public static void prChi(int card, EXPlayer owner) { + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + __chow(owner, chowcard1, chowcard2, card, activePlayer, false); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + if (bi) { + CardUtil.removeCard(player.cardInhand, card, 1); + } + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..ed30148 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,42 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + + +public class PRChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..96900b8 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,98 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..7441809 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,41 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + +public class PRDrawChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java new file mode 100644 index 0000000..2710a3e --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java @@ -0,0 +1,106 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDrawPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + int fromseat = activePlayer.seat; + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..8478789 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,81 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRDrawPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + CardUtil.removeCard(owner.cardInhand, card, 2); + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..7d63bd9 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,81 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + CardUtil.removeCard(owner.cardInhand, card, 2); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java new file mode 100644 index 0000000..46ebf74 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java @@ -0,0 +1,85 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRTiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + int card = owner.opCard.getInt(0); + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.tiGroup.add(tiGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..b834338 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,77 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + int card = owner.opCard.getInt(0); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + owner.weiGroup.add(weiGroup); + + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..7050ece --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,38 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + room.win(owner, activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..dc571a9 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,53 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..7d543a2 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,165 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + + owner.getRoom().tipMap.clear(); + + if (owner.cardInhand.isEmpty()) { + + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + + } else { + + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + if (!Util.checkCard(discard, owner.cardInhand)) { + return; + } + logger.info("discard,player:" + owner + ",card:" + discard); + if (owner.seat == owner.room.bankerSeat) { + + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + owner.outcardExList.add(discard); + exit(owner); + EXMainServer.gameCtr.outCard(owner, discard); + long current_time = System.currentTimeMillis()/1000; + long space_time = current_time - owner.start_auto; + + /*if(owner.getRoom().entrust_round > 0 && space_time > owner.getRoom().tuoguan_reduce ) { + owner.enter_auto++; + owner.initPlayerAutoTime(owner.offlineTime); + }*/ + + owner.getRoom().isDiHu = false; + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + + if (owner.getRoom().isAllPass) { + + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + + } else { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + + if (owner.room.isDestroy) + return; + + owner.room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + + owner.outcardList.add(owner.getRoom().activeCard); + + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..c54f9c3 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,432 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } + else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else { + Global.logger.info("dealcards playerid:"+owner.playerid+ " general player"); + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + } + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..1f4e455 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,52 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..3c6c54a --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,145 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.Paixing; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + room.isAllPass = false; + + owner.drawCard = room.card.pop(); + + room.drawCard = owner.drawCard; + + //发消息给自己,并记录玩家抓牌的日志 + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + //通知所有其他的玩家 + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + //启动定时器 + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + + if (!owner.getRoom().isAllPass) { + + //根据规则判定自己能不能胡 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + + //看看其他玩家能不能胡 + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + //判断玩家抓牌之后可以进行的操作 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + + //判断玩家是否有坎的操作 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + + int drawCard = owner.drawCard; + owner.drawCard = 0; + owner.getRoom().isTianHu = false; + + if (drawCard != 0) { + + owner.cardInhand.add(drawCard); + + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + + if (owner.room.isDestroy) + return; + + owner.room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + + boolean win = false; + + //看看其他玩家能不能胡牌 + for (Entry entry : owner.getRoom().playerMapById.entrySet()) { + + if (entry.getKey().equals(owner.playerid)) { + continue; + } + + EXPlayer player = (EXPlayer) entry.getValue(); + if(Paixing.checkWin(player, owner.drawCard)) { + win = true; + } + } + + // 如果不能胡 则看抓牌的玩家能不能提和坎 + if(!win) + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..af786e1 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,40 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..c3abb79 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..ca0016b --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,85 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import com.taurus.core.util.Logger; + +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + Logger logger = Logger.getLogger(EXRoomDealState.class); + @Override + public void enter(EXRoom owner) { + + //洗牌 + owner.card.init(); + logger.info("bankerseat===>"+owner.bankerSeat); + for(Entry en : owner.playerMapBySeat.entrySet()) { + logger.info("en-===>"+en.getKey()); + } + // 如果没有庄家,确定一个庄家 + if (owner.bankerSeat == 0) { + //随机一个庄家 + int a=(int)(Math.random()*(owner.playerMapBySeat.size()))+1; + owner.bankerSeat = a; + } + + //发牌 + EXMainServer.gameCtr.dealCard(owner); + + // 去底牌 + if (owner.maxPlayers == 2 ) { + int qupaiV = owner.config.getInt(Config.ROOM_CONFIG_QUPAI); + if(qupaiV > 0) { + + int num = qupaiV * 5 + 5; + for (int index = 0; index < num; index++) { + owner.throwCardsList.add(owner.card.pop()); + } + } + } + + // 生成游戏记录对象 + owner.playBackData = new PlayBack(owner); + + // 不是庄家的玩家要进行规则判定 + for (Entry entry : owner.playerMapById.entrySet()) { + + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + //状态迁移 + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + public static void main(String[] args) { + for(int i = 0;i < 100;i++) { + + int a=(int)(Math.random()*(2))+1; + System.out.println(a); + } + + } + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..090757d --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,46 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapById.entrySet()) { + + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + + player.entrust_round = 0; + if (owner.isEntrust()) { + if(player.offlineTime == 0) { + if (player.isEntrust()) { + player.offlineTime = owner.default_entrust_time; + } else { + player.offlineTime = owner.entrustTime; + } + } + } + } + + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Action.java b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Tip.java b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/tip/TipManager.java b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..6c760a6 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,181 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.RuleWeight; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + public int getUid(){ + return this.uid; + } + + // + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + /// + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass discardtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7da6330 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,129 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.taurus.core.entity.ITArray; + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } + + /** + * TArray转list + * */ + public static final List toList(ITArray list){ + List tem = new ArrayList<>(); + for(int i=0;i cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + } + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + result = handle(list,bi_card,bi_card) || result; + } + if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + result = handle(list,eventCard,bi_card) || result; + CardUtil.addCard(eventCard, cardMap, 1); + } + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..8897afc --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,152 @@ +package extend.zp.uitl; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class Paixing { + public static boolean checkWin(EXPlayer player, int drawCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (win.tryWin(player)) { + if (player.huXi >= 15) { + isWin = true; + } + } + if (!isWin) { + player.resetHuXi(); + //3提,5坎,1提4坎,2提3坎 + if (player.getRoom().isTianHu) { + if (player.tiCount >= 3) { + player.isMingTang = true; + isWin = true; + } + if (player.kanGroup.size() >= 5) { + player.isMingTang = true; + isWin = true; + } + if (player.tiCount >= 1 && player.kanGroup.size() >= 4) { + player.isMingTang = true; + isWin = true; + } + if (player.tiCount >= 2 && player.kanGroup.size() >= 3) { + player.isMingTang = true; + isWin = true; + } + } + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + } + } + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + for (int i = 0; i < win.stack.size(); i++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(i).get(0); + opcard.card2 = win.stack.get(i).get(1); + opcard.type = 1; + if (win.stack.get(i).size() > 2) { + opcard.card3 = win.stack.get(i).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(i); + + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + + } + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 9; + } else { + huXi = 12; + } + break; + case RuleWeight.TYPE_PAO: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 6; + } else { + huXi = 9; + } + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + case RuleWeight.TYPE_KAN: + case RuleWeight.TYPE_CHOW: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 3; + } else { + huXi = 6; + } + break; + case RuleWeight.TYPE_PONG: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 1; + } else { + huXi = 3; + } + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..aa66505 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,328 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + } + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.tiCount + player.kongCount > 0) { + if (this.pair_count == 1) { + return true; + } + return false; + } else { + if (this.pair_count > 0) { + return false; + } + return true; + } + } + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..aea44ac --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,381 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCardNew winCard2 = new WinCardNew(list, 106, 9, true, op); + /* op = winCard2.groupCard(207); */ + System.out.println(winCard2.checkHu()); + winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + + } + + /** + * + * @param cardInhand + * :����,�������� + * @param addCard + * : �Ӵ����Ƿ��ܺ���������������������Ҫ��0 + * @param huxi + * ��������еĺ�Ϣ + * @param isJiang + * ���Ƿ���Ҫ�� + */ + public WinCardNew(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + } +} diff --git a/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_hspaohuzi/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_paohuzi/config/game-config.xml b/game_zp_paohuzi/config/game-config.xml new file mode 100644 index 0000000..2079778 --- /dev/null +++ b/game_zp_paohuzi/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.14.1 + 192.168.14.1 + 8811 + 8811 + 13 + true + \ No newline at end of file diff --git a/game_zp_paohuzi/config/log4j.properties b/game_zp_paohuzi/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_paohuzi/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_paohuzi/config/taurus-core.xml b/game_zp_paohuzi/config/taurus-core.xml new file mode 100644 index 0000000..0f9fa8f --- /dev/null +++ b/game_zp_paohuzi/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_paohuzi/config/taurus-permanent.xml b/game_zp_paohuzi/config/taurus-permanent.xml new file mode 100644 index 0000000..9cdaab3 --- /dev/null +++ b/game_zp_paohuzi/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_paohuzi/pom.xml b/game_zp_paohuzi/pom.xml new file mode 100644 index 0000000..7dbe59c --- /dev/null +++ b/game_zp_paohuzi/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_paohuzi + game_zp_paohuzi + 1.0.0 + jar + game_zp_paohuzi + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_paohuzi_zipai + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_paohuzi/src/main/java/extend/zp/Config.java b/game_zp_paohuzi/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..903ff66 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/Config.java @@ -0,0 +1,90 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 13; + + public static final String GAME_MODE = "mode"; + + public static final String GAME_TUN = "tun"; + + public static final String GAME_FENGDING = "fengding"; + + public static final String GAME_TUANYUAN = "tuanyuan"; + + public static final String GAME_HANGHANGXI = "hanghangxi"; + + public static final String GAME_SHUAHOU = "shuahou"; + + public static final String GAME_HUANGFAN = "huangfan"; + + public static final String GAME_JIAXINGXING = "jiaxingxing"; + + public static final String GAME_TINGHU = "tinghu"; + + public static final String GAME_SIQI = "siqi"; + + public static final String GAME_DUIZIFU = "duizifu"; + + public static final String GAME_YUAN = "yuan"; + + public static final String GAME_BEIKAOBEI = "back"; + + public static final String GAME_TIANHU = "tianhu"; + + public static final String GAME_DIHU = "dihu"; + + public static final String GAME_HAIHU = "haihu"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + // 1.��ׯ 2.��ׯ + // public static final String GAME_ZHUANG = "zhuang"; + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + + public static final String GAME_EVT_FANGWEI = "822"; + + public static final String GAME_EVT_FANGPAO = "823"; + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXActionEvent.java b/game_zp_paohuzi/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..ee5df29 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,27 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXGameController.java b/game_zp_paohuzi/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..10c9ec3 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,389 @@ +package extend.zp; + +import java.util.Collections; +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.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; +import com.taurus.core.plugin.redis.Redis; +import redis.clients.jedis.Jedis; + + + +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + public EXGameController() { + super(); + } + + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender,ITObject params,int gid,Player owner) { + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player, params); + } + + + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + 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 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.getRoom().getPlayBack().addGetCardCommand(player.room.activeSeat, player.drawCard, leftCount); + } + + @ActionKey(Config.GAME_EVT_FANGPAO) + public void RouterFangwei(Session sender,ITObject params,int gid,Player owner){ + EXPlayer player = (EXPlayer) owner; + int discard = params.getInt("card"); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + response.putInt("card", discard); + logger.info("jefe GAME_EVT_FANGPAO:" + discard+";player:"+player.playerid); + owner.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + + //记录用户放跑 + Jedis jedis = Redis.use("group1_db5").getJedis(); + jedis.hset("pao"+player.room+player.room.round+player.playerid,"fanpao",discard+""); + jedis.close(); + EXRoom room = player.getRoom(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + public void outCard(EXPlayer player, int discard) { + logger.info("jefe outcard:" + discard+";player:"+player.playerid); + //判断是否有喂 + Jedis jedis = Redis.use("group1_db5").getJedis(); + String wei = jedis.hget("p"+player.room+player.room.round,"4,"+discard); + jedis.close(); + ITObject response = new TObject(); + response.putInt("seat", player.seat); + response.putInt("card", discard); + logger.info("jefe roomId:" + player.room+",playerid:"+player.playerid +",card:"+discard+",wei:"+wei+",round:"+player.room.round); + if (wei!=null){ + logger.info("jefe roomId:" + player.room +",wei:"+wei); + //player.room.broadCastToClient(player.playerid, Config.GAME_EVT_FANGWEI, response); + player.sendEvent(Config.GAME_EVT_FANGWEI, response); + + }else{ + + player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + + EXRoom room = player.getRoom(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + //jedis.close(); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + //放跑不能吃碰等 + + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao"+player.room+player.room.round+player.playerid,"fanpao"); + jedis.close(); + + if (fp!=null){ + //锁 + logger.info("jefe fanpao into:" + player.room+",playerid:"+player.playerid ); + //player.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + //player.room.broadCastToServer(player.playerid, EXActionEvent.EVENT_DEAL, null); + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + }else{ + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } + + + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + +// if (2 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 102, 102, 103, 103, 109, 201, 201, 202, 202, 203, 203, 204, 204, 204, 206, 207, 208, 209, 210"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (3 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 101, 201, 201, 202, 202, 203, 203, 103, 104, 105, 106, 204, 207, 207, 107, 208, 209, 110, 110"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (1 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "102, 103, 103, 104, 104, 104, 107, 107, 107, 108, 110, 201, 202, 204, 205, 205, 206, 206, 206, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } + + Collections.sort(player.cardInhand); + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + player.cardInhand); + } +// owner.card.cardList.clear(); +// String cardStr = "210, 105, 101, 209, 106, 203, 109, 109, 204, 109, 108, 207, 110, 103, 203, 201, 107, 106, 110, 201, 210, 208, 101, 201, 105, 210, 205, 102, 108, 208, 105, 108, 102, 207, 202, 103, 106, 210, 202, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// owner.card.cardList.add(card); +// } + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + logger.info(param.toString()); + + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao"+owner.room+owner.room.round+owner.playerid,"fanpao"); + jedis.close(); + logger.info("jefe tipEvent:" +param.getInt("uid")); + //ITObject params = new TObject(); + //params.putInt("id",param.getInt("uid")); + + if (fp!=null){ + + param.putInt("fptype",1); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + }else{ + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("xipai_score", owner.xi_pai_score); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.huXi); + param.putInt("tun", player.winScore); + player.hp_info(param); + if (owner.maxPlayers == 2) { + param.putInt("total_tun", player.score.round_score); + } else { + param.putInt("total_tun", player.score.round_score / 2); + } + + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + + if (player.winer == 1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + cardList.addTObject(obj); + } + param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + ITArray opCardList = TArray.newInstance(); + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); + param.putInt("win_count", player.winCount); + param.putInt("total_score", player.score.total_score); + player.hp_info(param); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + if (!dissmiss) { + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXMainServer.java b/game_zp_paohuzi/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..c88c4c0 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,96 @@ +package extend.zp; + +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.zp.player.rulestate.PRChiState; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerPreDrawState; +import extend.zp.player.state.EXPlayerWaitState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + + Global.registerState(PRTiState.class, new PRTiState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXPlayer.java b/game_zp_paohuzi/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..b9f9c70 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,256 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.zp.player.rule.RuleChi; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public Stack handCard; + public List handCardEx; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashSet chouPongSet; + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public List mingtangList; + + public int kongCount = 0; + public int tiCount = 0; + // ��Ϣ + public int huXi = 0; + + public int total_huxi = 0; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", this.cardInhand.size()); + playerData.putInt("score", this.score.total_score); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (!self) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI) { + continue; + } + } else { + if (opCard.type == RuleWeight.TYPE_KAN) { + continue; + } + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 0; + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + } + + public void clear() { + this.cardInhand.clear(); + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.kongCount = 0; + this.tiCount = 0; + this.huXi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.tiGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouPongSet.clear(); + this.mingtangList.clear(); + this.score.resetRound(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + return card.getKey(); + } + } + return 0; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + if (this.cardInhand.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + // ���� + if (this.chouChiSet.contains(eventCard)) { + return false; + } + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + return false; + } + + ChowCard chow = new ChowCard(this.cardInhand, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + } + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXRoom.java b/game_zp_paohuzi/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..08eb3fe --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1266 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +import com.game.Global; +import com.game.Router; +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.*; +import com.taurus.core.util.Logger; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCard; + + +public class EXRoom extends Room { + Logger logger = Logger.getLogger(getClass()); + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; + public boolean isTianHu = true; + public boolean isDiHu = true; + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public int typeface = 1; + + public ITObject paiXing; + public int adminSeat; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + 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); + } + this.adminSeat = 0; + } + + public void changePaiXing(EXPlayer player, ITObject params) { + ITArray paixing = null; + try { + paixing = params.getTArray("card_list"); + } + catch(Exception e) + { + + } + + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < paixing.size(); i++) + { + TDataWrapper card = paixing.get(i); + TObject map = (TObject)card.getObject(); + tmpCardList.add(map.getInt("card")); + } + + Collections.sort(tmpCardList); + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(player.cardInhand); + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + } + } + Collections.sort(tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2)) + { + ITObject param = new TObject(); + player.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + + paiXing.putTArray(player.seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", player.seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(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); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat != player.seat) { + continue; + } + Global.logger.info("tempPlayer:"+tempPlayer.playerid); + info_list.addTObject(tempPlayer.getReloadInfo(true)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + + player.score.round_score += score; + player.score.total_score += score; + } + + public void addScore(EXPlayer destPlayer) { + int score = caclScore(destPlayer); + //先判断分够不够 + int tmp_all_score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + if (!entry.getKey().equals(destPlayer.playerid)) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + tmp_all_score += reMultipleScore((int)fromPlayer.hp.cur_hp); + this.addScore(fromPlayer, -reMultipleScore((int)fromPlayer.hp.cur_hp), EXScore.WIN); + }else { + tmp_all_score += score; + this.addScore(fromPlayer, -score, EXScore.WIN); + } + } + } + // + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + this.addScore(destPlayer, tmp_all_score, EXScore.WIN); + } + } + + //// +// for (Entry entry : this.playerMapById.entrySet()) { +// if (entry.getKey().equals(destPlayer.playerid)) { +// if (this.maxPlayers == 2) { +// this.addScore(destPlayer, score, EXScore.WIN); +// } else { +// this.addScore(destPlayer, score * 2, EXScore.WIN); +// } +// } else { +// EXPlayer fromPlayer = (EXPlayer) entry.getValue(); +// this.addScore(fromPlayer, -score, EXScore.WIN); +// } +// } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 0; + int huXiNum = 0; + boolean isDuzi = true; + int huangFan = 0; + + //ssdd + if (!player.handCardEx.isEmpty()) { + isDuzi = false; + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (opCard.type == 2) { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + isDuzi = false; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (opCard.type == RuleWeight.TYPE_CHOW) { + isDuzi = false; + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + player.mingtangList.clear(); + player.winFan = 0; + player.huXi = huXi; + player.total_huxi = huXi; + player.winScore =huXi-huXi%3;//jefe (huXi - 15) / 3 + 1 + + + int score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (!player.isMingTang) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + if (player.seat == this.bankerSeat) { + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } else { + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + player.winFan += 6; + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 + redCard - 10; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 5; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 3; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + } else if (player.room.config.getInt(Config.GAME_MODE) == 1) {//jefe + if (huXi>=30){ + player.winFan += 2; + }else { + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + } + + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + + return score; + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 ;//jefe 2 + redCard - 10 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 2;//jefe 5 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 2;//jefe 3 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���Ӻ� + if (isDuzi) { + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 8)); + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (this.config.getInt(Config.GAME_DUIZIFU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } else { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 2)); + } + } + // ���� + if (this.winSeat == player.seat) { + //player.winScore += 1; jefe + player.mingtangList.add(new MingTang(RuleWeight.ZI_MO, 2, 1*3));//jefe *3 + } + // ȫ���� + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } + // �غ� + else { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + } + // ���� + if (this.card.getCount() == 0) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 6)); + } + // ���� + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + if (player.isTingHu) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 6)); + } + } + // ��� + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + + // С�� + if (smallCard >= 16) { + int fan = 10 + smallCard - 16; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + + // ����Բ + if (this.config.getInt(Config.GAME_TUANYUAN) == 1) { + int duan = 0; + for (int i = 1; i <= 10; i++) { + int num = 0; + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + if (opCard.card1 % 100 == i) { + num++; + } + } + if (num == 2) { + duan++; + } + } + if (duan > 0) { + int fan = duan * 8; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_TUAN_YUAN, 1, fan)); + } + } + // ����Ϣ + if (this.config.getInt(Config.GAME_HANGHANGXI) == 1) { + if (huXiNum == 7) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 8)); + } + } + // ������Ϣ + if (this.config.getInt(Config.GAME_JIAXINGXING) == 1) { + if ((player.tiCount + player.kongCount) > 0) { + if (huXiNum == 6) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.JIA_XING_XING, 1, 4)); + } + } + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + // ˣ�� + if (this.config.getInt(Config.GAME_SHUAHOU) == 1) { + if (player.kanGroup.isEmpty() && player.cardInhand.size() == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.SHUA_HOU, 1, 8)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // Բ + if (this.config.getInt(Config.GAME_YUAN) == 1) { + List cardList = new ArrayList<>(); + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + cardList.add(opCard.card1); + } + if (!cardList.isEmpty()) { + Collections.sort(cardList); + int yuan = 0; + int num = cardList.get(0); + for (int i = 1; i < cardList.size(); i++) { + if (num + 1 == cardList.get(i)) { + yuan++; + } + num = cardList.get(i); + } + if (yuan > 0) { + int fan = yuan * 6; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.YUAN, 1, fan)); + } + } + } + // ������ + if (this.config.getInt(Config.GAME_BEIKAOBEI) == 1) { + boolean kezi1 = false; + boolean kezi2 = false; + boolean isBeiKaoBei = true; + for (OpCard opCard : player.handCard) { + if (opCard.type == 1) { + if (opCard.card1 != player.winCard && opCard.card1 % 100 == player.winCard % 100) { + kezi1 = true; + continue; + } + break; + } else { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + if (opCard.card1 == player.winCard || opCard.card2 == player.winCard || opCard.card3 == player.winCard) { + isBeiKaoBei = false; + break; + } + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (isBeiKaoBei) { + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_WEI && opCard.type != RuleWeight.TYPE_CHOUWEI && opCard.type != RuleWeight.TYPE_KAN) { + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (kezi1 && kezi2) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.BEI_KAO_BEI, 1, 8)); + } + } + } + // ���෬ + if (this.config.getInt(Config.GAME_MODE) == 1) {//jefe + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 0) {//jefe 1 + player.winFan += 2; //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 2)); + } + } + // �غ� + else { + if (this.config.getInt(Config.GAME_DIHU) == 0) { //jefe 1 + player.winFan += 2;// jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 2)); + } + } + } + // ���� + if (this.config.getInt(Config.GAME_HAIHU) == 1) {// + if (this.card.getCount() == 0) { + player.winFan += 2; // //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 2)); + } + } + /* + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + // ���� + if (player.isTingHu) { + player.winFan += 2; //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 2)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + }*/ + + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + fan = 2;//jefe + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + + // С�� + if (smallCard >= 18) { + int fan = 10 + smallCard - 18; + fan = 2;//jefe + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + + //30息翻倍 jefe + if(player.winFan<=1&&huXi>=30){ + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.SANSHI_XI_FAN, 1, 2)); + } + + } + score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 3) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 300); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 4) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 500); + } + } + //jefe *3 + if (this.winSeat == player.seat) { + score += 3; + } + + return score; + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + // public void settleRound() { + // saveMilitaryRound(playBackData.getData(this)); + // if (this.liuju == true) { + // this.bankerSeat = this.playerMapBySeat.get(this.bankerSeat).nextSeat; + // } + // boolean total = this.round >= this.maxRound; + // int result = this.nonNegative(false); + // if (!total) { + // EXMainServer.gameCtr.roomResult(this); + // if (result == 4) { + // total = true; + // this.saveMilitaryTotal(false); + // } + // } else { + // this.saveMilitaryTotal(false); + // } + // this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + // this.winCount = 0; + // + // if (total) { + // this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + // return; + // } + // } + + public void win(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + player.winCard = player.getRoom().drawCard; + } + player.winer = 1; + int scoreSrc = caclScore(player); + if (player.handCard.isEmpty()) { + scoreSrc = 0; + } + player.resetHuXi(); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + + Stack handCard = new Stack(); + List handCardEx = new ArrayList<>(); + handCard.addAll(player.handCard); + handCardEx.addAll(player.handCardEx); + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (activePlayer.drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.pongGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] pongGroup = new int[3]; + pongGroup[0] = activePlayer.drawCard; + pongGroup[1] = activePlayer.drawCard; + pongGroup[2] = activePlayer.drawCard; + + player.pongGroup.add(pongGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (activePlayer.drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.kanGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] kanGroup = new int[3]; + kanGroup[0] = activePlayer.drawCard; + kanGroup[1] = activePlayer.drawCard; + kanGroup[2] = activePlayer.drawCard; + + player.kanGroup.add(kanGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (activePlayer.drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.weiGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] weiGroup = new int[3]; + weiGroup[0] = activePlayer.drawCard; + weiGroup[1] = activePlayer.drawCard; + weiGroup[2] = activePlayer.drawCard; + + player.weiGroup.add(weiGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + } + this.addScore(player); + // this.liuju = false; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(player.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + EXMainServer.gameCtr.winEvent(player, player.seat); + // if (owner.room.config.getInt(Config.GAME_ZHUANG) == 1) { + // if (room.bankerSeat != owner.seat) { + // room.bankerSeat = owner.lastSeat; + // } + // } else { + // room.bankerSeat = owner.seat; + // } + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + } + + @Override + public void endGame() { + super.endGame(); + } + + public void saveRecRound() { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.saveRecRound(); + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + } + // public void destroy() { + // super.destroy(); + // } + + /** + * 开启倍数后 体力值消耗= 倍数*分数 + */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/EXScore.java b/game_zp_paohuzi/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/MingTang.java b/game_zp_paohuzi/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..82b8723 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,13 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; + public int score; + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/OpCard.java b/game_zp_paohuzi/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..bbd5df6 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,35 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + public boolean pailie; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = false; + } + + public OpCard(int type, int card1, int card2, int card3, int huXi, boolean pailei) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = pailei; + } + + public OpCard() { + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/PlayBack.java b/game_zp_paohuzi/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..74f6ad7 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_paohuzi/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..86ffaef --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,121 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.RuleChi; +import extend.zp.player.rule.RuleDealKan; +import extend.zp.player.rule.RuleDealTi; +import extend.zp.player.rule.RuleDiscardPao; +import extend.zp.player.rule.RuleDrawChi; +import extend.zp.player.rule.RuleDrawPao; +import extend.zp.player.rule.RuleDrawPong; +import extend.zp.player.rule.RuleKan; +import extend.zp.player.rule.RulePong; +import extend.zp.player.rule.RuleTi; +import extend.zp.player.rule.RuleWei; +import extend.zp.player.rule.RuleWin; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + drawPaoList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List otherHuList = new ArrayList(); + otherHuList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/RoomCard.java b/game_zp_paohuzi/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..abe4238 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,104 @@ +package extend.zp; + +import java.util.*; + +public class RoomCard { + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + this.subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + +// private void initCard2() { +// List list = Arrays.asList(102, 103, 105, 106, 106, 107, 108, 108, 109, 110, 110, 110, 110, 201, 202, 207, 209, 209, 210, 210); +// List list2 = Arrays.asList(101, 101, 104, 104, 105, 107, 107, 109, 201, 201, 203, 203, 203, 203, 204, 206, 207, 208, 209, 210); +// List list3 = Arrays.asList(205, 106, 108, 208, 209, 105, 106, 206, 102, 105, 104, 108, 102, 107, 202, 106, 206, 202, 104, 204, 102, 108, 208, 207, 208, 205, 205, 201, 202, 101, 103, 206, 103, 209, 208, 210, 102, 105, 109, 108); +// +// this.cardList.addAll(list2); +// this.cardList.addAll(list); +// this.cardList.addAll(list3); +// } + + private void shuffle() { + for(int i = 0;i < 100;i++) { + Collections.shuffle(this.cardList); + } + } + + public int pop() { + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/RuleWeight.java b/game_zp_paohuzi/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..259ac8f --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,46 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10; + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; + public final static int WU_HU = 2; + public final static int DIAN_HU = 3; + public final static int DUIZI_HU = 4; + public final static int TIAN_HU = 5; + public final static int DI_HU = 6; + public final static int HAI_HU = 7; + public final static int TING_HU = 8; + public final static int DA_HU = 9; + public final static int XIAO_HU = 10; + public final static int DA_TUAN_YUAN = 11; + public final static int XING_XING_XI = 12; + public final static int SI_QI_HONG = 13; + public final static int SHUA_HOU = 14; + public final static int HUANG_FAN = 15; + public final static int ZI_MO = 16; + public final static int JIA_XING_XING = 17; + public final static int HONG_WU = 18; + public final static int YUAN = 19; + public final static int BEI_KAO_BEI = 20; + public final static int SANSHI_XI_FAN = 21;//30息翻倍 +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..37c033f --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,34 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..5fb46b6 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,75 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 2 && card == player.drawCard) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + } + if (num == 3) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..7d85c36 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,82 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.plugin.redis.Redis; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import redis.clients.jedis.Jedis; + + +public class RuleDealTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 3) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..6ccb35c --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,61 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..c58451a --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,37 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..7634af7 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,81 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..b2fa1cc --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,55 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..df87829 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..0ad7640 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleTi.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleTi.java new file mode 100644 index 0000000..ef15e2f --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleTi.java @@ -0,0 +1,62 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRTiState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..0e9e852 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,41 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleWei implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..5fffee6 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,48 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isLaoYe) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + if (Paixing.checkWin(player, activePlayer.drawCard)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRCheck.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRCheck.java new file mode 100644 index 0000000..0e4dd0d --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRCheck.java @@ -0,0 +1,22 @@ +package extend.zp.player.rulestate; + +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import redis.clients.jedis.Jedis; + +public class PRCheck { + public static final Logger logger = Logger.getLogger(PRCheck.class); + + public static boolean check(EXPlayer owner) { + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao"+owner.room+owner.room.round+owner.playerid,"fanpao"); + jedis.close(); + if (fp!=null){ + return false; + } + return true; + } + + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..0f47d7b --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,69 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +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.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static void prChi(int card, EXPlayer owner) { + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + + __chow(owner, chowcard1, chowcard2, card, activePlayer, false); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + if (bi) { + CardUtil.removeCard(player.cardInhand, card, 1); + } + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + logger.info("jefe chowGroup,player:" + player.playerid + ",card1:" + chowcard1+",card2:"+card+",card3:"+chowcard2); + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..ed30148 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,42 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + + +public class PRChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..96900b8 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,98 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..7441809 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,41 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + +public class PRDrawChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java new file mode 100644 index 0000000..2710a3e --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java @@ -0,0 +1,106 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDrawPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + int fromseat = activePlayer.seat; + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..8478789 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,81 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRDrawPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + CardUtil.removeCard(owner.cardInhand, card, 2); + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..3274942 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,82 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + CardUtil.removeCard(owner.cardInhand, card, 2); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + this.toNextState(owner); + ; + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java new file mode 100644 index 0000000..9fb47bd --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRTiState.java @@ -0,0 +1,84 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRTiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + int card = owner.opCard.getInt(0); + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.tiGroup.add(tiGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..291addd --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,94 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + +import com.taurus.core.plugin.redis.Redis; +import redis.clients.jedis.Jedis; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + int card = owner.opCard.getInt(0); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + + owner.weiGroup.add(weiGroup); + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + //出喂 + logger.info("jefe chouwei,player:" + owner +",seat:"+owner.seat+",room:"+owner.room+ ",card:" + card+",type:"+type); + + if (type==4){ + //加入redis + + Jedis jedis = Redis.use("group1_db5").getJedis(); + jedis.hset("p"+owner.room+owner.room.round,type+","+card,card+""); + jedis.close(); + } + + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..7050ece --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,38 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + room.win(owner, activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..dc571a9 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,53 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..9cedf04 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,141 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.getRoom().tipMap.clear(); + if (owner.cardInhand.isEmpty()) { + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + logger.info("discard,player:" + owner + ",card:" + discard); + if (owner.seat == owner.room.bankerSeat) { + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + owner.outcardExList.add(discard); + exit(owner); + EXMainServer.gameCtr.outCard(owner, discard); + + owner.getRoom().isDiHu = false; + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + } else { + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().isAllPass) { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..81a0368 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,433 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } + else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else { + Global.logger.info("dealcards playerid:"+owner.playerid+ " general player"); + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + } + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..1f4e455 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,52 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..48344a0 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,109 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.Paixing; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.isAllPass = false; + owner.drawCard = room.card.pop(); + // owner.drawCard = 110; + + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + int drawCard = owner.drawCard; + owner.drawCard = 0; + owner.getRoom().isTianHu = false; + if (drawCard != 0) { + owner.cardInhand.add(drawCard); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } else { + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, owner.getRoom().drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + boolean win = false; + for (Entry entry : owner.getRoom().playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer player = (EXPlayer) entry.getValue(); + if(Paixing.checkWin(player, owner.drawCard)) { + win = true; + } + } + if(!win) + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..af786e1 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,40 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..c3abb79 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..e26516d --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,101 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + + this.toNextState(owner); + } + + //this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } + EXMainServer.gameCtr.dealCard(owner); + // Boolean qupaiV = owner.config.getBoolean(Config.ROOM_CONFIG_QUPAI); + // boolean qupai = (qupaiV == null) ? false : qupaiV; + int qupaiV = owner.config.getInt(Config.ROOM_CONFIG_QUPAI); + if (owner.maxPlayers == 2 && qupaiV>0) { + for (int index = 0; index < 20; index++) { + owner.throwCardsList.add(owner.card.pop()); + } + } + // owner.isplaying = true; + // owner.round += 1; + owner.playBackData = new PlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..32697d3 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,35 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + // TODO Auto-generated method stub + //owner.readyCount = 0; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + } + // if (owner.round == 0) { + owner.startGame(); + // } + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + // TODO Auto-generated method stub + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/tip/Action.java b/game_zp_paohuzi/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_paohuzi/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/tip/Tip.java b/game_zp_paohuzi/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/tip/TipManager.java b/game_zp_paohuzi/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..39a67a8 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,178 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.RuleWeight; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + public int getUid(){ + return this.uid; + } + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass discardtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7608fca --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..976354f --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + } + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + result = handle(list,bi_card,bi_card) || result; + } + if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + result = handle(list,eventCard,bi_card) || result; + CardUtil.addCard(eventCard, cardMap, 1); + } + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..ab9143c --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,156 @@ +package extend.zp.uitl; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRChi; + + +public class Paixing { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static boolean checkWin(EXPlayer player, int drawCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (win.tryWin(player)) { + if (player.huXi >= 15) { + isWin = true; + } + } + if (!isWin) { + player.resetHuXi(); + if (player.getRoom().isTianHu) { + if (player.tiCount >= 3) { + player.isMingTang = false; + isWin = true; + } + if (player.kanGroup.size() >= 5) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 1 && player.kanGroup.size() >= 4) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 2 && player.kanGroup.size() >= 3) { + player.isMingTang = false; + isWin = true; + } + } + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + } + } + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + for (int i = 0; i < win.stack.size(); i++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(i).get(0); + opcard.card2 = win.stack.get(i).get(1); + opcard.type = 1; + if (win.stack.get(i).size() > 2) { + opcard.card3 = win.stack.get(i).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(i); + + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + + } + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 9; + } else { + huXi = 12; + } + break; + case RuleWeight.TYPE_PAO: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 6; + } else { + huXi = 9; + } + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + case RuleWeight.TYPE_KAN: + case RuleWeight.TYPE_CHOW: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 3; + } else { + huXi = 6; + } + break; + case RuleWeight.TYPE_PONG: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 1; + } else { + huXi = 3; + } + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..4de2c60 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,328 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard && player.getRoom().bankerSeat == player.seat) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + } + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.tiCount + player.kongCount > 0) { + if (this.pair_count == 1) { + return true; + } + return false; + } else { + if (this.pair_count > 0) { + return false; + } + return true; + } + } + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..aea44ac --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,381 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCardNew winCard2 = new WinCardNew(list, 106, 9, true, op); + /* op = winCard2.groupCard(207); */ + System.out.println(winCard2.checkHu()); + winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + + } + + /** + * + * @param cardInhand + * :����,�������� + * @param addCard + * : �Ӵ����Ƿ��ܺ���������������������Ҫ��0 + * @param huxi + * ��������еĺ�Ϣ + * @param isJiang + * ���Ƿ���Ҫ�� + */ + public WinCardNew(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + } +} diff --git a/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_paohuzi/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_paohuzi/src/test/java/game_zp_paohuzi/Main.java b/game_zp_paohuzi/src/test/java/game_zp_paohuzi/Main.java new file mode 100644 index 0000000..4f75ce5 --- /dev/null +++ b/game_zp_paohuzi/src/test/java/game_zp_paohuzi/Main.java @@ -0,0 +1,9 @@ +package game_zp_paohuzi; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_zp_shihuka/.idea/compiler.xml b/game_zp_shihuka/.idea/compiler.xml new file mode 100644 index 0000000..b4fff8d --- /dev/null +++ b/game_zp_shihuka/.idea/compiler.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_shihuka/.idea/encodings.xml b/game_zp_shihuka/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_zp_shihuka/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_zp_shihuka/.idea/jarRepositories.xml b/game_zp_shihuka/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_zp_shihuka/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_shihuka/.idea/misc.xml b/game_zp_shihuka/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_zp_shihuka/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_zp_shihuka/config/game-config.xml b/game_zp_shihuka/config/game-config.xml new file mode 100644 index 0000000..2079778 --- /dev/null +++ b/game_zp_shihuka/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.14.1 + 192.168.14.1 + 8811 + 8811 + 13 + true + \ No newline at end of file diff --git a/game_zp_shihuka/config/log4j.properties b/game_zp_shihuka/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_shihuka/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_shihuka/config/taurus-core.xml b/game_zp_shihuka/config/taurus-core.xml new file mode 100644 index 0000000..0f9fa8f --- /dev/null +++ b/game_zp_shihuka/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_shihuka/config/taurus-permanent.xml b/game_zp_shihuka/config/taurus-permanent.xml new file mode 100644 index 0000000..9cdaab3 --- /dev/null +++ b/game_zp_shihuka/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_shihuka/pom.xml b/game_zp_shihuka/pom.xml new file mode 100644 index 0000000..b5b75ed --- /dev/null +++ b/game_zp_shihuka/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_shihuka + game_zp_shihuka + 1.0.0 + jar + game_zp_shihuka + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_shihuka_zipai + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_shihuka/src/main/java/extend/zp/Config.java b/game_zp_shihuka/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..903ff66 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/Config.java @@ -0,0 +1,90 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 13; + + public static final String GAME_MODE = "mode"; + + public static final String GAME_TUN = "tun"; + + public static final String GAME_FENGDING = "fengding"; + + public static final String GAME_TUANYUAN = "tuanyuan"; + + public static final String GAME_HANGHANGXI = "hanghangxi"; + + public static final String GAME_SHUAHOU = "shuahou"; + + public static final String GAME_HUANGFAN = "huangfan"; + + public static final String GAME_JIAXINGXING = "jiaxingxing"; + + public static final String GAME_TINGHU = "tinghu"; + + public static final String GAME_SIQI = "siqi"; + + public static final String GAME_DUIZIFU = "duizifu"; + + public static final String GAME_YUAN = "yuan"; + + public static final String GAME_BEIKAOBEI = "back"; + + public static final String GAME_TIANHU = "tianhu"; + + public static final String GAME_DIHU = "dihu"; + + public static final String GAME_HAIHU = "haihu"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + // 1.��ׯ 2.��ׯ + // public static final String GAME_ZHUANG = "zhuang"; + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + + public static final String GAME_EVT_FANGWEI = "822"; + + public static final String GAME_EVT_FANGPAO = "823"; + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXActionEvent.java b/game_zp_shihuka/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..ee5df29 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,27 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXGameController.java b/game_zp_shihuka/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..6500263 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,388 @@ +package extend.zp; + +import java.util.Collections; +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.plugin.redis.Redis; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; +import redis.clients.jedis.Jedis; + +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + + public EXGameController() { + super(); + } + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender, ITObject params, int gid, Player owner) { + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender, ITObject params, int gid, Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player, params); + } + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender, ITObject params, int gid, Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + 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 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.getRoom().getPlayBack().addGetCardCommand(player.room.activeSeat, player.drawCard, leftCount); + } + + @ActionKey(Config.GAME_EVT_FANGPAO) + public void RouterFangwei(Session sender, ITObject params, int gid, Player owner) { + EXPlayer player = (EXPlayer) owner; + int discard = params.getInt("card"); + ITObject response = new TObject(); + response.putInt("seat", owner.seat); + response.putInt("card", discard); + logger.info("jefe GAME_EVT_FANGPAO:" + discard + ";player:" + player.playerid); + owner.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + + // 记录用户放跑 + Jedis jedis = Redis.use("group1_db5").getJedis(); + jedis.hset("pao" + player.room + player.room.round + player.playerid, "fanpao", discard + ""); + jedis.close(); + EXRoom room = player.getRoom(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + public void outCard(EXPlayer player, int discard) { + logger.info("jefe outcard:" + discard + ";player:" + player.playerid); + // 判断是否有喂 + Jedis jedis = Redis.use("group1_db5").getJedis(); + String wei = jedis.hget("p" + player.room + player.room.round, "4," + discard); + jedis.close(); + ITObject response = new TObject(); + response.putInt("seat", player.seat); + response.putInt("card", discard); + logger.info("jefe roomId:" + player.room + ",playerid:" + player.playerid + ",card:" + discard + ",wei:" + wei + + ",round:" + player.room.round); + if (wei != null) { + logger.info("jefe roomId:" + player.room + ",wei:" + wei); + // player.room.broadCastToClient(player.playerid, Config.GAME_EVT_FANGWEI, + // response); + player.sendEvent(Config.GAME_EVT_FANGWEI, response); + + } else { + + player.room.broadCastToClient(0, Config.GAME_EVT_DISCARD, response); + + EXRoom room = player.getRoom(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + CardUtil.removeCard(player.cardInhand, discard, 1); + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + // jedis.close(); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + // 放跑不能吃碰等 + + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao" + player.room + player.room.round + player.playerid, "fanpao"); + jedis.close(); + + if (fp != null) { + // 锁 + logger.info("jefe fanpao into:" + player.room + ",playerid:" + player.playerid); + // player.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + // player.room.broadCastToServer(player.playerid, EXActionEvent.EVENT_DEAL, + // null); + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } else { + EXRoom room = player.getRoom(); + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + } + + } + + public void dealCard(EXRoom owner) { + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.cardInhand = owner.card.deal(); + +// if (2 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 102, 102, 103, 103, 109, 201, 201, 202, 202, 203, 203, 204, 204, 204, 206, 207, 208, 209, 210"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (3 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "101, 101, 201, 201, 202, 202, 203, 203, 103, 104, 105, 106, 204, 207, 207, 107, 208, 209, 110, 110"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } +// if (1 == player.seat) { +// player.cardInhand.clear(); +// String cardStr = "102, 103, 103, 104, 104, 104, 107, 107, 107, 108, 110, 201, 202, 204, 205, 205, 206, 206, 206, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// player.cardInhand.add(card); +// } +// } + + Collections.sort(player.cardInhand); + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + + player.cardInhand); + } +// owner.card.cardList.clear(); +// String cardStr = "210, 105, 101, 209, 106, 203, 109, 109, 204, 109, 108, 207, 110, 103, 203, 201, 107, 106, 110, 201, 210, 208, 101, 201, 105, 210, 205, 102, 108, 208, 105, 108, 102, 207, 202, 103, 106, 210, 202, 209"; +// String[] cards = cardStr.split(", "); +// for(String c : cards) { +// Integer card = Integer.valueOf(c); +// owner.card.cardList.add(card); +// } + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + logger.info(param.toString()); + + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao" + owner.room + owner.room.round + owner.playerid, "fanpao"); + jedis.close(); + logger.info("jefe tipEvent:" + param.getInt("uid")); + // ITObject params = new TObject(); + // params.putInt("id",param.getInt("uid")); + + if (fp != null) { + + param.putInt("fptype", 1); + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } else { + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("xipai_score", owner.xi_pai_score); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.huXi); + param.putInt("tun", player.winScore); + player.hp_info(param); + if (owner.maxPlayers == 2) { + param.putInt("total_tun", player.score.round_score); + } else { + param.putInt("total_tun", player.score.round_score / 2); + } + + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + + if (player.winer == 1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (OpCard opCard : player.handCard) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + cardList.addTObject(obj); + } + param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + ITArray opCardList = TArray.newInstance(); + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + } + param.putTArray("opCardList", opCardList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); + param.putInt("win_count", player.winCount); + param.putInt("total_score", player.score.total_score); + player.hp_info(param); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + if (!dissmiss) { + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXMainServer.java b/game_zp_shihuka/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..c88c4c0 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,96 @@ +package extend.zp; + +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.zp.player.rulestate.PRChiState; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerPreDrawState; +import extend.zp.player.state.EXPlayerWaitState; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + + Global.registerState(PRTiState.class, new PRTiState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXPlayer.java b/game_zp_shihuka/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..b9f9c70 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,256 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +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.zp.player.rule.RuleChi; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public Stack handCard; + public List handCardEx; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashSet chouPongSet; + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public List mingtangList; + + public int kongCount = 0; + public int tiCount = 0; + // ��Ϣ + public int huXi = 0; + + public int total_huxi = 0; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("card_count", this.cardInhand.size()); + playerData.putInt("score", this.score.total_score); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (!self) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI) { + continue; + } + } else { + if (opCard.type == RuleWeight.TYPE_KAN) { + continue; + } + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 0; + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + } + + public void clear() { + this.cardInhand.clear(); + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.kongCount = 0; + this.tiCount = 0; + this.huXi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.tiGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouPongSet.clear(); + this.mingtangList.clear(); + this.score.resetRound(); + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + return card.getKey(); + } + } + return 0; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + if (this.cardInhand.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + // ���� + if (this.chouChiSet.contains(eventCard)) { + return false; + } + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + return false; + } + + ChowCard chow = new ChowCard(this.cardInhand, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + } + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXRoom.java b/game_zp_shihuka/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..c1ce5d3 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1265 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Stack; + +import com.game.Global; +import com.game.Router; +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.*; +import com.taurus.core.util.Logger; + +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import extend.zp.uitl.WinCard; + + +public class EXRoom extends Room { + Logger logger = Logger.getLogger(getClass()); + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; + public boolean isTianHu = true; + public boolean isDiHu = true; + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public int typeface = 1; + + public ITObject paiXing; + public int adminSeat; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + 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); + } + this.adminSeat = 0; + } + + public void changePaiXing(EXPlayer player, ITObject params) { + ITArray paixing = null; + try { + paixing = params.getTArray("card_list"); + } + catch(Exception e) + { + + } + + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < paixing.size(); i++) + { + TDataWrapper card = paixing.get(i); + TObject map = (TObject)card.getObject(); + tmpCardList.add(map.getInt("card")); + } + + Collections.sort(tmpCardList); + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(player.cardInhand); + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + } + } + Collections.sort(tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2)) + { + ITObject param = new TObject(); + player.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + + paiXing.putTArray(player.seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", player.seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(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); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat == player.seat) { + self = true; + } + info_list.addTObject(tempPlayer.getReloadInfo(self)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + + player.score.round_score += score; + player.score.total_score += score; + } + + public void addScore(EXPlayer destPlayer) { + int score = caclScore(destPlayer); + //先判断分够不够 + int tmp_all_score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + if (!entry.getKey().equals(destPlayer.playerid)) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + //// + if(multipleScore(score) > fromPlayer.hp.cur_hp) { + tmp_all_score += reMultipleScore((int)fromPlayer.hp.cur_hp); + this.addScore(fromPlayer, -reMultipleScore((int)fromPlayer.hp.cur_hp), EXScore.WIN); + }else { + tmp_all_score += score; + this.addScore(fromPlayer, -score, EXScore.WIN); + } + } + } + // + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + this.addScore(destPlayer, tmp_all_score, EXScore.WIN); + } + } + + //// +// for (Entry entry : this.playerMapById.entrySet()) { +// if (entry.getKey().equals(destPlayer.playerid)) { +// if (this.maxPlayers == 2) { +// this.addScore(destPlayer, score, EXScore.WIN); +// } else { +// this.addScore(destPlayer, score * 2, EXScore.WIN); +// } +// } else { +// EXPlayer fromPlayer = (EXPlayer) entry.getValue(); +// this.addScore(fromPlayer, -score, EXScore.WIN); +// } +// } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 0; + int huXiNum = 0; + boolean isDuzi = true; + int huangFan = 0; + + //ssdd + if (!player.handCardEx.isEmpty()) { + isDuzi = false; + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (opCard.type == 2) { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + isDuzi = false; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + if (opCard.type == RuleWeight.TYPE_CHOW) { + isDuzi = false; + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + player.mingtangList.clear(); + player.winFan = 0; + player.huXi = huXi; + player.total_huxi = huXi; + player.winScore =huXi-huXi%3;//jefe (huXi - 15) / 3 + 1 + + + int score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (!player.isMingTang) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + if (player.seat == this.bankerSeat) { + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } else { + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + player.winFan += 6; + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 + redCard - 10; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 5; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 3; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + } else if (player.room.config.getInt(Config.GAME_MODE) == 1) {//jefe + if (huXi>=30){ + player.winFan += 2; + }else { + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 1) { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 4)); + } + } else { + if (this.config.getInt(Config.GAME_DIHU) == 1) { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 4)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + } + } + + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + + return score; + } + // ��� + if (redCard >= 10) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 3 + redCard - 10; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (redCard < 13) { + fan = 2; + } + } else { + fan = 2 ;//jefe 2 + redCard - 10 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + if (this.config.getInt(Config.GAME_MODE) == 2) { + // ���� + if (redCard >= 13) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.HONG_WU, 1, 4)); + } + } + // �ں� + if (redCard == 0) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 8; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 5; + } else { + fan = 2;//jefe 5 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + // ��� + if (redCard == 1) { + int fan = 0; + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + fan = 6; + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + fan = 3; + } else { + fan = 2;//jefe 3 + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + // ���Ӻ� + if (isDuzi) { + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 8)); + } else if (this.config.getInt(Config.GAME_MODE) == 2) { + if (this.config.getInt(Config.GAME_DUIZIFU) == 1) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 4)); + } + } else { + player.winFan += 2;//jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 2)); + } + } + // ���� + if (this.winSeat == player.seat) { + //player.winScore += 1; jefe + player.mingtangList.add(new MingTang(RuleWeight.ZI_MO, 2, 1*3));//jefe *3 + } + // ȫ���� + if (this.config.getInt(Config.GAME_MODE) == 3) {//jefe + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 6)); + } + // �غ� + else { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 6)); + } + } + // ���� + if (this.card.getCount() == 0) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 6)); + } + // ���� + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + if (player.isTingHu) { + player.winFan += 6; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 6)); + } + } + // ��� + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + + // С�� + if (smallCard >= 16) { + int fan = 10 + smallCard - 16; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + + // ����Բ + if (this.config.getInt(Config.GAME_TUANYUAN) == 1) { + int duan = 0; + for (int i = 1; i <= 10; i++) { + int num = 0; + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + if (opCard.card1 % 100 == i) { + num++; + } + } + if (num == 2) { + duan++; + } + } + if (duan > 0) { + int fan = duan * 8; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_TUAN_YUAN, 1, fan)); + } + } + // ����Ϣ + if (this.config.getInt(Config.GAME_HANGHANGXI) == 1) { + if (huXiNum == 7) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 8)); + } + } + // ������Ϣ + if (this.config.getInt(Config.GAME_JIAXINGXING) == 1) { + if ((player.tiCount + player.kongCount) > 0) { + if (huXiNum == 6) { + player.winFan += 4; + player.mingtangList.add(new MingTang(RuleWeight.JIA_XING_XING, 1, 4)); + } + } + } + // ���ߺ� + if (this.config.getInt(Config.GAME_SIQI) == 1) { + if (redCard == 4 || redCard == 7) { + player.winFan += 2; + player.mingtangList.add(new MingTang(RuleWeight.SI_QI_HONG, 1, 2)); + } + } + // ˣ�� + if (this.config.getInt(Config.GAME_SHUAHOU) == 1) { + if (player.kanGroup.isEmpty() && player.cardInhand.size() == 1) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.SHUA_HOU, 1, 8)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + } + // Բ + if (this.config.getInt(Config.GAME_YUAN) == 1) { + List cardList = new ArrayList<>(); + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_PAO && opCard.type != RuleWeight.TYPE_TI) { + continue; + } + cardList.add(opCard.card1); + } + if (!cardList.isEmpty()) { + Collections.sort(cardList); + int yuan = 0; + int num = cardList.get(0); + for (int i = 1; i < cardList.size(); i++) { + if (num + 1 == cardList.get(i)) { + yuan++; + } + num = cardList.get(i); + } + if (yuan > 0) { + int fan = yuan * 6; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.YUAN, 1, fan)); + } + } + } + // ������ + if (this.config.getInt(Config.GAME_BEIKAOBEI) == 1) { + boolean kezi1 = false; + boolean kezi2 = false; + boolean isBeiKaoBei = true; + for (OpCard opCard : player.handCard) { + if (opCard.type == 1) { + if (opCard.card1 != player.winCard && opCard.card1 % 100 == player.winCard % 100) { + kezi1 = true; + continue; + } + break; + } else { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + if (opCard.card1 == player.winCard || opCard.card2 == player.winCard || opCard.card3 == player.winCard) { + isBeiKaoBei = false; + break; + } + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (isBeiKaoBei) { + for (OpCard opCard : player.opCardList) { + if (opCard.type != RuleWeight.TYPE_WEI && opCard.type != RuleWeight.TYPE_CHOUWEI && opCard.type != RuleWeight.TYPE_KAN) { + continue; + } + if (opCard.card1 == player.winCard) { + kezi2 = true; + } + } + } + if (kezi1 && kezi2) { + player.winFan += 8; + player.mingtangList.add(new MingTang(RuleWeight.BEI_KAO_BEI, 1, 8)); + } + } + } + // ���෬ + if (this.config.getInt(Config.GAME_MODE) == 1) {//jefe + if (this.isTianHu) { + // ��� + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.GAME_TIANHU) == 0) {//jefe 1 + player.winFan += 2; //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 2)); + } + } + // �غ� + else { + if (this.config.getInt(Config.GAME_DIHU) == 0) { //jefe 1 + player.winFan += 2;// jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 2)); + } + } + } + // ���� + if (this.config.getInt(Config.GAME_HAIHU) == 1) {// + if (this.card.getCount() == 0) { + player.winFan += 2; // //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 2)); + } + } + /* + if (this.config.getInt(Config.GAME_TINGHU) == 1) { + // ���� + if (player.isTingHu) { + player.winFan += 2; //jefe 4 + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 2)); + } + } + // �Ʒ� + if (this.config.getInt(Config.GAME_HUANGFAN) == 1) { + if (this.liujuNum > 0) { + huangFan = this.liujuNum; + player.mingtangList.add(new MingTang(RuleWeight.HUANG_FAN, 3, huangFan + 1)); + } + }*/ + + if (bigCard >= 18) { + int fan = 8 + bigCard - 18; + fan = 2;//jefe + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + + // С�� + if (smallCard >= 18) { + int fan = 10 + smallCard - 18; + fan = 2;//jefe + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + + //30息翻倍 jefe + if(player.winFan<=1&&huXi>=30){ + player.winFan += 2;//jefe fan + player.mingtangList.add(new MingTang(RuleWeight.SANSHI_XI_FAN, 1, 2)); + } + + } + score = player.winScore + this.config.getInt(Config.GAME_TUN); + if (player.winFan > 0) { + score *= player.winFan; + } + if (huangFan > 0) { + score *= (huangFan + 1); + } + if (this.config.getInt(Config.GAME_FENGDING) == 1) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 100); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 20); + } else { + score = Math.min(score, 60); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 2) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 200); + } else if (player.room.config.getInt(Config.GAME_MODE) == 2) { + score = Math.min(score, 40); + } else { + score = Math.min(score, 80); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 3) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 300); + } + } + if (this.config.getInt(Config.GAME_FENGDING) == 4) { + if (player.room.config.getInt(Config.GAME_MODE) == 3) {//jefe + score = Math.min(score, 500); + } + } + //jefe *3 + if (this.winSeat == player.seat) { + score += 3; + } + + return score; + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + // public void settleRound() { + // saveMilitaryRound(playBackData.getData(this)); + // if (this.liuju == true) { + // this.bankerSeat = this.playerMapBySeat.get(this.bankerSeat).nextSeat; + // } + // boolean total = this.round >= this.maxRound; + // int result = this.nonNegative(false); + // if (!total) { + // EXMainServer.gameCtr.roomResult(this); + // if (result == 4) { + // total = true; + // this.saveMilitaryTotal(false); + // } + // } else { + // this.saveMilitaryTotal(false); + // } + // this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + // this.winCount = 0; + // + // if (total) { + // this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + // return; + // } + // } + + public void win(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + player.winCard = player.getRoom().drawCard; + } + player.winer = 1; + int scoreSrc = caclScore(player); + if (player.handCard.isEmpty()) { + scoreSrc = 0; + } + player.resetHuXi(); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + + Stack handCard = new Stack(); + List handCardEx = new ArrayList<>(); + handCard.addAll(player.handCard); + handCardEx.addAll(player.handCardEx); + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (activePlayer.drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.pongGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] pongGroup = new int[3]; + pongGroup[0] = activePlayer.drawCard; + pongGroup[1] = activePlayer.drawCard; + pongGroup[2] = activePlayer.drawCard; + + player.pongGroup.add(pongGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (activePlayer.drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.kanGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] kanGroup = new int[3]; + kanGroup[0] = activePlayer.drawCard; + kanGroup[1] = activePlayer.drawCard; + kanGroup[2] = activePlayer.drawCard; + + player.kanGroup.add(kanGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (activePlayer.drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + + WinCard win = new WinCard(player.cardInhand, 0); + if (win.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + if (player.huXi - huXi1 + huXi >= 15) { + player.weiGroup.remove(i); + + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] paoGroup = new int[4]; + paoGroup[0] = activePlayer.drawCard; + paoGroup[1] = activePlayer.drawCard; + paoGroup[2] = activePlayer.drawCard; + paoGroup[3] = activePlayer.drawCard; + + player.paoGroup.add(paoGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PAO, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + for (int j = 0; j < win.stack.size(); j++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(j).get(0); + opcard.card2 = win.stack.get(j).get(1); + opcard.type = 1; + if (win.stack.get(j).size() > 2) { + opcard.card3 = win.stack.get(j).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(j); + + player.handCard.push(opcard); + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + + int scoreDes = caclScore(player); + if (scoreDes < scoreSrc) { + for (int j = 0; j < player.paoGroup.size(); j++) { + if (activePlayer.drawCard == player.paoGroup.get(j)[0]) { + player.paoGroup.remove(j); + break; + } + } + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PAO, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, 0)); + + int[] weiGroup = new int[3]; + weiGroup[0] = activePlayer.drawCard; + weiGroup[1] = activePlayer.drawCard; + weiGroup[2] = activePlayer.drawCard; + + player.weiGroup.add(weiGroup); + + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, activePlayer.drawCard); + player.opCardList.add(new OpCard(RuleWeight.TYPE_WEI, activePlayer.drawCard, activePlayer.drawCard, activePlayer.drawCard, huXi)); + + player.handCard.clear(); + player.handCardEx.clear(); + + player.handCard.addAll(handCard); + player.handCardEx.addAll(handCardEx); + + player.kongCount--; + } + } else { + player.kongCount--; + } + } else { + player.kongCount--; + } + break; + } + } + } + this.addScore(player); + // this.liuju = false; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(player.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + EXMainServer.gameCtr.winEvent(player, player.seat); + // if (owner.room.config.getInt(Config.GAME_ZHUANG) == 1) { + // if (room.bankerSeat != owner.seat) { + // room.bankerSeat = owner.lastSeat; + // } + // } else { + // room.bankerSeat = owner.seat; + // } + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + } + + @Override + public void endGame() { + super.endGame(); + } + + public void saveRecRound() { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.saveRecRound(); + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void clear() { + super.clear(); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + } + // public void destroy() { + // super.destroy(); + // } + + /** + * 开启倍数后 体力值消耗= 倍数*分数 + */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/EXScore.java b/game_zp_shihuka/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/MingTang.java b/game_zp_shihuka/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..82b8723 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,13 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; + public int score; + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/OpCard.java b/game_zp_shihuka/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..bbd5df6 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,35 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + public boolean pailie; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = false; + } + + public OpCard(int type, int card1, int card2, int card3, int huXi, boolean pailei) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = pailei; + } + + public OpCard() { + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/PlayBack.java b/game_zp_shihuka/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..74f6ad7 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_shihuka/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..86ffaef --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,121 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.RuleChi; +import extend.zp.player.rule.RuleDealKan; +import extend.zp.player.rule.RuleDealTi; +import extend.zp.player.rule.RuleDiscardPao; +import extend.zp.player.rule.RuleDrawChi; +import extend.zp.player.rule.RuleDrawPao; +import extend.zp.player.rule.RuleDrawPong; +import extend.zp.player.rule.RuleKan; +import extend.zp.player.rule.RulePong; +import extend.zp.player.rule.RuleTi; +import extend.zp.player.rule.RuleWei; +import extend.zp.player.rule.RuleWin; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + drawPaoList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List otherHuList = new ArrayList(); + otherHuList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/RoomCard.java b/game_zp_shihuka/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..abe4238 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,104 @@ +package extend.zp; + +import java.util.*; + +public class RoomCard { + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + this.subCardList = new ArrayList<>(); + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + +// private void initCard2() { +// List list = Arrays.asList(102, 103, 105, 106, 106, 107, 108, 108, 109, 110, 110, 110, 110, 201, 202, 207, 209, 209, 210, 210); +// List list2 = Arrays.asList(101, 101, 104, 104, 105, 107, 107, 109, 201, 201, 203, 203, 203, 203, 204, 206, 207, 208, 209, 210); +// List list3 = Arrays.asList(205, 106, 108, 208, 209, 105, 106, 206, 102, 105, 104, 108, 102, 107, 202, 106, 206, 202, 104, 204, 102, 108, 208, 207, 208, 205, 205, 201, 202, 101, 103, 206, 103, 209, 208, 210, 102, 105, 109, 108); +// +// this.cardList.addAll(list2); +// this.cardList.addAll(list); +// this.cardList.addAll(list3); +// } + + private void shuffle() { + for(int i = 0;i < 100;i++) { + Collections.shuffle(this.cardList); + } + } + + public int pop() { + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + + return dealCards; + } + + public void reInitCards(List cards) { +// Global.logger.info("sub before===>"+subCardList.size()); +// this.subCardList.addAll(cards); + //从底牌移除 +// Global.logger.info("before===>"+cardList.size()); + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { +// Global.logger.info("bidui===>"+cardList.get(i)+":"+Integer.valueOf(card)); + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } +// Global.logger.info("sub after===>"+subCardList.size()); +// Global.logger.info("after===>"+cardList.size()); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/RuleWeight.java b/game_zp_shihuka/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..259ac8f --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,46 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10; + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; + public final static int WU_HU = 2; + public final static int DIAN_HU = 3; + public final static int DUIZI_HU = 4; + public final static int TIAN_HU = 5; + public final static int DI_HU = 6; + public final static int HAI_HU = 7; + public final static int TING_HU = 8; + public final static int DA_HU = 9; + public final static int XIAO_HU = 10; + public final static int DA_TUAN_YUAN = 11; + public final static int XING_XING_XI = 12; + public final static int SI_QI_HONG = 13; + public final static int SHUA_HOU = 14; + public final static int HUANG_FAN = 15; + public final static int ZI_MO = 16; + public final static int JIA_XING_XING = 17; + public final static int HONG_WU = 18; + public final static int YUAN = 19; + public final static int BEI_KAO_BEI = 20; + public final static int SANSHI_XI_FAN = 21;//30息翻倍 +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..37c033f --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,34 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..5fb46b6 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,75 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if(num == 2 && card == player.drawCard) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + } + if (num == 3) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true)); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..7d85c36 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,82 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.plugin.redis.Redis; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; +import redis.clients.jedis.Jedis; + + +public class RuleDealTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 3) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..6ccb35c --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,61 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..c58451a --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,37 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..7634af7 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,81 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..b2fa1cc --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,55 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..df87829 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card))); + EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..0ad7640 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,53 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.cardInhand.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleTi.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleTi.java new file mode 100644 index 0000000..ef15e2f --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleTi.java @@ -0,0 +1,62 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRTiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleTi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.winCard = player.drawCard; + player.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + break; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRTiState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..0e9e852 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,41 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.player.rulestate.PRCheck; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleWei implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.drawCard; + //判断是否可以偎 + boolean c = PRCheck.check(player); + if (!c){ + return false; + } + + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..5fffee6 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,48 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isLaoYe) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + if (Paixing.checkWin(player, activePlayer.drawCard)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRCheck.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRCheck.java new file mode 100644 index 0000000..0e4dd0d --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRCheck.java @@ -0,0 +1,22 @@ +package extend.zp.player.rulestate; + +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import redis.clients.jedis.Jedis; + +public class PRCheck { + public static final Logger logger = Logger.getLogger(PRCheck.class); + + public static boolean check(EXPlayer owner) { + Jedis jedis = Redis.use("group1_db5").getJedis(); + String fp = jedis.hget("pao"+owner.room+owner.room.round+owner.playerid,"fanpao"); + jedis.close(); + if (fp!=null){ + return false; + } + return true; + } + + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..0f47d7b --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,69 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +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.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static void prChi(int card, EXPlayer owner) { + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + + __chow(owner, chowcard1, chowcard2, card, activePlayer, false); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + if (bi) { + CardUtil.removeCard(player.cardInhand, card, 1); + } + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + logger.info("jefe chowGroup,player:" + player.playerid + ",card1:" + chowcard1+",card2:"+card+",card3:"+chowcard2); + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..ed30148 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,42 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + + +public class PRChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..96900b8 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,98 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..7441809 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,41 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; + +public class PRDrawChiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java new file mode 100644 index 0000000..2710a3e --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPaoState.java @@ -0,0 +1,106 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDrawPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + int fromseat = activePlayer.seat; + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..8478789 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,81 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRDrawPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + CardUtil.removeCard(owner.cardInhand, card, 2); + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..3274942 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,82 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + CardUtil.removeCard(owner.cardInhand, card, 2); + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + this.toNextState(owner); + ; + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRTiState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRTiState.java new file mode 100644 index 0000000..9fb47bd --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRTiState.java @@ -0,0 +1,84 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRTiState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + int card = owner.opCard.getInt(0); + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.tiGroup.add(tiGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..291addd --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,94 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + +import com.taurus.core.plugin.redis.Redis; +import redis.clients.jedis.Jedis; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + int card = owner.opCard.getInt(0); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + + owner.weiGroup.add(weiGroup); + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + //出喂 + logger.info("jefe chouwei,player:" + owner +",seat:"+owner.seat+",room:"+owner.room+ ",card:" + card+",type:"+type); + + if (type==4){ + //加入redis + + Jedis jedis = Redis.use("group1_db5").getJedis(); + jedis.hset("p"+owner.room+owner.room.round,type+","+card,card+""); + jedis.close(); + } + + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.tiCount > 1) { + owner.tiCount--; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..7050ece --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,38 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + room.win(owner, activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..dc571a9 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,53 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..9cedf04 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,141 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.getRoom().tipMap.clear(); + if (owner.cardInhand.isEmpty()) { + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + + @Override + public void toNextState(EXPlayer owner) { + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + if (!Util.checkCard(discard, owner.cardInhand)) { + ITObject reconParam = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam); + return; + } + logger.info("discard,player:" + owner + ",card:" + discard); + if (owner.seat == owner.room.bankerSeat) { + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + owner.outcardExList.add(discard); + exit(owner); + EXMainServer.gameCtr.outCard(owner, discard); + + owner.getRoom().isDiHu = false; + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + } else { + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().isAllPass) { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..81a0368 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,433 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + if(owner.seat == room.adminSeat) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " adminseat"); + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) + { + Global.logger.info("dealcards playerid:"+owner.playerid+ " xingyuhao:"+owner.is_white+" white_value:"+room.white_value); + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } + else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else + { + if(owner.black_white_status == 2) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " white player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + Global.logger.info("dealcards playerid:"+owner.playerid+ " black player:" + owner.black_white_rate); + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else { + Global.logger.info("dealcards playerid:"+owner.playerid+ " general player"); + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + } + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..1f4e455 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,52 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.type == RuleWeight.TYPE_WIN) { + id = tip.id; + break; + } + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..48344a0 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,109 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXGameController; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; +import extend.zp.uitl.Paixing; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + room.isAllPass = false; + owner.drawCard = room.card.pop(); + // owner.drawCard = 110; + + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + int drawCard = owner.drawCard; + owner.drawCard = 0; + owner.getRoom().isTianHu = false; + if (drawCard != 0) { + owner.cardInhand.add(drawCard); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } else { + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, owner.getRoom().drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + boolean win = false; + for (Entry entry : owner.getRoom().playerMapById.entrySet()) { + if (entry.getKey().equals(owner.playerid)) { + continue; + } + EXPlayer player = (EXPlayer) entry.getValue(); + if(Paixing.checkWin(player, owner.drawCard)) { + win = true; + } + } + if(!win) + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..af786e1 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,40 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..c3abb79 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..e26516d --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,101 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + + this.toNextState(owner); + } + + //this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + owner.card.init(); + if (owner.bankerSeat == 0) { + owner.bankerSeat = 1; + } + EXMainServer.gameCtr.dealCard(owner); + // Boolean qupaiV = owner.config.getBoolean(Config.ROOM_CONFIG_QUPAI); + // boolean qupai = (qupaiV == null) ? false : qupaiV; + int qupaiV = owner.config.getInt(Config.ROOM_CONFIG_QUPAI); + if (owner.maxPlayers == 2 && qupaiV>0) { + for (int index = 0; index < 20; index++) { + owner.throwCardsList.add(owner.card.pop()); + } + } + // owner.isplaying = true; + // owner.round += 1; + owner.playBackData = new PlayBack(owner); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..32697d3 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,35 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + // TODO Auto-generated method stub + //owner.readyCount = 0; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + } + // if (owner.round == 0) { + owner.startGame(); + // } + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + // TODO Auto-generated method stub + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/tip/Action.java b/game_zp_shihuka/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_shihuka/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/tip/Tip.java b/game_zp_shihuka/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/tip/TipManager.java b/game_zp_shihuka/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..39a67a8 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,178 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.RuleWeight; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + public int getUid(){ + return this.uid; + } + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass discardtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + } + } + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7608fca --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..976354f --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + List removeList = new ArrayList(); + for (Entry entry1 : cardMap.entrySet()) { + int card = entry1.getKey(); + int num = entry1.getValue(); + if(num>=3)removeList.add(card); + } + + for(Integer card : removeList) { + cardMap.remove(card); + } + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + result = handle(list,bi_card,bi_card) || result; + } + if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + result = handle(list,eventCard,bi_card) || result; + CardUtil.addCard(eventCard, cardMap, 1); + } + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..ab9143c --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,156 @@ +package extend.zp.uitl; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRChi; + + +public class Paixing { + public static final Logger logger = Logger.getLogger(PRChi.class); + + public static boolean checkWin(EXPlayer player, int drawCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player.cardInhand, drawCard); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (win.tryWin(player)) { + if (player.huXi >= 15) { + isWin = true; + } + } + if (!isWin) { + player.resetHuXi(); + if (player.getRoom().isTianHu) { + if (player.tiCount >= 3) { + player.isMingTang = false; + isWin = true; + } + if (player.kanGroup.size() >= 5) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 1 && player.kanGroup.size() >= 4) { + player.isMingTang = false; + isWin = true; + } + if (player.tiCount >= 2 && player.kanGroup.size() >= 3) { + player.isMingTang = false; + isWin = true; + } + } + + for (int i = 0; i < player.pongGroup.size(); i++) { + if (drawCard == player.pongGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_PONG, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_KAN, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + player.kongCount++; + WinCard win1 = new WinCard(player.cardInhand, 0); + if (win1.tryWin(player)) { + int huXi1 = Paixing.caclHuxi(RuleWeight.TYPE_WEI, drawCard); + int huXi2 = Paixing.caclHuxi(RuleWeight.TYPE_PAO, drawCard); + if (player.huXi - huXi1 + huXi2 >= 15) { + isWin = true; + } + } + player.kongCount--; + break; + } + } + } + } + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + for (int i = 0; i < win.stack.size(); i++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(i).get(0); + opcard.card2 = win.stack.get(i).get(1); + opcard.type = 1; + if (win.stack.get(i).size() > 2) { + opcard.card3 = win.stack.get(i).get(2); + opcard.type = 2; + } + opcard.huXi = win.stackHuxi.get(i); + + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + + } + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 9; + } else { + huXi = 12; + } + break; + case RuleWeight.TYPE_PAO: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 6; + } else { + huXi = 9; + } + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + case RuleWeight.TYPE_KAN: + case RuleWeight.TYPE_CHOW: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 3; + } else { + huXi = 6; + } + break; + case RuleWeight.TYPE_PONG: + if (cardType == RuleWeight.SMALL_CARD) { + huXi = 1; + } else { + huXi = 3; + } + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..4de2c60 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,328 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard && player.getRoom().bankerSeat == player.seat) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + } + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean tryPair(int card) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.tiCount + player.kongCount > 0) { + if (this.pair_count == 1) { + return true; + } + return false; + } else { + if (this.pair_count > 0) { + return false; + } + return true; + } + } + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (player.tiCount + player.kongCount > 0) { + if (tryPair(activeCard)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + this.stackHuxi.pop(); + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + } + + return false; + } + + public WinCard(List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..aea44ac --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,381 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCardNew winCard2 = new WinCardNew(list, 106, 9, true, op); + /* op = winCard2.groupCard(207); */ + System.out.println(winCard2.checkHu()); + winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + + } + + /** + * + * @param cardInhand + * :����,�������� + * @param addCard + * : �Ӵ����Ƿ��ܺ���������������������Ҫ��0 + * @param huxi + * ��������еĺ�Ϣ + * @param isJiang + * ���Ƿ���Ҫ�� + */ + public WinCardNew(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + } +} diff --git a/game_zp_shihuka/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_shihuka/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_shihuka/src/test/java/game_zp_shihuka/Main.java b/game_zp_shihuka/src/test/java/game_zp_shihuka/Main.java new file mode 100644 index 0000000..46d41b1 --- /dev/null +++ b/game_zp_shihuka/src/test/java/game_zp_shihuka/Main.java @@ -0,0 +1,9 @@ +package game_zp_shihuka; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/game_zp_yueyangwaihuzi/.idea/compiler.xml b/game_zp_yueyangwaihuzi/.idea/compiler.xml new file mode 100644 index 0000000..2cc2636 --- /dev/null +++ b/game_zp_yueyangwaihuzi/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/.idea/encodings.xml b/game_zp_yueyangwaihuzi/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/game_zp_yueyangwaihuzi/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/.idea/jarRepositories.xml b/game_zp_yueyangwaihuzi/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/game_zp_yueyangwaihuzi/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/.idea/misc.xml b/game_zp_yueyangwaihuzi/.idea/misc.xml new file mode 100644 index 0000000..d5cd614 --- /dev/null +++ b/game_zp_yueyangwaihuzi/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/.idea/vcs.xml b/game_zp_yueyangwaihuzi/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/game_zp_yueyangwaihuzi/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/config/game-config.xml b/game_zp_yueyangwaihuzi/config/game-config.xml new file mode 100644 index 0000000..2e59600 --- /dev/null +++ b/game_zp_yueyangwaihuzi/config/game-config.xml @@ -0,0 +1,10 @@ + + + + 192.168.3.9 + 192.168.3.9 + 4016 + 8960 + 301 + true + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/config/log4j.properties b/game_zp_yueyangwaihuzi/config/log4j.properties new file mode 100644 index 0000000..aaea5f3 --- /dev/null +++ b/game_zp_yueyangwaihuzi/config/log4j.properties @@ -0,0 +1,19 @@ +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=logs/mpnet.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd | HH:mm} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/config/taurus-core.xml b/game_zp_yueyangwaihuzi/config/taurus-core.xml new file mode 100644 index 0000000..69a7e20 --- /dev/null +++ b/game_zp_yueyangwaihuzi/config/taurus-core.xml @@ -0,0 +1,50 @@ + + + log4j.properties + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/config/taurus-permanent.xml b/game_zp_yueyangwaihuzi/config/taurus-permanent.xml new file mode 100644 index 0000000..7a303d2 --- /dev/null +++ b/game_zp_yueyangwaihuzi/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 2 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 10 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + extend.zp.EXMainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/game_zp_yueyangwaihuzi/pom.xml b/game_zp_yueyangwaihuzi/pom.xml new file mode 100644 index 0000000..76daf49 --- /dev/null +++ b/game_zp_yueyangwaihuzi/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + + com.zp.game_zp_yueyangwaihuzi + game_zp_yueyangwaihuzi + 1.0.0 + jar + game_zp_yueyangwaihuzi + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.game + game_common + 1.0.0 + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + game_zp_yueyangwaihuzi + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/.DS_Store b/game_zp_yueyangwaihuzi/src/main/java/extend/.DS_Store new file mode 100644 index 0000000..69f20b7 Binary files /dev/null and b/game_zp_yueyangwaihuzi/src/main/java/extend/.DS_Store differ diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/.DS_Store b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/.DS_Store new file mode 100644 index 0000000..5283e37 Binary files /dev/null and b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/.DS_Store differ diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/Config.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/Config.java new file mode 100644 index 0000000..b0313d9 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/Config.java @@ -0,0 +1,115 @@ +package extend.zp; + +public class Config { + + public static final int GAME_ID = 301; + public static final int XIPAI_SCORE = 10; + + public static final String GAME_MODE = "mode"; // 1 全名堂 2 红黑点 3 多红多番 + + public static final String GAME_TUN = "tun"; + + public static final String GAME_FENGDING = "fengding"; //封顶 + + public static final String GAME_TUANYUAN = "tuanyuan"; //团员 + + public static final String GAME_HANGHANGXI = "hanghangxi"; //行行息 + + public static final String GAME_SHUAHOU = "shuahou"; //耍猴 + + public static final String GAME_HUANGFAN = "huangfan"; //黄番 + + public static final String GAME_JIAXINGXING = "jiaxingxing"; //假行行 + + public static final String GAME_TINGHU = "tinghu"; //听胡 + + public static final String GAME_SIQI = "siqi"; + + public static final String GAME_DUIZIFU = "duizifu"; + + public static final String GAME_YUAN = "yuan"; + + public static final String GAME_BEIKAOBEI = "back"; + + public static final String GAME_TIANHU = "tianhu"; + + public static final String GAME_DIHU = "dihu"; + + public static final String GAME_HAIHU = "haihu"; + + public static final String ROOM_CONFIG_QUPAI = "qupai"; + + public static final String ROOM_CONFIG_KA_WAI = "kawai"; + + public static final String ROOM_CONFIG_ZHUANG_DI_HU = "zhuang_di_hu"; //庄家地胡 + + public static final String ROOM_CONFIG_HAO_CONFIG = "hao_config"; //0毫123 1毫234 + + public static final String ROOM_CONFIG_HAO_JIABEI = "hao_jiabei"; //0加倍 + + public static final String ROOM_CONFIG_MENG_TANG = "ming_tang"; //名堂 + + public static final String ROOM_CONFIG_FIRST_RAND_ZHUANG = "first_rand_zhuang"; //手局随机庄 + + /** + * 飘分玩法 + */ + public static final String ROOM_CONFIG_PIAO = "piao"; + + public static final String ROOM_CONFIG_XIPAI = "xi_pai"; + + public static final String ROOM_CONFIG_XIPAI_SCORE = "xi_pai_score"; + + // 1.��ׯ 2.��ׯ + // public static final String GAME_ZHUANG = "zhuang"; + + public static final String GAME_CHANGE_PAIXING = "613"; + + public static final String GAME_CHANGE_TYPEFACE = "615"; + + 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_THROW_CARD = "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_ADD_CARD = "821"; + + /** + * + */ + public static final String GAME_PIAO = "1015"; + + /** + * 飘鸟提示 + */ + public static final String GAME_EVT_PIAO_TIP = "2031"; + public static final String GAME_EVT_PIAO = "2032"; +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXActionEvent.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXActionEvent.java new file mode 100644 index 0000000..02c7d58 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXActionEvent.java @@ -0,0 +1,29 @@ +package extend.zp; + +public class EXActionEvent { + + public static final String EVENT_ACTION = "action"; + + public static final String EVENT_DISCARD = "discard"; + + public static final String EVENT_START_GAME = "start_game"; + + public static final String EVENT_EXIT_ROOM = "exit_room"; + + public static final String EVENT_DEAL = "deal"; + + public static final String EVENT_OTHER_DISCARD = "other_discard"; + + public static final String EVENT_OTHER_DRAW = "other_draw"; + + public static final String EVENT_OTHER_PAO = "other_pao"; + + public static final String EVENT_PIAO= "1015"; + + // public static final int REDIS_EVENT_PAY = 1; + public static final int REDIS_EVENT_WIN = 2; + public static final int REDIS_EVENT_LOSE = 3; + // public static final int REDIS_EVENT_SCORE= 4; + public static final int REDIS_EVENT_RANK = 5; + +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXGameController.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXGameController.java new file mode 100644 index 0000000..996880d --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXGameController.java @@ -0,0 +1,410 @@ +package extend.zp; + +import java.util.Collections; +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.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.data.Session; + +import extend.zp.uitl.CardUtil; + + +public class EXGameController extends GameController { + Logger logger = Logger.getLogger(getClass()); + public EXGameController() { + super(); + } + + + @ActionKey(Config.GAME_ACTION) + public void RouterAction(Session sender,ITObject params,int gid,Player owner) { + logger.info("step:1" ); + 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); + } + + @ActionKey(Config.GAME_CHANGE_PAIXING) + public void RouterChangePaixing(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + player.getRoom().changePaiXing(player, params); + } + + @ActionKey(Config.GAME_CHANGE_TYPEFACE) + public void RouterChangeTypeFace(Session sender,ITObject params,int gid,Player owner) { + EXPlayer player = (EXPlayer) owner; + int typeface = params.getInt("typeface"); + player.getRoom().typeface = typeface; + } + + @ActionKey(Config.GAME_PIAO) + public void RouterPiao(Session sender,ITObject params,int gid,Player owner) { + owner.stateMachine.execute(EXActionEvent.EVENT_PIAO, 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); + } + + /** + * 玩家摸牌 + * @param player + * @param leftCount + */ + public void getCard(EXPlayer player, int 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.getRoom().getPlayBack().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(); + room.getPlayBack().addOutCardCommand(player.seat, discard); + + room.activeCard = discard; + room.lastDiscardSeat = player.seat; + room.currenDiscardSeat = 0; + + if (!Util.checkCard(discard, player.cardInhand)) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (discard == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, discard, discard, discard, 0)); + player.cardInhand.add(discard); + player.cardInhand.add(discard); + break; + } + } + for (int i = 0; i < player.tiGroup.size(); i++) { + if (discard == player.tiGroup.get(i)[0]) { + player.tiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_TI, discard, discard, discard, 0)); + player.cardInhand.add(discard); + player.cardInhand.add(discard); + player.cardInhand.add(discard); + break; + } + } + } + else { + CardUtil.removeCard(player.cardInhand, discard, 1); + } + + room.broadCastToServer(player.playerid, EXActionEvent.EVENT_OTHER_DISCARD, discard); + } + + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat) { + actionCard(player, active_card, card, type, from_seat, null); + } + + /** + * 玩家对牌操作 + * @param player + * @param active_card + * @param card + * @param type + * @param from_seat + * @param opcardArray + */ + public void actionCard(EXPlayer player, int active_card, int card, int type, int from_seat, ITArray opcardArray) { + + ITObject paramBroadCast = new TObject(); + paramBroadCast.putInt("playerid", player.playerid); + paramBroadCast.putInt("active_card", active_card); + paramBroadCast.putInt("card", card); + paramBroadCast.putInt("type", type); + paramBroadCast.putInt("from_seat", from_seat); + int huxi = player.getShowHuXi(true); + paramBroadCast.putInt("hu_xi", huxi); + if (opcardArray != null) { + paramBroadCast.putTArray("opcard", opcardArray); + } + EXRoom room = player.getRoom(); + + room.getPlayBack().addActionCommand(player.seat, type, active_card, card, from_seat, huxi, opcardArray); + + ITObject otherBroadCast = new TObject(); + Utils.objectCopyDeep(paramBroadCast, otherBroadCast); + otherBroadCast.putInt("hu_xi", player.getShowHuXi(false)); + room.broadCastToClient(player.playerid, Config.GAME_EVT_ACTION, otherBroadCast); + + ITArray notPutArray = TArray.newInstance(); + for (Integer notPutCard : player.notPutSet) { + notPutArray.addInt(notPutCard); + } + paramBroadCast.putTArray("notput", notPutArray); + + player.sendEvent(Config.GAME_EVT_ACTION, paramBroadCast); + } + + /** + * 发牌 + * @param owner + */ + public void dealCard(EXRoom owner) { + + for (Entry entry : owner.playerMapById.entrySet()) { + + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.room.bankerSeat==player.seat){ + player.cardInhand = owner.card.deal2(); + }else{ + player.cardInhand = owner.card.deal(); + } + + //player.cardInhand = owner.card.deal(); + + + Collections.sort(player.cardInhand); + + ITObject param = new TObject(); + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("card_list", handCard); + param.putInt("bank_seat", player.room.bankerSeat); + player.sendEvent(Config.GAME_EVT_PLAYER_DEAL, param); + + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",player:" + player + ",cardInhand:" + player.cardInhand); + } + + logger.info("roomId:" + owner.roomid + ",round:" + owner.round + ",cardList:" + owner.card.cardList); + } + + public void tipEvent(EXPlayer owner) { + ITObject param = owner.tipMgr.toMP(); + if (!owner.tipMgr.tipMap.isEmpty()) { + owner.sendEvent(Config.GAME_EVT_FZTIPS, param); + } + } + + public void discardTipEvent(EXPlayer owner) { + owner.getRoom().currenDiscardSeat = owner.seat; + owner.sendEvent(Config.GAME_EVT_DISCARD_TIP, null); + } + + 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); + + EXRoom room = owner.getRoom(); + room.broadCastToClient(0, Config.GAME_EVT_HU, param); + room.getPlayBack().addWinCardCommand(owner.seat, false); + } + + public ITObject getRoomResultData(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putBoolean("liuju", owner.liuju); + mp.putInt("active_player", owner.playerMapBySeat.get(owner.activeSeat).playerid); + mp.putTArray("left_card", Util.toTArray(owner.card.cardList)); + mp.putTArray("throw_card", Util.toTArray(owner.throwCardsList)); + mp.putInt("xipai_score", owner.xi_pai_score); + long time = System.currentTimeMillis(); + long t = time / 1000; + mp.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry 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("hu_xi", player.huXi); + param.putInt("tun", player.winScore); + param.putInt("piao", player.piao); + player.hp_info(param); + if (owner.maxPlayers == 2) { + param.putInt("total_tun", player.score.round_score); + } else { + param.putInt("total_tun", player.score.round_score / 2); + } + + param.putInt("round_score", player.score.round_score); + param.putInt("total_score", player.score.total_score); + + ITArray mtList = TArray.newInstance(); + for (MingTang mingTang : player.mingtangList) { + ITObject obj = TObject.newInstance(); + obj.putInt("mingtang", mingTang.mingTang); + obj.putInt("type", mingTang.type); + obj.putInt("score", mingTang.score); + + mtList.addTObject(obj); + } + param.putTArray("mingtang", mtList); + + ITArray haoList = TArray.newInstance(); + if (player.winer == 1) { + ITArray handCard = Util.toTArray(player.handCardEx); + param.putTArray("hand_card", handCard); + + ITArray cardList = TArray.newInstance(); + for (int i = 0; i < player.tiGroup.size(); i++) { + int ti_card = player.tiGroup.get(i)[0]; + ITObject hao = TObject.newInstance(); + hao.putInt("hao", RuleWeight.HAO_QING); + hao.putInt("hao_card", ti_card); + haoList.addTObject(hao); + } + + for (OpCard opCard : player.handCard) { + boolean flag = true; + if (opCard.card1 == opCard.card2 && opCard.card1 == opCard.card3 && opCard.card1 != 0) { + for (int i = 0; i < player.tiGroup.size(); i++) { + int ti_card = player.tiGroup.get(i)[0]; + if (ti_card == opCard.card1) + { + flag = false; + } + } + } + if (flag) + { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + if (opCard.hao != RuleWeight.HAO_NONE) + { + ITObject hao = TObject.newInstance(); + hao.putInt("hao", opCard.hao); + hao.putInt("hao_card", opCard.haoCard); + haoList.addTObject(hao); + } + + cardList.addTObject(obj); + } + } + param.putTArray("cardList", cardList); + } else { + ITArray handCard = Util.toTArray(player.cardInhand); + param.putTArray("hand_card", handCard); + } + + ITArray opCardList = TArray.newInstance(); + + for (OpCard opCard : player.opCardList) { + ITObject obj = TObject.newInstance(); + obj.putInt("type", opCard.type); + obj.putInt("hu_xi", opCard.huXi); + obj.putInt("card1", opCard.card1); + obj.putInt("card2", opCard.card2); + obj.putInt("card3", opCard.card3); + + opCardList.addTObject(obj); + + if (opCard.hao != RuleWeight.HAO_NONE) + { + ITObject hao = TObject.newInstance(); + hao.putInt("hao", opCard.hao); + hao.putInt("hao_card", opCard.haoCard); + haoList.addTObject(hao); + } + } + param.putTArray("opCardList", opCardList); + param.putTArray("haoList", haoList); + + infoList.addTObject(param); + } + mp.putTArray("info_list", infoList); + return mp; + } + + public void roomResult(EXRoom owner) { + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + public void roomTotalResult(EXRoom owner, boolean dissmiss) { + ITObject data = TObject.newInstance(); + long t = System.currentTimeMillis() / 1000; + data.putLong("time", t); + ITArray infoList = new TArray(); + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + ITObject param = new TObject(); + param.putInt("seat", player.seat); + param.putInt("total_huxi", player.total_huxi); + param.putInt("win_count", player.winCount); + param.putInt("total_score", player.score.total_score); + player.hp_info(param); + infoList.addTObject(param); + } + data.putTArray("info_list", infoList); + + ITObject mp = TObject.newInstance(); + mp.putInt("type", dissmiss ? 2 : 1); + if (!dissmiss) { + ITObject result = getRoomResultData(owner); + mp.putTObject("result", result); + } + mp.putTObject("total_result", data); + + owner.broadCastToClient(0, Config.GAME_EVT_RESULT1, mp); + } + + /** + * 票鸟提示 + * @param owner + */ + public void piaoTipEvent(EXPlayer owner,int reload) { + + ITObject response = new TObject(); + response.putInt("piao", owner.room.config.getInt(Config.ROOM_CONFIG_PIAO)); + response.putInt("reload", reload); + System.out.println("piao"); + owner.sendEvent(Config.GAME_EVT_PIAO_TIP, response); + } + + /** + * 票鸟事件 + * @param owner + */ + public void piaoEvent(EXPlayer owner) { + if(owner.piao==-1)return; + + ITObject param = new TObject(); + param.putInt("seat", owner.seat); + param.putInt("piao", owner.piao); + owner.room.broadCastToClient(0, Config.GAME_EVT_PIAO, param); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXMainServer.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXMainServer.java new file mode 100644 index 0000000..0537924 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXMainServer.java @@ -0,0 +1,91 @@ +package extend.zp; + +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.zp.player.rulestate.*; +import extend.zp.player.state.*; +import extend.zp.room.state.EXRoomDealState; +import extend.zp.room.state.EXRoomPiaoState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.room.state.EXRoomStartGameState; + + +public class EXMainServer extends MainServer { + + public static PlayerRuleManager playerRuleMgr; + + public static EXGameController gameCtr; + + @Override + public void onStart() { + super.onStart(); + Global.loggerDebug = true; + Global.gameId = Config.GAME_ID; + 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(EXRoomPiaoState.class, new EXRoomPiaoState()); + //Global.registerState(EXRoomRoundSettleState.class, new EXRoomRoundSettleState()); + + Global.registerState(PlayerWaitState.class, new EXPlayerWaitState()); + Global.registerState(EXPlayerDrawState.class, new EXPlayerDrawState()); + Global.registerState(EXPlayerPreDrawState.class, new EXPlayerPreDrawState()); + Global.registerState(EXPlayerTianHuState.class, new EXPlayerTianHuState()); + Global.registerState(EXPlayerDiscardState.class, new EXPlayerDiscardState()); + Global.registerState(EXPlayerDisCardTipState.class, new EXPlayerDisCardTipState()); + Global.registerState(EXPlayerDrawTipState.class, new EXPlayerDrawTipState()); + Global.registerState(EXPlayerPiaoNiaoTipState.class, new EXPlayerPiaoNiaoTipState()); + //Global.registerState(EXPlayerRoundSettleState.class, new EXPlayerRoundSettleState()); + + Global.registerState(PRLiuState.class, new PRLiuState()); + Global.registerState(PRWeiState.class, new PRWeiState()); + Global.registerState(PRWeiLiuState.class, new PRWeiLiuState()); + Global.registerState(PRDealLiuState.class, new PRDealLiuState()); + + Global.registerState(PRDrawPaoState.class, new PRDrawPaoState()); + Global.registerState(PRDiscardPaoState.class, new PRDiscardPaoState()); + Global.registerState(PRDrawPongState.class, new PRDrawPongState()); + Global.registerState(PRPongState.class, new PRPongState()); + Global.registerState(PRChiState.class, new PRChiState()); + Global.registerState(PRDrawChiState.class, new PRDrawChiState()); + Global.registerState(PRWinState.class, new PRWinState()); + //Global.registerState(PRWinState.class, new PRWinState()); + } + + @Override + public Room newRoom(String roomid, Map 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(); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXPlayer.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXPlayer.java new file mode 100644 index 0000000..48b5d28 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXPlayer.java @@ -0,0 +1,560 @@ +package extend.zp; + +import java.util.*; +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.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.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.ChowCard; +import extend.zp.uitl.Paixing; + +/** + * + * + * + * 2017��8��30�� EXPlayer.java + */ +public class EXPlayer extends Player { + // ���� + public List cardInhand; + // ������ + public List outcardList; + // ������ + public List outcardExList; + + public ITArray opCard; + + public int biCard; + + public List tiGroup; + public List liuGroup; + public List paoGroup; + public List kanGroup; + public List pongGroup; + public List weiGroup; + public List chowGroup; + public List opCardList; + + public Stack handCard; + public List handCardEx; + + public HashSet chouChiSet; + public HashSet chouChiExSet; + public HashMap chouChiTypeMap; + public HashSet chouPongSet; + public HashSet notPutSet; + public HashSet notChiSet; + + public HashSet guoChiSet; + + + + public HashMap notChiTypeMap; + + + + public int drawCard = 0; + public int winCard = 0; + public int winScore = 0; + public int winFan = 0; + public List mingtangList; + + public int kongCount = 0; + public int tiCount = 0; + // ��Ϣ + public int huXi = 0; + + public int total_huxi = 0; + + public boolean isTingHu = true; + + // �Ƿ�����ү + public boolean isLaoYe = false; + + public boolean isMingTang = true; + + public TipManager tipMgr; + + public Tip actionTip; + + public int piao = -1; + + public boolean isDiHu = true; + public boolean isGuoliu = false; + + public boolean isDeadPut = false; + + public EXPlayer(int playerid, Room table, String session_id) { + super(playerid, table, session_id); + + cardInhand = new ArrayList<>(); + outcardList = new ArrayList<>(); + outcardExList = new ArrayList<>(); + + tiGroup = new ArrayList<>(); + liuGroup = new ArrayList<>(); + paoGroup = new ArrayList<>(); + kanGroup = new ArrayList<>(); + pongGroup = new ArrayList<>(); + weiGroup = new ArrayList<>(); + chowGroup = new ArrayList<>(); + opCardList = new ArrayList<>(); + mingtangList = new ArrayList<>(); + + opCard = new TArray(); + chouChiSet = new HashSet<>(); + chouChiTypeMap = new HashMap<>(); + chouChiExSet = new HashSet<>(); + chouPongSet = new HashSet<>(); + notPutSet = new HashSet<>(); + notChiSet = new HashSet<>(); + guoChiSet = new HashSet<>(); + notChiTypeMap = new HashMap<>(); + + handCard = new Stack(); + handCardEx = new ArrayList<>(); + + tipMgr = new TipManager(this); + + isDiHu = true; + + isGuoliu = false; //过溜 + + isDeadPut = false; + } + + 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(boolean self) { + ITObject playerData = super.getReloadInfo(); + ITArray disCard = Util.toTArray(this.outcardList); + playerData.putTArray("outcard_list", disCard); + playerData.putInt("score", this.score.total_score); + playerData.putInt("hu_xi", this.getShowHuXi(self)); + playerData.putInt("piao", this.piao); + int size = 0; + ITArray opcards = TArray.newInstance(); + for (OpCard opcard : opCardList) { + if (opcard.type == RuleWeight.TYPE_TI && opcard.pailie == true) + { + size += 4; + continue; + } + if (opcard.type == RuleWeight.TYPE_KAN && opcard.pailie == true) + { + size += 3; + continue; + } + ITObject opcardParam = new TObject(); + opcardParam.putInt("type", opcard.type); + opcardParam.putInt("card1", opcard.card1); + opcardParam.putInt("card2", opcard.card2); + opcardParam.putInt("card3", opcard.card3); + opcards.addTObject(opcardParam); + } + playerData.putInt("card_count", this.cardInhand.size() + size); + playerData.putTArray("opcard", opcards); + return playerData; + } + + public int getShowHuXi(boolean self) { + int huXi = 0; + for (OpCard opCard : this.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_TI && opCard.pailie == true) { + continue; + } + huXi += opCard.huXi; + } + return huXi; + } + + public void resetHuXi() { + this.huXi = 1; //胡算一分 + for (OpCard opCard : this.opCardList) { + this.huXi += opCard.huXi; + } + if (tiGroup.size() > 0) + { + this.huXi -= Paixing.caclHuxi(RuleWeight.TYPE_TI, 0) * tiGroup.size(); + } + } + + public void clear() { + this.isDiHu = true; + this.cardInhand.clear(); + this.winer = 0; + this.outcardList.clear(); + this.outcardExList.clear(); + this.drawCard = 0; + this.winScore = 0; + this.winFan = 0; + this.kongCount = 0; + this.tiCount = 0; + this.huXi = 0; + this.isTingHu = true; + this.isLaoYe = false; + this.isMingTang = true; + this.tiGroup.clear(); + this.liuGroup.clear(); + this.paoGroup.clear(); + this.kanGroup.clear(); + this.pongGroup.clear(); + this.weiGroup.clear(); + this.chowGroup.clear(); + this.opCardList.clear(); + this.chouChiSet.clear(); + this.chouChiExSet.clear(); + this.chouChiTypeMap.clear(); + this.notChiTypeMap.clear(); + this.chouPongSet.clear(); + this.notPutSet.clear(); + this.mingtangList.clear(); + this.score.resetRound(); + this.piao = -1; + this.isDeadPut = false; + } + + public EXRoom getRoom() { + return (EXRoom) room; + } + /** + * �Զ����ƣ��йܣ� + */ + public Integer autoDiscard(){ + Map cardNum=CardUtil.getCardNumMap(this.cardInhand); + for (Entry card : cardNum.entrySet()) { + if (card.getValue()==1||card.getValue()==2) { + if (!this.notPutSet.contains(card.getKey())) + { + return card.getKey(); + } + } + } + return 0; + } + + public void handleDeadPut() + { + ArrayList tempList = new ArrayList<>(); + tempList.addAll(this.cardInhand); + for (int i = 0; i < kanGroup.size(); i++) { + tempList.add(kanGroup.get(i)[0]); + tempList.add(kanGroup.get(i)[0]); + tempList.add(kanGroup.get(i)[0]); + } + + for (int i = 0; i < tiGroup.size(); i++) { + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + } + + for(int i = 0; i < tempList.size(); i++) { + int card = tempList.get(i); + if (!notPutSet.contains(card)) + { + return; + } + } + + isDeadPut = true; + } + public boolean chi(int eventCard, IRuleBase rule) { + EXPlayer activePlayer = (EXPlayer) this.room.playerMapBySeat.get(this.room.activeSeat); + ArrayList tempList = new ArrayList<>(); + tempList.addAll(this.cardInhand); + for (int i = 0; i < kanGroup.size(); i++) { + tempList.add(kanGroup.get(i)[0]); + tempList.add(kanGroup.get(i)[0]); + tempList.add(kanGroup.get(i)[0]); + } + for (int i = 0; i < tiGroup.size(); i++) { + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + tempList.add(tiGroup.get(i)[0]); + } + + if (tempList.size() <= 2) { + return false; + } + if (eventCard == 0) { + return false; + } + if (this.isEntrust()) { + this.chouChiSet.add(eventCard); + return false; + } + + Global.logger.info("user: "+ this.playerid+" chi==========> chouChiSet = "+chouChiSet+ " eventCard ="+eventCard); + // ���� + if (this.chouChiSet.contains(eventCard)) { + if (this.chouChiTypeMap.containsKey(eventCard)) { + //可以吃2 7 10 + Global.logger.info("user: "+ this.playerid + " maybe can chi for 2 7 10 " + " for eventCard:"+eventCard); + //return false; + } else { + Global.logger.info("user: "+ this.playerid+" chouChiSet = "+chouChiSet + " ==> false for eventCard:"+eventCard); + return false; + } + } + + HashSet getChi = new HashSet<>(); + getChi.addAll(this.guoChiSet); + Global.logger.info("jefe getChi : "+ this.playerid+" chi==========> = "+getChi+ " eventCard ="+eventCard); + + // ���� + if (this.chouChiExSet.contains(eventCard) && this.getRoom().throwCardsSet.contains(eventCard)) { + return false; + } + + if (CardUtil.cardNum(eventCard, this.outcardExList) != 0) { + return false; + } + if (activePlayer.nextSeat != this.seat && activePlayer.seat != this.seat) { + return false; + } + //if (this.getRoom().checkPao(eventCard, rule instanceof RuleChi)) { + // return false; + //} + + ChowCard chow = new ChowCard(tempList, eventCard); + ITArray list = TArray.newInstance(); + boolean isChi = chow.tryChow(list); + if (isChi) { + boolean hasChi = false; + + int weight = activePlayer.seat != this.seat ? RuleWeight.CHOW1 : RuleWeight.CHOW2; + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + ITArray opCard = obj.getTArray("opcard"); + int chowcard1 = opCard.getInt(0); + int chowcard2 = opCard.getInt(1); + + if (this.chouChiTypeMap.containsKey(eventCard)) { + //Global.logger.info("====> opCard : "+opCard); + if (isThreeCard2_7_10(chowcard1, chowcard2, eventCard)) { + //可以吃2 7 10 + Global.logger.info("user: "+ this.playerid + " can chi for 2 7 10 " + " for eventCard:"+eventCard); + continue; + } else { + Global.logger.info("user dd: "+ this.playerid + " can't chi for 2 7 10 " + " for eventCard:"+eventCard); + //判断卡隆 + if(!getChi.contains(eventCard)){ + //处理卡隆 + //Global.logger.info("jefe step1"+eventCard); + //处理最大最小 + if (this.chouChiTypeMap.containsKey(eventCard-3)){ + //Global.logger.info("jefe step2"+eventCard); + //eventcard 最大 + if (eventCardchowcard1){ + //大于 + if (eventCard-chowcard1==1&&chowcard2-eventCard==1){ + Global.logger.info("user ka1long: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + continue;//都不能吃 + } + }else{ + //小于 + if (chowcard1-eventCard==1&&eventCard-chowcard2==1){ + Global.logger.info("user ka3long: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + continue;//都不能吃 + } + } + } + }else if (this.chouChiTypeMap.containsKey(eventCard+3)){ + //Global.logger.info("jefe step3"+eventCard); + if (eventCard>chowcard1&&eventCard>chowcard2){ + Global.logger.info("user min: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + if (chowcard2>chowcard1){ + //大于 + if (eventCard-chowcard1==1&&chowcard2-eventCard==1){ + Global.logger.info("user ka1long: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + continue;//都不能吃 + } + }else{ + //小于 + if (chowcard1-eventCard==1&&eventCard-chowcard2==1){ + Global.logger.info("user ka3long: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + continue;//都不能吃 + } + } + } + }else{ + //Global.logger.info("jefe step4"+eventCard); + if (chowcard2>chowcard1){ + //大于 + if (eventCard-chowcard1==1&&chowcard2-eventCard==1){ + Global.logger.info("user kalong: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + }else{ + continue;//都不能吃 + } + }else{ + //小于 + if (chowcard1-eventCard==1&&eventCard-chowcard2==1){ + Global.logger.info("user ka2long: "+ this.playerid + "chowcard1:"+chowcard1+" chowcard2: "+chowcard2+" eventCard :"+eventCard); + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + }else{ + continue;//都不能吃 + } + } + } + + }else{ + Global.logger.info("jefe step5"+eventCard); + continue;//都不能吃 + } + + } + } + + hasChi = true; + + Tip tip = new Tip(eventCard, opCard, weight, rule, RuleWeight.TYPE_CHOW); + tip.bi_list = obj.getTArray("bi_list"); + this.tipMgr.addTip(tip); + + //__notChi(this, chowcard1, chowcard2, eventCard); + __notChi1(this, chowcard1, chowcard2, eventCard); + + HashSet notChiSet11 = this.notChiSet; + Global.logger.info("---> user: "+ this.playerid+" opCard = "+opCard+" notChiSet = "+notChiSet); + Global.logger.info("---> user: "+ this.playerid+" chouChiSet = "+this.chouChiSet); + } + + return hasChi; + } else { + this.chouChiExSet.add(eventCard); + } + return isChi; + } + + private static boolean isThreeCard2_7_10(int card1, int card2, int card3) { + int mod1 = card1%100; + int mod2 = card2%100; + int mod3 = card3%100; + + HashSet set = new HashSet<>(); + set.add(mod1); + set.add(mod2); + set.add(mod3); + + if ((mod1 + mod2 + mod3 == 2 + 7 + 10) && set.contains(2) && set.contains(7) && set.contains(10)) { + return true; + } else { + return false; + } + } + + + private static final void __notChi(EXPlayer player, int chowcard1, int chowcard2, int card) { + player.notChiSet.add(card); + Global.logger.info("---> notchi jefe: chowcard1:"+ chowcard1+" chowcard2: "+chowcard2+"card:"+card); + if (chowcard1 - chowcard2 == 1) { + if (chowcard2 % 100 == 1) { + player.notChiSet.add(chowcard2 + 2); + } else if (chowcard2 % 100 == 9) { + player.notChiSet.add(chowcard2 - 1); + } else { + player.notChiSet.add(chowcard2 - 1); + player.notChiSet.add(chowcard2 + 2); + } + } else if (chowcard1 - chowcard2 == 2) { + player.notChiSet.add(chowcard2 + 1); + } else if (chowcard2 - chowcard1 == 1) { + if (chowcard1 % 100 == 1) { + player.notChiSet.add(chowcard1 + 2); + } else if (chowcard1 % 100 == 9) { + player.notChiSet.add(chowcard1 - 1); + } else { + player.notChiSet.add(chowcard1 - 1); + player.notChiSet.add(chowcard1 + 2); + } + } else if (chowcard2 - chowcard1 == 2) { + player.notChiSet.add(chowcard1 + 1); + } + } + + private static final void __notChi1(EXPlayer player, int chowcard1, int chowcard2, int card) { + player.notChiSet.add(card); + player.guoChiSet.add(card); + //player.notChiTypeMap.put(card, 0); + Global.logger.info("---> notchi jefe: chowcard1:"+ chowcard1+" chowcard2: "+chowcard2+"card:"+card); + if (chowcard1 - chowcard2 == 1) { + if (chowcard2 % 100 == 1) { + player.notChiSet.add(chowcard2 + 2); + player.notChiTypeMap.put(chowcard2 + 2, 0); + } else if (chowcard2 % 100 == 9) { + player.notChiSet.add(chowcard2 - 1); + player.notChiTypeMap.put(chowcard2 - 1, 0); + } else { + player.notChiSet.add(chowcard2 - 1); + player.notChiSet.add(chowcard2 + 2); + player.notChiTypeMap.put(chowcard2 - 1, 0); + player.notChiTypeMap.put(chowcard2 + 2, 0); + } + } else if (chowcard1 - chowcard2 == 2) { + player.notChiSet.add(chowcard2 + 1); + player.notChiTypeMap.put(chowcard2 + 1, 0); + } else if (chowcard2 - chowcard1 == 1) { + if (chowcard1 % 100 == 1) { + player.notChiSet.add(chowcard1 + 2); + player.notChiTypeMap.put(chowcard1 + 2, 0); + } else if (chowcard1 % 100 == 9) { + player.notChiSet.add(chowcard1 - 1); + player.notChiTypeMap.put(chowcard1 - 1, 0); + } else { + player.notChiSet.add(chowcard1 - 1); + player.notChiSet.add(chowcard1 + 2); + player.notChiTypeMap.put(chowcard1 - 1, 0); + player.notChiTypeMap.put(chowcard1 + 2, 0); + } + } else if (chowcard2 - chowcard1 == 2) { + player.notChiSet.add(chowcard1 + 1); + player.notChiTypeMap.put(chowcard1 + 1, 0); + } else { //2 7 10 + /*if (isThreeCard2_7_10(chowcard1,chowcard2,card)){ + player.notChiSet.add(chowcard1); + player.notChiSet.add(chowcard2); + player.notChiTypeMap.put(chowcard1, 0); + player.notChiTypeMap.put(chowcard2, 0); + player.notChiTypeMap.put(card, 0); + }*/ + //player.notChiSet.add(card); + //player.notChiTypeMap.put(card, 0); + } + + } + +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXRoom.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXRoom.java new file mode 100644 index 0000000..0e33e31 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXRoom.java @@ -0,0 +1,1223 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +import com.game.Router; +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.*; + +import com.taurus.core.util.Logger; +import extend.zp.player.rule.*; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.tip.Action; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.TipManager; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class EXRoom extends Room { + + // + public Map tipMap; + public List actionList; + + public RoomCard card; + + Logger logger = Logger.getLogger(getClass()); + + public int activeCard; + public int drawCard; + public int currenDiscardSeat; + public int lastDiscardSeat; + public int winSeat; + public int winCount = 0; + public boolean liuju = false; + public int liujuNum = 0; + public boolean isAllPass = false; + public boolean isTianHu = true; + public boolean isDiHu = true; + public int piaoCount = 0; + + public boolean hh = false; + public boolean dh = false; + public boolean hw = false; + public boolean wh = false; + public boolean hd = false; + public boolean wd = false; + public boolean jhd = false; + + public boolean dhdf =false; + + public int step; + + public HashSet throwCardsSet; + public ArrayList throwCardsList; + + public int typeface = 1; + + public ITObject paiXing; + public int adminSeat; + + public EXRoom(String roomid, Map redis_room_map) { + super(roomid, redis_room_map); + card = new RoomCard(this); + + this.tipMap = new HashMap(); + this.actionList = new ArrayList(); + this.paiXing = TObject.newInstance(); + this.throwCardsSet = new HashSet<>(); + this.throwCardsList = new ArrayList(); + this.isEntrust = true; + + hh = config.containsKey("hh") ? (config.getInt("hh") == 0 ? true : false) : true; + dh = config.containsKey("dh") ? (config.getInt("dh") == 0 ? true : false) : true; + hw = config.containsKey("hw") ? (config.getInt("hw") == 0 ? true : false) : true; + wh = config.containsKey("wh") ? (config.getInt("wh") == 0 ? true : false) : true; + hd = config.containsKey("hd") ? (config.getInt("hd") == 0 ? true : false) : true; + wd = config.containsKey("wd") ? (config.getInt("wd") == 0 ? true : false) : true; + jhd = config.containsKey("jhd") ? (config.getInt("jhd") == 0 ? true : false) : true; + + dhdf = config.containsKey("dhdf") ? (config.getInt("dhdf") == 0 ? false : true) : false; + this.adminSeat = 0; + if (!this.config.containsKey(Config.GAME_MODE)) + { + this.config.putInt(Config.GAME_MODE, 2); + } + if (!this.config.containsKey(Config.GAME_TUN)) + { + this.config.putInt(Config.GAME_TUN, 0); + } + if (!this.config.containsKey(Config.GAME_TUN)) + { + this.config.putInt(Config.GAME_TUN, 0); + } + if (!this.config.containsKey(Config.GAME_FENGDING)) + { + this.config.putInt(Config.GAME_FENGDING, 0); + } + if (!this.config.containsKey(Config.GAME_TUANYUAN)) + { + this.config.putInt(Config.GAME_TUANYUAN, 0); + } + if (!this.config.containsKey(Config.GAME_TUANYUAN)) + { + this.config.putInt(Config.GAME_TUANYUAN, 0); + } + if (!this.config.containsKey(Config.GAME_HANGHANGXI)) + { + this.config.putInt(Config.GAME_HANGHANGXI, 0); + } + if (!this.config.containsKey(Config.GAME_SHUAHOU)) + { + this.config.putInt(Config.GAME_SHUAHOU, 0); + } + if (!this.config.containsKey(Config.GAME_SHUAHOU)) + { + this.config.putInt(Config.GAME_SHUAHOU, 0); + } + if (!this.config.containsKey(Config.GAME_HUANGFAN)) + { + this.config.putInt(Config.GAME_HUANGFAN, 0); + } + if (!this.config.containsKey(Config.GAME_JIAXINGXING)) + { + this.config.putInt(Config.GAME_JIAXINGXING, 0); + } + if (!this.config.containsKey(Config.GAME_TINGHU)) + { + this.config.putInt(Config.GAME_TINGHU, 0); + } + if (!this.config.containsKey(Config.GAME_SIQI)) + { + this.config.putInt(Config.GAME_SIQI, 0); + } + if (!this.config.containsKey(Config.GAME_DUIZIFU)) + { + this.config.putInt(Config.GAME_DUIZIFU, 0); + } + if (!this.config.containsKey(Config.GAME_YUAN)) + { + this.config.putInt(Config.GAME_YUAN, 0); + } + if (!this.config.containsKey(Config.GAME_BEIKAOBEI)) + { + this.config.putInt(Config.GAME_BEIKAOBEI, 0); + } + if (!this.config.containsKey(Config.GAME_TIANHU)) + { + this.config.putInt(Config.GAME_TIANHU, 0); + } + if (!this.config.containsKey(Config.GAME_DIHU)) + { + this.config.putInt(Config.GAME_DIHU, 0); + } + if (!this.config.containsKey(Config.GAME_HAIHU)) + { + this.config.putInt(Config.GAME_HAIHU, 0); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_QUPAI)) + { + this.config.putInt(Config.ROOM_CONFIG_QUPAI, 0); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_KA_WAI)) + { + this.config.putInt(Config.ROOM_CONFIG_KA_WAI, 0); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_FIRST_RAND_ZHUANG)) + { + this.config.putBoolean(Config.ROOM_CONFIG_FIRST_RAND_ZHUANG, false); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAO_CONFIG)) + { + this.config.putInt(Config.ROOM_CONFIG_HAO_CONFIG, 0); + } + if (!this.config.containsKey(Config.ROOM_CONFIG_HAO_JIABEI)) + { + this.config.putInt(Config.ROOM_CONFIG_HAO_JIABEI, 0); + } + + if (!this.config.containsKey(Config.ROOM_CONFIG_MENG_TANG)) + { + this.config.putInt(Config.ROOM_CONFIG_MENG_TANG, 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); + } + logger.info("jefe kawai:"+this.config.getInt(Config.ROOM_CONFIG_KA_WAI)); + if (this.config.getInt(Config.ROOM_CONFIG_KA_WAI) == 0) + { + List paoList = new ArrayList(); + //paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + EXMainServer.playerRuleMgr.ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + //drawRuleList.add(new RuleLiu()); + drawRuleList.add(new RuleWeiHu()); + //drawRuleList.add(new RuleWei()); + drawRuleList.add(new RuleWeiLiu()); + //drawRuleList.add(new RuleDealLiu()); + + EXMainServer.playerRuleMgr.ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + } + else + { + List paoList = new ArrayList(); + EXMainServer.playerRuleMgr.ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + drawRuleList.add(new RuleLiu()); + drawRuleList.add(new RuleWei()); + //drawRuleList.add(new RuleDealLiu()); + drawRuleList.add(new RuleWeiLiu()); + EXMainServer.playerRuleMgr.ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + } + + } + + public void changePaiXing(EXPlayer player, ITObject params) { + ITArray paixing = params.getTArray("card_list"); + if (paixing == null) { + paixing = TArray.newInstance(); + } + + ArrayList tmpCardList = new ArrayList(); + for(int i = 0; i < paixing.size(); i++) + { + TDataWrapper card = paixing.get(i); + TObject map = (TObject)card.getObject(); + tmpCardList.add(map.getInt("card")); + } + + Collections.sort(tmpCardList); + ArrayList tmpCardList2 = new ArrayList(); + tmpCardList2.addAll(player.cardInhand); + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_KAN && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.type == RuleWeight.TYPE_TI && opCard.pailie) { + tmpCardList2.add(opCard.card1); + tmpCardList2.add(opCard.card2); + tmpCardList2.add(opCard.card3); + tmpCardList2.add(opCard.card3); + } + } + Collections.sort(tmpCardList2); + + if (!tmpCardList.equals(tmpCardList2)) + { + ITObject param = new TObject(); + player.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + + paiXing.putTArray(player.seat + "", paixing); + + ITObject cmdData = TObject.newInstance(); + cmdData.putTArray("card_list", paixing); + this.getPlayBack().addCommand("ChangePaiXing", player.seat, cmdData); + } + + public void addAction(Action action) { + 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) { + this.actionList.add(action); + } + checkAction(); + } + + public void checkAction() { + boolean isWeightest = this.isWeightestAction(); + if (!isWeightest) { + return; + } + if (this.isAllPass()) { + this.isAllPass = true; + //add allpass + + Player activePlayer = this.playerMapBySeat.get(this.activeSeat); + + + 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 entry : this.tipMap.entrySet()) { + TipManager tip = entry.getValue(); + if (curaction.player.seat == tip.owner.seat) { + continue; + } + if (curaction.tip.weight <= tip.getWeightest()) { + return false; + } + } + for (Entry entry : this.playerMapById.entrySet()) { + Player player = entry.getValue(); + if (curaction.player.seat == player.seat) { + continue; + } + if (player.stateMachine.curState instanceof EXPlayerDisCardTipState || player.stateMachine.curState instanceof EXPlayerDrawTipState) { + player.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + } + } + return true; + } + + public ITObject getReloadInfo(Player player) { + ITObject data = getReloadInfoEx(player); + EXPlayer p = (EXPlayer) player; + ArrayList tempList = new ArrayList<>(); + tempList.addAll(p.cardInhand); + for (OpCard opcard : p.opCardList) { + if (opcard.type == RuleWeight.TYPE_TI && opcard.pailie == true) { + tempList.add(opcard.card1); + tempList.add(opcard.card1); + tempList.add(opcard.card1); + tempList.add(opcard.card1); + continue; + } + if (opcard.type == RuleWeight.TYPE_KAN && opcard.pailie == true) { + tempList.add(opcard.card1); + tempList.add(opcard.card1); + tempList.add(opcard.card1); + continue; + } + } + + data.putTArray("hand_card", Util.toTArray(tempList)); + data.putInt("left_card", card.getCount()); + data.putInt("curren_outcard_seat", currenDiscardSeat); + data.putInt("last_outcard_seat", lastDiscardSeat); + data.putInt("typeface", typeface); + data.putInt("discard", this.isDiHu ? 0 : 1); + + ITArray paiXing = this.paiXing.getTArray(player.seat + ""); + if (paiXing == null) { + paiXing = TArray.newInstance(); + } + data.putTArray("card_list", paiXing); + + EXPlayer activePlayer = (EXPlayer) playerMapBySeat.get(activeSeat); + if (activePlayer != null) { + if (activePlayer.drawCard != 0) { + data.putInt("acitve_card", activePlayer.drawCard); + } else { + data.putInt("acitve_card", activeCard); + } + } else { + data.putInt("acitve_card", 0); + } + return data; + } + + public ITObject getReloadInfoEx(Player player) { + ITObject data = new TObject(); + data.putInt("active_seat", this.activeSeat); + data.putInt("banker_seat", this.bankerSeat); + data.putBoolean("playing", this.isplaying); + + EXPlayer exPlayer = (EXPlayer)player; + ITArray notPutArray = TArray.newInstance(); + for (Integer notPutCard : exPlayer.notPutSet) { + notPutArray.addInt(notPutCard); + } + data.putTArray("notput", notPutArray); + ITArray info_list = TArray.newInstance(); + boolean self = false; + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer tempPlayer = (EXPlayer) entry.getValue(); + if (tempPlayer.seat == player.seat) { + self = true; + } + info_list.addTObject(tempPlayer.getReloadInfo(self)); + } + data.putTArray("info_list", info_list); + return data; + } + + public void addScore(EXPlayer player, int score, int type) { + player.score.round_log.put(type, player.score.round_log.get(type) + score); + + player.score.round_score += score; + player.score.total_score += score; + } + + public void addScore(EXPlayer destPlayer) { + int score = caclScore(destPlayer); + + //先判断分够不够 + int tmp_all_score = 0; + for (Entry entry : this.playerMapById.entrySet()) { + if (!entry.getKey().equals(destPlayer.playerid)) { + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + int temp_score = score; + if(destPlayer.piao > 0) { + temp_score += destPlayer.piao; + } + + if(fromPlayer.piao > 0) { + temp_score += fromPlayer.piao; + } + //// + if(multipleScore(temp_score) > fromPlayer.hp.cur_hp) { + tmp_all_score += reMultipleScore((int)fromPlayer.hp.cur_hp); + this.addScore(fromPlayer, -reMultipleScore((int)fromPlayer.hp.cur_hp), EXScore.WIN); + }else { + tmp_all_score += temp_score; + this.addScore(fromPlayer, -temp_score, EXScore.WIN); + } + } + } + // + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(destPlayer.playerid)) { + this.addScore(destPlayer, tmp_all_score, EXScore.WIN); + } + } + + //// + +// for (Entry entry : this.playerMapById.entrySet()) { +// if (entry.getKey().equals(destPlayer.playerid)) { +// if (this.maxPlayers == 2) { +// this.addScore(destPlayer, score, EXScore.WIN); +// } else { +// this.addScore(destPlayer, score * 2, EXScore.WIN); +// } +// } else { +// EXPlayer fromPlayer = (EXPlayer) entry.getValue(); +// this.addScore(fromPlayer, -score, EXScore.WIN); +// } +// } + } + + public int caclScore(EXPlayer player) { + int redCard = 0; + int bigCard = 0; + int smallCard = 0; + int huXi = 1; //胡算一分 + int huXiNum = 0; + int kanXi = 0; + int haoXi = 0; + int waiXi = 0; + boolean isDuzi = true; + for (int i = 0; i < player.tiGroup.size(); i++) { + int ti_card = player.tiGroup.get(i)[0]; + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_TI, ti_card, ti_card, ti_card, 0)); + + for (OpCard opCard : player.handCard) { + if (opCard.card1 == opCard.card2 && opCard.card1 == opCard.card3 && opCard.card1 == ti_card) { + int[] kanGroup = new int[3]; + kanGroup[0] = ti_card; + kanGroup[1] = ti_card; + kanGroup[2] = ti_card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, ti_card, ti_card, ti_card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, ti_card), true, RuleWeight.HAO_NONE, 0)); + } + } + + //hao + if (this.config.getInt(Config.ROOM_CONFIG_HAO_CONFIG) == 0) + { + huXi += 30; + haoXi += 30; + } + else { + huXi += 40; + haoXi += 40; + } + } + + if (!player.handCardEx.isEmpty()) { + isDuzi = false; + for (int card : player.handCardEx) { + if (CardUtil.isRedCard(card)) { + redCard++; + } + if (CardUtil.cardType(card) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.handCard) { + if (opCard.huXi != 0) { + boolean flag = true; + if (opCard.card1 == opCard.card2 && opCard.card1 == opCard.card3 && opCard.card1 != 0) { + for (int i = 0; i < player.tiGroup.size(); i++) { + int ti_card = player.tiGroup.get(i)[0]; + if (ti_card == opCard.card1) + { + flag = false; + } + } + } + if (flag) + { + huXi += opCard.huXi; + huXiNum++; + } + } + + //hao + if (this.config.getInt(Config.ROOM_CONFIG_HAO_CONFIG) == 0) + { + if (opCard.hao == RuleWeight.HAO_SHAN) + { + huXi += 40; + haoXi += 40; + } + else if (opCard.hao == RuleWeight.HAO_QING) + { + huXi += 30; + haoXi += 30; + } + else if (opCard.hao == RuleWeight.HAO_NUI) + { + huXi += 20; + haoXi += 20; + } + else if (opCard.hao == RuleWeight.HAO_WAI) + { + huXi += 10; + haoXi += 10; + } + } + else { + if (opCard.hao == RuleWeight.HAO_SHAN) + { + huXi += 50; + haoXi += 50; + } + else if (opCard.hao == RuleWeight.HAO_QING) + { + huXi += 40; + haoXi += 40; + } + else if (opCard.hao == RuleWeight.HAO_NUI) + { + huXi += 30; + haoXi += 30; + } + else if (opCard.hao == RuleWeight.HAO_WAI) + { + huXi += 20; + haoXi += 20; + } + } + + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + + if (opCard.type == 1) { + if (opCard.card1 != opCard.card2) { + isDuzi = false; + } + } + else if (opCard.type == 2) { + if (opCard.card1 != opCard.card2 || opCard.card1 != opCard.card3) { + isDuzi = false; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } + } + for (OpCard opCard : player.opCardList) { + if (opCard.huXi != 0) { + huXi += opCard.huXi; + huXiNum++; + } + + if (opCard.type == RuleWeight.TYPE_KAN) + { + kanXi += opCard.huXi; + } + else if (opCard.type == RuleWeight.TYPE_WEI) + { + waiXi += opCard.huXi; + } + else if (opCard.type == RuleWeight.TYPE_CHOUWEI) + { + waiXi += opCard.huXi; + } + else if (opCard.type == RuleWeight.TYPE_TI) + { + haoXi += opCard.huXi; + } + + //hao + if (this.config.getInt(Config.ROOM_CONFIG_HAO_CONFIG) == 0) + { + if (opCard.hao == RuleWeight.HAO_SHAN) + { + huXi += 40; + haoXi += 40; + } + else if (opCard.hao == RuleWeight.HAO_QING) + { + huXi += 30; + haoXi += 30; + } + else if (opCard.hao == RuleWeight.HAO_NUI) + { + huXi += 20; + haoXi += 20; + } + else if (opCard.hao == RuleWeight.HAO_WAI) + { + huXi += 10; + haoXi += 10; + } + } + else { + if (opCard.hao == RuleWeight.HAO_SHAN) + { + huXi += 50; + haoXi += 50; + } + else if (opCard.hao == RuleWeight.HAO_QING) + { + huXi += 40; + haoXi += 40; + } + else if (opCard.hao == RuleWeight.HAO_NUI) + { + huXi += 30; + haoXi += 30; + } + else if (opCard.hao == RuleWeight.HAO_WAI) + { + huXi += 20; + haoXi += 20; + } + } + + + if (opCard.type == RuleWeight.TYPE_CHOW) { + isDuzi = false; + if (CardUtil.isRedCard(opCard.card1)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card2)) { + redCard++; + } + if (CardUtil.isRedCard(opCard.card3)) { + redCard++; + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card2) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + if (CardUtil.cardType(opCard.card3) == RuleWeight.BIG_CARD) { + bigCard++; + } else { + smallCard++; + } + } else { + if (CardUtil.isRedCard(opCard.card1)) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + redCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + redCard += 4; + } + } + if (CardUtil.cardType(opCard.card1) == RuleWeight.BIG_CARD) { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + bigCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + bigCard += 4; + } + } else { + if (opCard.type == RuleWeight.TYPE_PONG || opCard.type == RuleWeight.TYPE_KAN || opCard.type == RuleWeight.TYPE_WEI || opCard.type == RuleWeight.TYPE_CHOUWEI) { + smallCard += 3; + } else if (opCard.type == RuleWeight.TYPE_PAO || opCard.type == RuleWeight.TYPE_TI) { + smallCard += 4; + } + } + } + } + + player.mingtangList.clear(); + player.winFan = 0; + + boolean mingtang = false; + boolean duiFlag = true; + do + { + int duziNum = 0; + int siduiNum = 0; + ArrayList duiList = new ArrayList<>(); + duiList.addAll(player.cardInhand); + for (int i = 0; i < player.tiGroup.size(); i++) { + int card = player.tiGroup.get(i)[0]; + duiList.add(card); + duiList.add(card); + duiList.add(card); + duiList.add(card); + } + for (int i = 0; i < player.kanGroup.size(); i++) { + int card = player.kanGroup.get(i)[0]; + duiList.add(card); + duiList.add(card); + duiList.add(card); + } + + if (duiList.size() < 19) + { + break; + } + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer != null & activePlayer.drawCard > 0) { + duiList.add(activePlayer.drawCard); + } + + Map cardNumList = CardUtil.getCardNumMap(duiList); + for (Entry card : cardNumList.entrySet()) { + if (card.getValue() == 2 || card.getValue() == 3) { + duziNum++; + } + else if (card.getValue() == 4) { + siduiNum++; + } + } + + if (duziNum + siduiNum == 0) + { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.NO_DUI, 1, 120)); + mingtang = true; + duiFlag = false; + this.isTianHu = false; + player.isDiHu = false; + } + else if (duziNum + siduiNum == 10 || duziNum + siduiNum*2 == 10) + { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.SHI_DUI, 1, 120)); + mingtang = true; + duiFlag = false; + this.isTianHu = false; + player.isDiHu = false; + } + else if (duziNum + siduiNum == 1 || duziNum + siduiNum*2 == 1) + { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.YI_DUI, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.YI_DUI, 1, 120)); + } + this.isTianHu = false; + player.isDiHu = false; + mingtang = true; + duiFlag = false; + } + else if (duziNum + siduiNum == 9 || duziNum + siduiNum*2 == 9) + { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.JIU_DUI, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.JIU_DUI, 1, 120)); + } + this.isTianHu = false; + player.isDiHu = false; + mingtang = true; + duiFlag = false; + } + } while(false); + + if (this.isTianHu) { + if (player.seat == this.bankerSeat) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.TIAN_HU, 1, 120)); + } + + mingtang = true; + } + } + else { + if (player.isDiHu) + { + if (player.seat == this.bankerSeat && config.getInt(Config.ROOM_CONFIG_ZHUANG_DI_HU) == 0) + { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 120)); + } + + mingtang = true; + } + else if (player.seat != this.bankerSeat) + { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.DI_HU, 1, 120)); + } + + mingtang = true; + } + } + } + + if (duiFlag && !this.isTianHu && !player.isDiHu && player.isTingHu) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 60; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 60)); + } + else { + player.winFan += 80; + player.mingtangList.add(new MingTang(RuleWeight.TING_HU, 1, 80)); + } + + mingtang = true; + } + + if (this.card.getCount() == 0) { + player.winFan += 30; + player.mingtangList.add(new MingTang(RuleWeight.HAI_HU, 1, 30)); + mingtang = true; + } + + if (player.cardInhand.size() == 1 && player.kanGroup.size() == 0 && player.tiGroup.size() == 0) + { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 60; + player.mingtangList.add(new MingTang(RuleWeight.QUAN_QIU_REN, 1, 60)); + } + else { + player.winFan += 80; + player.mingtangList.add(new MingTang(RuleWeight.QUAN_QIU_REN, 1, 80)); + } + + mingtang = true; + } + + // + if (redCard == 0) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + int fan = 80; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + else { + int fan = 100; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.WU_HU, 1, fan)); + } + + mingtang = true; + } + // + if (redCard == 1) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + int fan = 60; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + else { + int fan = 80; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DIAN_HU, 1, fan)); + } + + mingtang = true; + } + + if (redCard >= 13) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + int fan = 80; + if (this.config.getInt(Config.ROOM_CONFIG_HAO_CONFIG) == 0) + { + fan += (redCard - 13) * 10; + } + else { + fan += (redCard - 13) * 20; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + else { + int fan = 100; + if (this.config.getInt(Config.ROOM_CONFIG_HAO_CONFIG) == 0) + { + fan += (redCard - 13) * 10; + } + else { + fan += (redCard - 13) * 20; + } + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.HONG_HU, 1, fan)); + } + + mingtang = true; + } + + if (smallCard <= 0) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + int fan = 100; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + else { + int fan = 120; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.DA_HU, 1, fan)); + } + + mingtang = true; + } + + if (bigCard <= 0) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + int fan = 100; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + else { + int fan = 120; + player.winFan += fan; + player.mingtangList.add(new MingTang(RuleWeight.XIAO_HU, 1, fan)); + } + + mingtang = true; + } + + //对子胡 + if (isDuzi) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 100; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 100)); + } + else { + player.winFan += 120; + player.mingtangList.add(new MingTang(RuleWeight.DUIZI_HU, 1, 120)); + } + + mingtang = true; + } + + if (!isDuzi && huXiNum == 7) { + if (this.config.getInt(Config.ROOM_CONFIG_MENG_TANG) == 0) + { + player.winFan += 60; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 60)); + } + else { + player.winFan += 80; + player.mingtangList.add(new MingTang(RuleWeight.XING_XING_XI, 1, 80)); + } + + mingtang = true; + } + + if (!mingtang) + { + player.huXi = huXi; + player.total_huxi += player.huXi; + player.winScore = player.huXi; + int score = player.winScore; + return score; + } + else + { + player.huXi = player.winFan + kanXi + waiXi + haoXi; + player.total_huxi += player.huXi; + player.winScore = player.huXi; + int score = player.winScore; + return score; + } + } + + public boolean checkPao(int eventCard, boolean isDis) { + for (Entry entry : this.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (isDis) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } else { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + return true; + } + } + if (player.seat != this.activeSeat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + return true; + } + } + } + } + } + return false; + } + + // public void settleRound() { + // saveMilitaryRound(playBackData.getData(this)); + // if (this.liuju == true) { + // this.bankerSeat = this.playerMapBySeat.get(this.bankerSeat).nextSeat; + // } + // boolean total = this.round >= this.maxRound; + // int result = this.nonNegative(false); + // if (!total) { + // EXMainServer.gameCtr.roomResult(this); + // if (result == 4) { + // total = true; + // this.saveMilitaryTotal(false); + // } + // } else { + // this.saveMilitaryTotal(false); + // } + // this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class)); + // this.winCount = 0; + // + // if (total) { + // this.stateMachine.changeState(Global.getState(RoomEndGameState.class)); + // return; + // } + // } + + public void win(EXPlayer player, EXPlayer activePlayer) { + if (player.getRoom().drawCard != 0) { + player.winCard = player.getRoom().drawCard; + } + player.winer = 1; + + this.addScore(player); + // this.liuju = false; + this.liujuNum = 0; + + for (Entry entry : this.playerMapById.entrySet()) { + if (entry.getKey().equals(player.playerid)) { + continue; + } + EXPlayer fromPlayer = (EXPlayer) entry.getValue(); + fromPlayer.winer = 2; + } + EXMainServer.gameCtr.winEvent(player, player.seat); + // if (owner.room.config.getInt(Config.GAME_ZHUANG) == 1) { + // if (room.bankerSeat != owner.seat) { + // room.bankerSeat = owner.lastSeat; + // } + // } else { + // room.bankerSeat = owner.seat; + // } + this.bankerSeat = player.seat; + player.winCount++; + this.endGame(); + } + + @Override + public void endGame() { + this.getPlayBack().addResultData(EXMainServer.gameCtr.getRoomResultData(this)); + super.endGame(); + } + + @Override + protected void roomResult() { + EXMainServer.gameCtr.roomResult(this); + } + + @Override + public void saveMilitaryTotal(boolean dissmiss) { + super.saveMilitaryTotal(dissmiss); + EXMainServer.gameCtr.roomTotalResult(this, dissmiss); + } + + public PlayBack getPlayBack() { + return (PlayBack) playBackData; + } + + @Override + public void clear() { + super.clear(); + logger.info("jefe clear:"+this.isAllPass); + this.liuju = false; + this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0; + this.isplaying = this.isAllPass = false; + this.isTianHu = this.isDiHu = true; + this.paiXing = TObject.newInstance(); + this.throwCardsSet.clear(); + this.throwCardsList.clear(); + } + // public void destroy() { + // super.destroy(); + // } + + /** + * 开启倍数后 体力值消耗= 倍数*分数 + */ + private int reMultipleScore(int score) { + if (this.hpData != null) { + if (this.hpData.containsKey("times")) { + return Math.round(score / this.hpData.getInt("times")); + } + } + return score; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXScore.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXScore.java new file mode 100644 index 0000000..fb3834e --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/EXScore.java @@ -0,0 +1,15 @@ +package extend.zp; + +import com.game.data.Score; + +public class EXScore extends Score { + public static final int WIN = 1; + + public EXScore(EXPlayer owner) { + super(owner); + } + + protected void initLog() { + this.round_log.put(WIN, 0); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/MingTang.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/MingTang.java new file mode 100644 index 0000000..82b8723 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/MingTang.java @@ -0,0 +1,13 @@ +package extend.zp; + +public class MingTang { + public int mingTang; + public int type; + public int score; + + public MingTang(int mingTang, int type, int score) { + this.mingTang = mingTang; + this.type = type; + this.score = score; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/OpCard.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/OpCard.java new file mode 100644 index 0000000..25f7011 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/OpCard.java @@ -0,0 +1,41 @@ +package extend.zp; + +import java.io.Serializable; + +public class OpCard implements Serializable{ + private static final long serialVersionUID = 1L; + public int type; + public int card1; + public int card2; + public int card3; + public int huXi; + public boolean pailie; + public int hao; + public int haoCard; + + public OpCard(int type, int card1, int card2, int card3, int huXi) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = false; + this.hao = 0; + this.haoCard = 0; + } + + public OpCard(int type, int card1, int card2, int card3, int huXi, boolean pailei, int hao, int haoCard) { + this.type = type; + this.card1 = card1; + this.card2 = card2; + this.card3 = card3; + this.huXi = huXi; + this.pailie = pailei; + this.hao = hao; + this.haoCard = haoCard; + } + + public OpCard() { + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayBack.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayBack.java new file mode 100644 index 0000000..74f6ad7 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayBack.java @@ -0,0 +1,107 @@ +package extend.zp; + +import java.util.Map.Entry; + +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.TArray; +import com.taurus.core.entity.TObject; + +public class PlayBack extends BasePlayBack { + + public PlayBack(EXRoom room) { + super(room); + info.putInt("left_card", room.card.getCount()); + ITArray infoList = new TArray(); + for (Entry entry : room.playerMapById.entrySet()) { + ITObject obj = TObject.newInstance(); + EXPlayer player = (EXPlayer) entry.getValue(); + 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); + ITArray cardInhand = Util.toTArray(player.cardInhand); + obj.putTArray("hand_card", cardInhand); + obj.putInt("score", player.score.total_score); + infoList.addTObject(obj); + } + info.putTArray("playerData", infoList); + } + + 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 addAddCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("AddCard", seat, data); + } + + public void addThrowCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("ThrowCard", seat, data); + } + + public void addOutCardCommand(int seat, int card) { + ITObject data = TObject.newInstance(); + data.putInt("card", card); + addCommand("OutCard", seat, data); + } + + public void addResultData(ITObject resultData){ + ITObject mp = TObject.newInstance(); + mp.putInt("type", 0); + mp.putTObject("data", resultData); + ITObject cmdObj = TObject.newInstance(); + cmdObj.putUtfString("cmd", "result"); + cmdObj.putTObject("result", mp); + cmdList.addTObject(cmdObj); + } + + public void addActionCommand(int seat, int type, int active_card, int card, int from_seat, int huxi, ITArray opcardArray) { + ITObject cmdData = TObject.newInstance(); + cmdData.putInt("active_card", active_card); + cmdData.putInt("card", card); + cmdData.putInt("type", type); + cmdData.putInt("from_seat", from_seat); + cmdData.putInt("hu_xi", huxi); + if (opcardArray != null) { + ITArray opcard = TArray.newInstance(); + for (int i = 0; i < opcardArray.size(); i++) { + opcard.addInt(opcardArray.getInt(i)); + } + cmdData.putTArray("opcard", opcard); + } + addCommand("Action", seat, cmdData); + } + + public void addWinCardCommand(int seat, boolean zimo) { + ITObject cmdData = TObject.newInstance(); + addCommand("Win", seat, cmdData); + } + + public 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); + } + + public ITObject getData(EXRoom owner) { + ITObject data = TObject.newInstance(); + data.putTObject("info", info); + data.putTArray("cmdList", cmdList); + data.putTObject("result", EXMainServer.gameCtr.getRoomResultData(owner)); + return data; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayerRuleManager.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayerRuleManager.java new file mode 100644 index 0000000..06c999e --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/PlayerRuleManager.java @@ -0,0 +1,133 @@ +package extend.zp; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.game.Global; + +import extend.zp.player.rule.*; +import extend.zp.player.state.EXPlayerDisCardTipState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.player.state.EXPlayerTipState; +import extend.zp.tip.IRuleBase; + + +public class PlayerRuleManager { + public static final int DEAL_RULE = 1; + public static final int KAN_RULE = 2; + public static final int TI_RULE = 3; + public static final int DRAW_RULE = 4; + public static final int OTHER_DRAW_RULE = 5; + public static final int DRAW_PAO_RULE = 6; + public static final int DISCARD_RULE = 7; + public static final int HU_RULE = 9; + public static final int OTHER_HU_RULE = 11; + public static final int WAI_LIU_RULE = 12; + public static final int DEAL_LIU_RULE = 13; + public static final int HU_LIU_RULE = 14; + + public HashMap> ruleMap = null; + public HashMap tipMap = null; + + public PlayerRuleManager() { + ruleMap = new HashMap>(); + + tipMap = new HashMap(); + tipMap.put(PlayerRuleManager.DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.WAI_LIU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.DEAL_LIU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.TI_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + tipMap.put(PlayerRuleManager.HU_LIU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDrawTipState.class)); + + tipMap.put(PlayerRuleManager.OTHER_DRAW_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.DISCARD_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + tipMap.put(PlayerRuleManager.OTHER_HU_RULE, (EXPlayerTipState) Global.getState(EXPlayerDisCardTipState.class)); + + List dealList = new ArrayList(); + dealList.add(new RuleDealTi()); + dealList.add(new RuleDealKan()); + ruleMap.put(PlayerRuleManager.DEAL_RULE, dealList); + + List dealKanList = new ArrayList(); + dealKanList.add(new RuleKan()); + ruleMap.put(PlayerRuleManager.KAN_RULE, dealKanList); + + List paoList = new ArrayList(); + //paoList.add(new RuleTi()); + paoList.add(new RuleWei()); + ruleMap.put(PlayerRuleManager.TI_RULE, paoList); + + List drawRuleList = new ArrayList(); + drawRuleList.add(new RuleWin()); + drawRuleList.add(new RuleDrawChi()); + drawRuleList.add(new RuleLiu()); + ruleMap.put(PlayerRuleManager.DRAW_RULE, drawRuleList); + + List otherDrawRuleList = new ArrayList(); + otherDrawRuleList.add(new RuleWin()); + otherDrawRuleList.add(new RuleDrawPong()); + otherDrawRuleList.add(new RuleDrawChi()); + ruleMap.put(PlayerRuleManager.OTHER_DRAW_RULE, otherDrawRuleList); + + List drawPaoList = new ArrayList(); + //drawPaoList.add(new RuleDrawPao()); + ruleMap.put(PlayerRuleManager.DRAW_PAO_RULE, drawPaoList); + + List otherDiscardList = new ArrayList(); + //otherDiscardList.add(new RuleDiscardPao()); + otherDiscardList.add(new RulePong()); + otherDiscardList.add(new RuleChi()); + ruleMap.put(PlayerRuleManager.DISCARD_RULE, otherDiscardList); + + List huList = new ArrayList(); + huList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.HU_RULE, huList); + + List wailiuList = new ArrayList(); + wailiuList.add(new RuleWin()); + wailiuList.add(new RuleWeiLiu()); + ruleMap.put(PlayerRuleManager.WAI_LIU_RULE, wailiuList); + + List dealliuList = new ArrayList(); + dealliuList.add(new RuleDealLiu()); + ruleMap.put(PlayerRuleManager.DEAL_LIU_RULE, dealliuList); + + List huliuList = new ArrayList(); + huliuList.add(new RuleWin()); + huliuList.add(new RuleDealLiu()); + ruleMap.put(PlayerRuleManager.HU_LIU_RULE, huliuList); + + + List otherHuList = new ArrayList(); + otherHuList.add(new RuleWin()); + ruleMap.put(PlayerRuleManager.OTHER_HU_RULE, otherHuList); + } + + public boolean condition(int type, EXPlayer player) { + return condition(type, player, true); + } + + public boolean conditionEx(int type, EXPlayer player) { + return condition(type, player, false); + } + + public boolean condition(int type, EXPlayer player, boolean tonextState) { + List ruleList = this.ruleMap.get(type); + boolean result = false; + player.tipMgr.clean(); + + for (IRuleBase rule : ruleList) { + result = rule.condition(player) || result; + } + + if (result) { + player.stateMachine.changeState(this.tipMap.get(type)); + } else { + if (tonextState) + player.stateMachine.toNextState(); + } + return result; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RoomCard.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RoomCard.java new file mode 100644 index 0000000..1effa92 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RoomCard.java @@ -0,0 +1,141 @@ +package extend.zp; + +import com.taurus.core.util.Logger; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class RoomCard { + + Logger logger = Logger.getLogger(getClass()); + + public ArrayList cardList; + EXRoom room; + public ArrayList subCardList; + + public RoomCard(EXRoom table) { + this.cardList = new ArrayList(); + this.room = table; + this.subCardList = new ArrayList<>(); + } + + public List getAllResult(){ + List all = new ArrayList<>(); + if(subCardList.size() > 0) + all.addAll(subCardList); + all.addAll(cardList); + return all; + } + + public void init() { + this.cardList.clear(); + this.subCardList.clear(); + //this.initCard2(); + //this.initCard_tianhu(); + this.initCard(); + this.shuffle(); + } + + private void initCard() { + for (int index = 1; index <= 10; index++) { + for (int index2 = 0; index2 < 4; index2++) { + this.cardList.add(100 + index); + this.cardList.add(200 + index); + } + } + } + + private void initCard2() { +// List list = Arrays.asList(110,108,109,202,103,110,103,203,203,203,208,205,206, 202,204,210, 102,107,107); +// List list2 = Arrays.asList(110,108,109,202,103,110,103,203,203,203,208,205,206, 202,204,210, 102,107,107); +// List list3 = Arrays.asList(207, 105, 207, 207, 207, 207, 207, 207, 207, 207, 206, 203, 210, 206, 201, 205, 210, 202, 105, 101, 210, 106, 204, 107, 201, 209, 106, 205, 109, 209, 103, 104, 101, 105, 103, 202, 108, 109, 208); +// List list = Arrays.asList(103, 103, 103, 104, 104, 105, 106, 107, 109, 201, 202, 202, 203, 204, 205, 206, 209, 210, 210); +// List list2 = Arrays.asList(101, 102, 102, 103, 107, 110, 110, 110, 201, 201, 202, 204, 205, 205, 206, 206, 207, 208, 210); +// List list3 = Arrays.asList(107, 101, 204, 108, 207, 106, 203, 110, 201, 106, 207, 208, 204, 108, 108, 203, 105, 101, 102, 105, 208, 109, 102, 205, 209, 206, 209, 210, 106, 109, 105, 104, 109, 209, 107, 104, 207, 203, 101, 202, 108, 208); + List list = Arrays.asList(104,104, 104, 107, 107, 108, 108, 108, 109, 109, 110, 201, 201, 202, 207, 210, 204, 204, 103); + List list2 = Arrays.asList(101,101, 102, 102, 103, 103, 104, 104, 105, 105, 106, 106, 107, 107, 108, 108, 109, 109, 110); + List list3 = Arrays.asList( 202,204,104, 104,101, 109, 101, 106, 101, 105, 109, 205, 205, 208, 209, 207, 109, 203, 208, 102, 210, 106, 104, 107, 202, 105, 206, 206, 109, 202, 209, 210, 104, 206, 107, 101, 108, 210, 203, 101, 209, 106, 209); + + this.cardList.addAll(list); + this.cardList.addAll(list); + this.cardList.addAll(list3); + } + + private void initCard_tianhu() { + List list = Arrays.asList(101, 101, 101, 102, 102, 102, 102, 104, 103, 104, 104, 104, 105, 105, 105, 106, 106, 106, 107); + List list2 = Arrays.asList(201, 201, 202, 202, 206, 207, 207, 210, 210, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110); + List list3 = Arrays.asList(107, 108, 106, 103, 104, 105, 106, 107, 107, 108, 108, 108, 108, 109, 109, 109, 109, 110, 110, 110, 110, 203, 204, 205, 206, 206, 207, 207, 207, 207, 208, 208, 208, 208, 209, 209, 209, 209, 210, 210, 210, 210); + + this.cardList.addAll(list); + this.cardList.addAll(list); + this.cardList.addAll(list3); + } + + private void shuffle() { + Collections.shuffle(this.cardList); + } + + public int pop() { + if (this.cardList.size() == 0) { + if(this.subCardList.size() > 0) { + int card = this.subCardList.remove(0); + return card; + }else { + return 0; + } + }else { + int card = this.cardList.remove(0); + return card; + } + } + + public int popsub() { + if (this.subCardList.size() == 0) { + int card = this.cardList.remove(0); + return card; + }else { + int card = this.subCardList.remove(0); + return card; + } + } + + public int getCount() { + return this.cardList.size() + this.subCardList.size(); + } + + /** + * 发牌 + * */ + public ArrayList deal() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 19; index++) { + //logger.info("jefe card id:" + this.pop()); + dealCards.add(this.pop()); + } + return dealCards; + } + + public ArrayList deal2() { + ArrayList dealCards = new ArrayList(); + for (int index = 0; index < 20; index++) { + dealCards.add(this.pop()); + } + return dealCards; + } + + public void reInitCards(List cards) { + //从底牌移除 + for(Integer card : cards) { + for(int i = cardList.size() - 1;i >= 0;i--) { + if(cardList.get(i).intValue() == card.intValue()) { + if(cardList.remove(i) > 0) { + this.subCardList.add(card); + } + break; + } + } + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RuleWeight.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RuleWeight.java new file mode 100644 index 0000000..e67a3b7 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/RuleWeight.java @@ -0,0 +1,63 @@ +package extend.zp; + +public class RuleWeight { + public final static int CHOW1 = 1; + public final static int CHOW2 = 2; + public final static int PONG = 3; + public final static int WIN1 = 4; + public final static int WIN2 = 5; + public final static int WIN3 = 6; + public final static int TI = 7; + public final static int WAI = 8; + + public final static int TYPE_CHOW = 1; + public final static int TYPE_PONG = 2; + public final static int TYPE_KAN = 3; + public final static int TYPE_WEI = 4; + public final static int TYPE_CHOUWEI = 5; + public final static int TYPE_PAO = 6; + public final static int TYPE_TI = 7; + public final static int TYPE_WIN = 8; + public final static int TYPE_BI = 9; + public final static int TYPE_JIANG = 10; + + public final static int SMALL_CARD = 1; + public final static int BIG_CARD = 2; + + public final static int HONG_HU = 1; + public final static int WU_HU = 2; + public final static int DIAN_HU = 3; + public final static int DUIZI_HU = 4; + public final static int TIAN_HU = 5; + public final static int DI_HU = 6; + public final static int HAI_HU = 7; + public final static int TING_HU = 8; + public final static int DA_HU = 9; + public final static int XIAO_HU = 10; + public final static int DA_TUAN_YUAN = 11; + public final static int XING_XING_XI = 12; + public final static int SI_QI_HONG = 13; + public final static int SHUA_HOU = 14; + public final static int HUANG_FAN = 15; + public final static int ZI_MO = 16; + public final static int JIA_XING_XING = 17; + public final static int HONG_WU = 18; + public final static int YUAN = 19; + public final static int BEI_KAO_BEI = 20; + public final static int HONG_DUI =21; + public final static int WU_DUI = 22; + public final static int JIAHONG_DUI = 23; + public final static int DHDF = 24; + public final static int NO_DUI = 25;; //没有对子, 无对 + public final static int YI_DUI = 26; //一对 + public final static int JIU_DUI = 27; //九对 + public final static int SHI_DUI = 28; //十对 + public final static int QUAN_QIU_REN = 29; //全求人 + + + public final static int HAO_NONE = 0; + public final static int HAO_SHAN = 1; //散毫 + public final static int HAO_QING = 2; //清溜 + public final static int HAO_NUI = 3; //内毫 + public final static int HAO_WAI = 4; //外毫 +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleChi.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleChi.java new file mode 100644 index 0000000..030a101 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleChi.java @@ -0,0 +1,33 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + return player.chi(player.getRoom().activeCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + int activeCard=room.activeCard; + PRChi.prChi(activeCard, player, false); + room.activeCard = 0; + room.lastDiscardSeat = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + player.stateMachine.changeState(Global.getState(PRChiState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java new file mode 100644 index 0000000..e346b69 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealKan.java @@ -0,0 +1,78 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + + if(num == 2 && card == player.drawCard) { + + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true, RuleWeight.HAO_NONE, 0)); + //EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + + ITObject param = new TObject(); + param.putInt("card", card); + param.putInt("seat", player.room.activeSeat); + player.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + } + if (num == 3) { + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true, RuleWeight.HAO_NONE, 0)); + //EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealLiu.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealLiu.java new file mode 100644 index 0000000..b58ef5d --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealLiu.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDealLiuState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; + + +public class RuleDealLiu implements IRuleBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + int eventCard = player.drawCard; + boolean flag = false; + //player.tipMgr.clean(); + logger.info("jefe RuleDealLiu:" + eventCard); + + if (eventCard > 0) + { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + flag = true; + break; + } + } + + for (int i = 0; i < player.tiGroup.size(); i++) { + int card = player.tiGroup.get(i)[0]; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + Tip tip = new Tip(card, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + flag = true; + } + } + else { + for (int i = 0; i < player.tiGroup.size(); i++) { + int card = player.tiGroup.get(i)[0]; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + Tip tip = new Tip(card, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + flag = true; + } + } + logger.info("jefe RuleDealLiu end:" + flag); + return flag; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDealLiuState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java new file mode 100644 index 0000000..5637d74 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDealTi.java @@ -0,0 +1,61 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +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.Logger; +import extend.zp.*; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleDealTi implements IRuleBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public boolean condition(EXPlayer player) { + + logger.info("jefe RuleDealTi "); + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + + int card = entry.getKey(); + int num = entry.getValue(); + + if (num == 4) { + player.tiCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + player.tiGroup.add(tiGroup); + + //清溜 + player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card), true, RuleWeight.HAO_QING, card)); + //EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard); + } + } + logger.info("jefe RuleDealTi end"); + return false; + } + + @Override + public void action(EXPlayer player) { + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java new file mode 100644 index 0000000..c3a82db --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDiscardPao.java @@ -0,0 +1,54 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDiscardPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDiscardPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + int eventCard = player.getRoom().activeCard; + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + player.getRoom().activeCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java new file mode 100644 index 0000000..cefe3ea --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawChi.java @@ -0,0 +1,36 @@ +package extend.zp.player.rule; + +import com.game.Global; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.player.rulestate.PRChi; +import extend.zp.player.rulestate.PRDrawChiState; +import extend.zp.tip.IRuleBase; + + +public class RuleDrawChi implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + return player.chi(eventCard, this); + } + + @Override + public void action(EXPlayer player) { + EXRoom room = (EXRoom) player.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(player.room.activeSeat); + int activeCard = activePlayer.drawCard; + PRChi.prChi(activeCard, player, true); + activePlayer.drawCard = 0; + EXMainServer.gameCtr.changeActiveSeat(room, player.seat); + + player.stateMachine.changeState(Global.getState(PRDrawChiState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java new file mode 100644 index 0000000..5b33794 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPao.java @@ -0,0 +1,74 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPaoState; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; + + +public class RuleDrawPao implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + for (int i = 0; i < player.pongGroup.size(); i++) { + if (eventCard == player.pongGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.pongGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_PONG, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + if (player.seat != activePlayer.seat) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + activePlayer.drawCard = 0; + player.weiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + player.initOpCard(opcard); + this.action(player); + return false; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPaoState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java new file mode 100644 index 0000000..9dc6c47 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleDrawPong.java @@ -0,0 +1,86 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRDrawPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + +import java.util.ArrayList; + + +public class RuleDrawPong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + ArrayList tempList = new ArrayList<>(); + tempList.addAll(player.cardInhand); + for (int i = 0; i < player.kanGroup.size(); i++) { + tempList.add(player.kanGroup.get(i)[0]); + tempList.add(player.kanGroup.get(i)[0]); + tempList.add(player.kanGroup.get(i)[0]); + } + for (int i = 0; i < player.tiGroup.size(); i++) { + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + } + if (tempList.size() <= 2) { + return false; + } + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (player.seat == activePlayer.seat) { + return false; + } + int eventCard = activePlayer.drawCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + else { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRDrawPongState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleKan.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleKan.java new file mode 100644 index 0000000..7cdf612 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleKan.java @@ -0,0 +1,50 @@ +package extend.zp.player.rule; + +import java.util.Map; +import java.util.Map.Entry; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.IRuleBase; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleKan implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Entry entry : cardMap.entrySet()) { + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 2) { + player.winCard = player.drawCard; + player.drawCard = 0; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(player.cardInhand, card, num); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true, RuleWeight.HAO_NONE, 0)); + //EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_KAN, player.seat, opcard); + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleLiu.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleLiu.java new file mode 100644 index 0000000..3720988 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleLiu.java @@ -0,0 +1,64 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRLiuState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + +import java.util.Map; + + +public class RuleLiu implements IRuleBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + int eventCard = player.drawCard; + logger.info("jefe RuleLiu " +eventCard); + Map cardMap = CardUtil.getCardNumMap(player.cardInhand); + for (Map.Entry entry : cardMap.entrySet()) { + // 如果抓的牌 手中刚好有三张 + int card = entry.getKey(); + int num = entry.getValue(); + if (card == player.drawCard && num == 3) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + if (eventCard == player.weiGroup.get(i)[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + return true; + } + } + + logger.info("jefe RuleLiu end" ); + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRLiuState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RulePong.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RulePong.java new file mode 100644 index 0000000..b81e06f --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RulePong.java @@ -0,0 +1,84 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRPongState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + +import java.util.ArrayList; + + +public class RulePong implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + ArrayList tempList = new ArrayList<>(); + tempList.addAll(player.cardInhand); + for (int i = 0; i < player.kanGroup.size(); i++) { + tempList.add(player.kanGroup.get(i)[0]); + tempList.add(player.kanGroup.get(i)[0]); + tempList.add(player.kanGroup.get(i)[0]); + } + for (int i = 0; i < player.tiGroup.size(); i++) { + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + tempList.add(player.tiGroup.get(i)[0]); + } + if (tempList.size() <= 2) { + return false; + } + EXRoom room = player.getRoom(); + int eventCard = room.activeCard; + if (eventCard == 0) { + return false; + } + if (player.isEntrust()) { + player.chouPongSet.add(eventCard); + return false; + } + // ���� + if (player.chouPongSet.contains(eventCard)) { + return false; + } + if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) { + return false; + } + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + else { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG); + player.tipMgr.addTip(tip); + return true; + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRPongState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWei.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWei.java new file mode 100644 index 0000000..6fe8738 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWei.java @@ -0,0 +1,130 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleWei implements IRuleBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + int eventCard = player.drawCard; + logger.info("jefe RuleWei "+eventCard); + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + if (player.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) == 0) + { + if (Paixing.checkWin(player, player.drawCard, true)) { + return false; + } + else { + player.winCard = player.drawCard; + player.drawCard = 0; + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(0); + player.initOpCard(opcard); + this.action(player); + } + } + else { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.WAI, this, RuleWeight.TYPE_WEI); + player.tipMgr.addTip(tip); + return true; + } + } + else { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + if (player.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) == 0) + { + if (Paixing.checkWin(player, player.drawCard, true)) { + return false; + } + else { + player.winCard = player.drawCard; + player.drawCard = 0; + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + player.cardInhand.add(eventCard); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(1); + player.initOpCard(opcard); + this.action(player); + break; + } + } + else { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.WAI, this, RuleWeight.TYPE_WEI); + player.tipMgr.addTip(tip); + return true; + } + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.notPutSet.add(player.drawCard); + if (player.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) != 0) + { + int eventCard = player.drawCard; + player.winCard = player.drawCard; + player.drawCard = 0; + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(0); + player.initOpCard(opcard); + } + else + { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + player.cardInhand.add(eventCard); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(1); + player.initOpCard(opcard); + break; + } + } + } + } + + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiHu.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiHu.java new file mode 100644 index 0000000..3b758b2 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiHu.java @@ -0,0 +1,95 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import extend.zp.Config; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWeiState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class RuleWeiHu implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + int eventCard = player.drawCard; + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + if (player.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) == 0) + { + if (Paixing.checkWin(player, player.drawCard, true)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.WAI, this, RuleWeight.TYPE_WEI); + player.tipMgr.addTip(tip); + return true; + } + } + } + else { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + if (player.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) == 0) + { + if (Paixing.checkWin(player, player.drawCard, true)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.WAI, this, RuleWeight.TYPE_WEI); + player.tipMgr.addTip(tip); + return true; + } + else { + break; + } + } + } + } + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.notPutSet.add(player.drawCard); + int eventCard = player.drawCard; + player.winCard = player.drawCard; + player.drawCard = 0; + if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) { + CardUtil.removeCard(player.cardInhand, eventCard, 2); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(0); + player.initOpCard(opcard); + } + else + { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (eventCard == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + player.cardInhand.add(eventCard); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(1); + player.initOpCard(opcard); + break; + } + } + } + + player.stateMachine.changeState(Global.getState(PRWeiState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiLiu.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiLiu.java new file mode 100644 index 0000000..e64f016 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWeiLiu.java @@ -0,0 +1,117 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.*; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; + + +public class RuleWeiLiu implements IRuleBase { + Logger logger = Logger.getLogger(getClass()); + public boolean qlflag = false; + + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + //player.tipMgr.clean(); + int eventCard = player.drawCard; + /* logger.info("jefe weiliu wincard:" + player.winCard); + logger.info("jefe weiliu rreventCard:" + eventCard); + logger.info("jefe weiliu player.weiGroup:" + player.weiGroup.size()); + logger.info("jefe weiliu player.KAN:" + player.kanGroup.size()); + logger.info("jefe weiliu CardUtil.cardNum:" + CardUtil.cardNum(eventCard, player.cardInhand)); + logger.info("jefe weiliu player.cardInhand:" + player.cardInhand);*/ + + // logger.info("jefe weiliu player.it:" + player.tiGroup); + if (!(player.stateMachine.curState instanceof PRWeiState)) { + for (int i = 0; i < player.weiGroup.size(); i++) { + // logger.info("jefe weiliu player.weiGroup:" + player.weiGroup.get(0)[0]); + if (eventCard == player.weiGroup.get(i)[0]) { + //if (CardUtil.cardNum(eventCard, player.cardInhand) == 1) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + return true; + } + } + } + boolean flag = false; + + if((player.stateMachine.curState instanceof PRChiState)||(player.stateMachine.curState instanceof PRPongState)||(player.stateMachine.curState instanceof PRWeiState)||(player.stateMachine.curState instanceof PRDrawPongState)||(player.stateMachine.curState instanceof PRDrawChiState)){ + + if (player.tiGroup.size()>0){ + for (int i = 0; i < player.tiGroup.size(); i++) { + eventCard = player.tiGroup.get(i)[0]; + // logger.info("jefe weitiliuaaaeventCard:" + eventCard); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + this.qlflag = true; + flag = true; + // return true; + } + } + for (int i = 0; i < player.weiGroup.size(); i++) { + // if (eventCard == player.weiGroup.get(i)[0] && CardUtil.cardNum(eventCard, player.cardInhand) == 1) { + if ( CardUtil.cardNum(eventCard, player.cardInhand) == 1) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + return true; + }else { + + for (int j = 0; j < player.cardInhand.size(); j++) { + if (player.cardInhand.get(j) == player.weiGroup.get(i)[0]) { + eventCard = player.cardInhand.get(j); + // logger.info("jefe weiliuaaaeventCard:" + eventCard); + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI); + player.tipMgr.addTip(tip); + return true; + } + } + } + } + // + + } + // logger.info("jefe weiliu end" + player.tiGroup); + return flag; + } + + @Override + public void action(EXPlayer player) { + // logger.info("jefe weiliu action" ); + if (this.qlflag){ + this.qlflag = false; + player.stateMachine.changeState(Global.getState(PRDealLiuState.class)); + }else{ + player.stateMachine.changeState(Global.getState(PRWeiLiuState.class)); + } + + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWin.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWin.java new file mode 100644 index 0000000..6664e2d --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rule/RuleWin.java @@ -0,0 +1,53 @@ +package extend.zp.player.rule; + +import com.game.Global; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; +import extend.zp.player.rulestate.PRWinState; +import extend.zp.tip.IRuleBase; +import extend.zp.tip.Tip; +import extend.zp.uitl.Paixing; + + +public class RuleWin implements IRuleBase { + @Override + public boolean condition(EXPlayer player) { + if (player.isDeadPut) + { + return false; + } + if (player.isLaoYe) { + return false; + } + + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (activePlayer == null) { + return false; + } + if (Paixing.checkWin(player, activePlayer.drawCard, activePlayer.seat == player.seat)) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(activePlayer.drawCard); + int weight = RuleWeight.WIN3; + if (activePlayer.seat != player.seat) { + if (player.seat == activePlayer.nextSeat) { + weight = RuleWeight.WIN2; + } else { + weight = RuleWeight.WIN1; + } + } + Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN); + player.tipMgr.addTip(tip); + player.getRoom().winSeat = activePlayer.seat; + return true; + } + return false; + } + + @Override + public void action(EXPlayer player) { + player.stateMachine.changeState(Global.getState(PRWinState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChi.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChi.java new file mode 100644 index 0000000..d429ec4 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChi.java @@ -0,0 +1,311 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.Util; +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 extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.tip.Tip; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +public class PRChi { + + public static void prChi(int card, EXPlayer owner, boolean drawChi) { + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + Tip actionTip = owner.actionTip; + ITArray opcard = actionTip.opcard; + int chowcard1 = opcard.getInt(0); + int chowcard2 = opcard.getInt(1); + __chow(owner, chowcard1, chowcard2, card, activePlayer, false, drawChi); + if (actionTip.bi_list != null && actionTip.biid != null) { + ITObject obj = actionTip.bi_list.getTObject(actionTip.biid.getInt(0)); + ITArray biopcard = obj.getTArray("opcard"); + __chow(owner, biopcard.getInt(0), biopcard.getInt(1), card, owner, true, drawChi); + if (obj.containsKey("bi_list")) { + ITArray bi_list1 = obj.getTArray("bi_list"); + ITObject obj1 = bi_list1.getTObject(actionTip.biid.getInt(1)); + ITArray biopcard1 = obj1.getTArray("opcard"); + __chow(owner, biopcard1.getInt(0), biopcard1.getInt(1), card, owner, true, drawChi); + } + } + + } + + private static final void __chow(EXPlayer player, int chowcard1, int chowcard2, int card, EXPlayer activePlayer, boolean bi, boolean drawChi) { + int[] chiGroup = new int[3]; + chiGroup[0] = chowcard1; + chiGroup[1] = card; + chiGroup[2] = chowcard2; + int haoCard = 0; + int haoType = RuleWeight.HAO_NONE; + player.notPutSet.add(card); + if (chowcard1 - chowcard2 == 1) + { + if (chowcard2 % 100 == 1) + { + player.notPutSet.add(chowcard2 + 2); + } + else if (chowcard2 % 100 == 9) + { + player.notPutSet.add(chowcard2 - 1); + } + else + { + player.notPutSet.add(chowcard2 - 1); + player.notPutSet.add(chowcard2 + 2); + } + } + else if (chowcard1 - chowcard2 == 2) + { + player.notPutSet.add(chowcard2 + 1); + } + else if (chowcard2 - chowcard1 == 1) + { + if (chowcard1 % 100 == 1) + { + player.notPutSet.add(chowcard1 + 2); + } + else if (chowcard1 % 100 == 9) + { + player.notPutSet.add(chowcard1 - 1); + } + else + { + player.notPutSet.add(chowcard1 - 1); + player.notPutSet.add(chowcard1 + 2); + } + } + else if (chowcard2 - chowcard1 == 2) + { + player.notPutSet.add(chowcard1 + 1); + } + + if (!Util.checkCard(chowcard1, player.cardInhand)) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (chowcard1 == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, chowcard1, chowcard1, chowcard1, 0)); + player.cardInhand.add(chowcard1); + player.cardInhand.add(chowcard1); + break; + } + } + for (int i = 0; i < player.tiGroup.size(); i++) { + if (chowcard1 == player.tiGroup.get(i)[0]) { + player.tiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_TI, chowcard1, chowcard1, chowcard1, 0)); + + ////////////////////////////////////////////////// +// player.cardInhand.add(chowcard1); +// player.cardInhand.add(chowcard1); +// player.cardInhand.add(chowcard1); + //============================================ + int[] kanGroup = new int[3]; + kanGroup[0] = chowcard1; + kanGroup[1] = chowcard1; + kanGroup[2] = chowcard1; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, chowcard1, chowcard1, chowcard1, Paixing.caclHuxi(RuleWeight.TYPE_KAN, chowcard1), true, RuleWeight.HAO_NONE, 0)); + //////////////////////////////////////////////// + + haoCard = chowcard1; + haoType = RuleWeight.HAO_NUI; + break; + } + } + } + else { + CardUtil.removeCard(player.cardInhand, chowcard1, 1); + } + + if (!Util.checkCard(chowcard2, player.cardInhand)) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (chowcard2 == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, chowcard2, chowcard2, chowcard2, 0)); + player.cardInhand.add(chowcard2); + player.cardInhand.add(chowcard2); + break; + } + } + for (int i = 0; i < player.tiGroup.size(); i++) { + if (chowcard2 == player.tiGroup.get(i)[0]) { + player.tiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_TI, chowcard2, chowcard2, chowcard2, 0)); +// player.cardInhand.add(chowcard2); +// player.cardInhand.add(chowcard2); +// player.cardInhand.add(chowcard2); + + int[] kanGroup = new int[3]; + kanGroup[0] = chowcard2; + kanGroup[1] = chowcard2; + kanGroup[2] = chowcard2; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, chowcard2, chowcard2, chowcard2, Paixing.caclHuxi(RuleWeight.TYPE_KAN, chowcard2), true, RuleWeight.HAO_NONE, 0)); + + + haoCard = chowcard2; + haoType = RuleWeight.HAO_NUI; + break; + } + } + } + else { + CardUtil.removeCard(player.cardInhand, chowcard2, 1); + } + + if (bi) { + if (!Util.checkCard(card, player.cardInhand)) { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (card == player.kanGroup.get(i)[0]) { + player.kanGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, card, card, card, 0)); + player.cardInhand.add(card); + player.cardInhand.add(card); + break; + } + } + for (int i = 0; i < player.tiGroup.size(); i++) { + if (card == player.tiGroup.get(i)[0]) { + player.tiGroup.remove(i); + CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_TI, card, card, card, 0)); +// player.cardInhand.add(card); +// player.cardInhand.add(card); +// player.cardInhand.add(card); + + int[] kanGroup = new int[3]; + kanGroup[0] = card; + kanGroup[1] = card; + kanGroup[2] = card; + + player.kanGroup.add(kanGroup); + player.opCardList.add(new OpCard(RuleWeight.TYPE_KAN, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_KAN, card), true, RuleWeight.HAO_NONE, 0)); + + + + + break; + } + } + } + else { + CardUtil.removeCard(player.cardInhand, card, 1); + } + } + else { + if (haoCard == 0) + { + for (int i = 0; i < player.kanGroup.size(); i++) { + if (card == player.kanGroup.get(i)[0]) { + haoCard = card; + haoType = RuleWeight.HAO_WAI; + player.notPutSet.add(card); + break; + } + } + } + + if (haoCard == 0) + { + for (int i = 0; i < player.pongGroup.size(); i++) { + if (card == player.pongGroup.get(i)[0]) { + haoCard = card; + haoType = RuleWeight.HAO_WAI; + break; + } + } + } + + if (haoCard == 0) + { + for (int i = 0; i < player.weiGroup.size(); i++) { + if (card == player.weiGroup.get(i)[0]) { + if (player.playerid == activePlayer.playerid) + { + haoCard = card; + haoType = RuleWeight.HAO_NUI; + } + else if (player.playerid != activePlayer.playerid) + { + haoCard = card; + haoType = RuleWeight.HAO_WAI; + } + break; + } + } + } + + if (haoCard == 0) + { + int handNum = CardUtil.cardNum(card, player.cardInhand); + for (int i = 0; i < player.chowGroup.size(); i++) { + if (card == player.chowGroup.get(i)[0]) { + handNum++; + } + if (card == player.chowGroup.get(i)[2]) { + handNum++; + } + } + + //算出吃到的 + int chiNum = 1; //本次算一次 + for (int i = 0; i < player.chowGroup.size(); i++) { + if (card == player.chowGroup.get(i)[1]) { + chiNum++; + } + } + + //加上本次,相当于吃了4张一样的 + if (handNum == 0 && chiNum == 4) + { + haoCard = card; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 1 && chiNum == 3) { + haoCard = card; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 2 && chiNum == 2) + { + haoCard = card; + haoType = RuleWeight.HAO_WAI; + } + } + } + + + + player.chowGroup.add(chiGroup); + int huXi = 0; + if (chiGroup[0] % 100 != chiGroup[1] % 100) { + if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + //if (chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 6 || chiGroup[0] % 100 + chiGroup[1] % 100 + chiGroup[2] % 100 == 19) { + huXi += Paixing.caclHuxi(RuleWeight.TYPE_CHOW, chiGroup[0]); + } + } + + if (haoCard == 0) + { + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi)); + } + else + { + player.opCardList.add(new OpCard(RuleWeight.TYPE_CHOW, chiGroup[0], chiGroup[1], chiGroup[2], huXi, false, haoType, haoCard)); + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(chiGroup[0]); + opcard.addInt(chiGroup[2]); + EXMainServer.gameCtr.actionCard(player, card, card, bi ? RuleWeight.TYPE_BI : RuleWeight.TYPE_CHOW, activePlayer.seat, opcard); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java new file mode 100644 index 0000000..e55ad99 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRChiState.java @@ -0,0 +1,122 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.room.state.EXRoomSetpState; + +import java.util.concurrent.TimeUnit; + +//对手打吃 +public class PRChiState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + owner.isDiHu = false; + owner.handleDeadPut(); + logger.info("jefe PRChiState: enter" ); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + logger.info("jefe PRChiState: allpass " +owner.getRoom().isAllPass); + //if (!owner.getRoom().isAllPass) { + logger.info("jefe PRChiState:" +owner.getRoom().tipMap.size()); + logger.info("jefe PRChiState:" +owner.tiGroup.size()); + logger.info("jefe guoliu:" + owner.isGuoliu); + + boolean flags = false; + for (int i = 0; i < owner.weiGroup.size(); i++) { + for (int j = 0; j < owner.cardInhand.size(); j++) { + //logger.info("jefe PRPongState:"+owner.cardInhand.get(j) ); + if (owner.cardInhand.get(j) == owner.weiGroup.get(i)[0]) { + flags = true; + } + } + } + //判断是否能溜 + if (owner.tiGroup.size()>0&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + owner.isGuoliu = true; + } + + //判断是否可以溜 + if(flags&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + + + + //} + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + + public int duplicate(Integer[] numbers) { + Integer[] res = new Integer[numbers.length]; + for (int i=0;i { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + Tip actionTip = owner.actionTip; + int eventCard = actionTip.card; + logger.info("jefe PRDealLiuState :" + eventCard); + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (eventCard == owner.kanGroup.get(i)[0]) { + owner.winCard = owner.drawCard; + owner.drawCard = 0; + owner.kongCount++; + owner.kanGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0)); + + int[] tiGroup = new int[4]; + tiGroup[0] = eventCard; + tiGroup[1] = eventCard; + tiGroup[2] = eventCard; + tiGroup[3] = eventCard; + + owner.liuGroup.add(tiGroup); + + //内毫 + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, Paixing.caclHuxi(RuleWeight.TYPE_TI, eventCard), false, RuleWeight.HAO_NUI, eventCard)); + + break; + } + } + + for (int i = 0; i < owner.tiGroup.size(); i++) { + if (eventCard == owner.tiGroup.get(i)[0]) { + owner.kongCount++; + owner.tiGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, 0)); + + int[] tiGroup = new int[4]; + tiGroup[0] = eventCard; + tiGroup[1] = eventCard; + tiGroup[2] = eventCard; + tiGroup[3] = eventCard; + + owner.liuGroup.add(tiGroup); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, Paixing.caclHuxi(RuleWeight.TYPE_TI, eventCard), false, RuleWeight.HAO_QING, eventCard)); + + break; + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + + EXMainServer.gameCtr.actionCard(owner, eventCard, eventCard, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + owner.handleDeadPut(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.getRoom().isTianHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + timer(owner); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java new file mode 100644 index 0000000..2e3a5b4 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDiscardPaoState.java @@ -0,0 +1,98 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.Paixing; + + +public class PRDiscardPaoState extends StateBase { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + owner.isDiHu = false; + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + + int fromseat = activePlayer.seat; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + room.activeCard = 0; + room.lastDiscardSeat = 0; + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java new file mode 100644 index 0000000..8a5c933 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawChiState.java @@ -0,0 +1,84 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; + +import com.taurus.core.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawTipState; + +public class PRDrawChiState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + owner.biCard = 0; + owner.isTingHu = false; + owner.isDiHu = false; + owner.handleDeadPut(); + logger.info("jefe PRDrawChiState: enter" ); + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + logger.info("jefe PRDrawChiState"); + boolean flags = false; + for (int i = 0; i < owner.weiGroup.size(); i++) { + for (int j = 0; j < owner.cardInhand.size(); j++) { + //logger.info("jefe PRPongState:"+owner.cardInhand.get(j) ); + if (owner.cardInhand.get(j) == owner.weiGroup.get(i)[0]) { + flags = true; + } + } + } + //判断是否能溜 + if (owner.tiGroup.size()>0&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + owner.isGuoliu = true; + } + + //判断是否可以溜 + if(flags&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public int duplicate(Integer[] numbers) { + Integer[] res = new Integer[numbers.length]; + for (int i=0;i { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + owner.isDiHu = false; + EXRoom room = owner.getRoom(); + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + if (owner.seat != activePlayer.seat) { + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + } + + int fromseat = activePlayer.seat; + + int card = owner.opCard.getInt(0); + int[] paoGroup = new int[4]; + paoGroup[0] = card; + paoGroup[1] = card; + paoGroup[2] = card; + paoGroup[3] = card; + + owner.paoGroup.add(paoGroup); + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PAO, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PAO, card))); + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PAO, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + int count = owner.tiCount + owner.kongCount; + if (count == 1) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else if (count == 2) { + if (owner.tiCount == 2) { + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } else { + timer(owner); + } + } else { + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 2, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java new file mode 100644 index 0000000..4182e47 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRDrawPongState.java @@ -0,0 +1,159 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRDrawPongState extends StateBase { + + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + logger.info("jefe PRDrawPongState: enter" ); + EXRoom room = (EXRoom) owner.room; + owner.isDiHu = false; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = activePlayer.drawCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + activePlayer.drawCard = 0; + int haoCard = 0; + if (CardUtil.cardNum(card, owner.cardInhand) >= 2) { + CardUtil.removeCard(owner.cardInhand, card, 2); + for (int i = 0; i < owner.chowGroup.size(); i++) { + //if (owner.chowGroup.get(i)[0] == card || owner.chowGroup.get(i)[1] == card || owner.chowGroup.get(i)[2] == card) + if ( owner.chowGroup.get(i)[1] == card ) + { + haoCard = card; + break; + } + } + } + else + { + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (card == owner.kanGroup.get(i)[0]) { + owner.kanGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_KAN, card, card, card, 0)); + owner.cardInhand.add(card); + owner.notPutSet.add(card); + haoCard = card; + break; + } + } + } + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + if (haoCard == 0) + { + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + } + else + { + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card), false, RuleWeight.HAO_WAI, haoCard)); + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + owner.handleDeadPut(); + } + + @Override + public void toNextState(EXPlayer owner) { + //if (!owner.getRoom().isAllPass) { + logger.info("jefe PRDrawPongState:" ); + if (owner.tiGroup.size()>0&&owner.isGuoliu==false) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + + boolean flags = false; + for (int i = 0; i < owner.weiGroup.size(); i++) { + for (int j = 0; j < owner.cardInhand.size(); j++) { + //logger.info("jefe PRPongState:"+owner.cardInhand.get(j) ); + if (owner.cardInhand.get(j) == owner.weiGroup.get(i)[0]) { + flags = true; + } + } + } + //判断是否可以溜 + if(flags&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + //} + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + public int duplicate(Integer[] numbers) { + Integer[] res = new Integer[numbers.length]; + for (int i=0;i { + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + int eventCard = owner.drawCard; + Map cardMap = CardUtil.getCardNumMap(owner.cardInhand); + for (Map.Entry entry : cardMap.entrySet()) { + // 如果抓的牌 手中刚好有三张 + int card = entry.getKey(); + int num = entry.getValue(); + if (card == owner.drawCard && num == 3) { + owner.winCard = owner.drawCard; + owner.drawCard = 0; + owner.kongCount++; + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + opcard.addInt(card); + CardUtil.removeCard(owner.cardInhand, card, num); + + int[] tiGroup = new int[4]; + tiGroup[0] = card; + tiGroup[1] = card; + tiGroup[2] = card; + tiGroup[3] = card; + + owner.liuGroup.add(tiGroup); + + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card))); + + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (eventCard == owner.weiGroup.get(i)[0]) { + owner.winCard = owner.drawCard; + owner.drawCard = 0; + owner.kongCount++; + owner.weiGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + + int[] tiGroup = new int[4]; + tiGroup[0] = eventCard; + tiGroup[1] = eventCard; + tiGroup[2] = eventCard; + tiGroup[3] = eventCard; + + owner.liuGroup.add(tiGroup); + + //内毫 + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, Paixing.caclHuxi(RuleWeight.TYPE_TI, eventCard), false, RuleWeight.HAO_NUI, eventCard)); + + break; + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + + EXMainServer.gameCtr.actionCard(owner, eventCard, eventCard, RuleWeight.TYPE_TI, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + owner.handleDeadPut(); + } + + @Override + public void toNextState(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + timer(owner); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java new file mode 100644 index 0000000..da70820 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRPongState.java @@ -0,0 +1,140 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import extend.zp.*; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.player.state.EXPlayerDrawTipState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRPongState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXRoom room = (EXRoom) owner.room; + EXPlayer activePlayer = (EXPlayer) room.playerMapBySeat.get(owner.room.activeSeat); + activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + int fromseat = activePlayer.seat; + owner.isDiHu = false; + EXMainServer.gameCtr.changeActiveSeat(room, owner.seat); + + int[] pongGroup = new int[3]; + int card = room.activeCard; + pongGroup[0] = card; + pongGroup[1] = card; + pongGroup[2] = card; + + int haoCard = 0; + if (CardUtil.cardNum(card, owner.cardInhand) >= 2) { + CardUtil.removeCard(owner.cardInhand, card, 2); + for (int i = 0; i < owner.chowGroup.size(); i++) { + //if (owner.chowGroup.get(i)[0] == card || owner.chowGroup.get(i)[1] == card || owner.chowGroup.get(i)[2] == card) + if ( owner.chowGroup.get(i)[1] == card ) + { + haoCard = card; + break; + } + } + } + else + { + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (card == owner.kanGroup.get(i)[0]) { + owner.kanGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_KAN, card, card, card, 0)); + owner.cardInhand.add(card); + owner.notPutSet.add(card); + haoCard = card; + break; + } + } + } + room.activeCard = 0; + room.lastDiscardSeat = 0; + + owner.pongGroup.add(pongGroup); + owner.isTingHu = false; + if (haoCard == 0) + { + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card))); + } + else + { + owner.opCardList.add(new OpCard(RuleWeight.TYPE_PONG, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_PONG, card), false, RuleWeight.HAO_WAI, haoCard)); + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, RuleWeight.TYPE_PONG, fromseat, opcard); + logger.info("jefe PRPongState: enter" ); + owner.handleDeadPut(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + //if (!owner.getRoom().isAllPass) { + //logger.info("jefe PRPongState:"+owner.tiGroup.size()+" isguoliu:"+owner.isGuoliu ); + // logger.info("jefe PRPongState:"+owner.weiGroup.size()+" isguoliu:"+owner.kanGroup.size()+"liuGroup:"); + //logger.info("jefe PRPongState:"+owner.weiGroup.get(0)[0]+" isguoliu:"+owner.kanGroup.get(0)[0]+"wei:" +owner.weiGroup.get(1)[0]); + boolean flags = false; + for (int i = 0; i < owner.weiGroup.size(); i++) { + for (int j = 0; j < owner.cardInhand.size(); j++) { + //logger.info("jefe PRPongState:"+owner.cardInhand.get(j) ); + if (owner.cardInhand.get(j) == owner.weiGroup.get(i)[0]) { + flags = true; + } + } + } + + if (owner.tiGroup.size()>0&&owner.isGuoliu==false) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + //判断是否可以溜 + if(flags&&owner.isGuoliu==false){ + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.WAI_LIU_RULE, owner); + owner.isGuoliu = true; + } + + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + //} + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiLiuState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiLiuState.java new file mode 100644 index 0000000..eefc5a6 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiLiuState.java @@ -0,0 +1,127 @@ +package extend.zp.player.rulestate; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.PlayerRuleManager; +import extend.zp.RuleWeight; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class PRWeiLiuState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + owner.kongCount++; + owner.isDiHu = false; + int eventCard = owner.drawCard;//jefe wincard + + logger.info("jefe weiliustate :" + eventCard); + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (eventCard == owner.weiGroup.get(i)[0] && CardUtil.cardNum(eventCard, owner.cardInhand) == 1) { + // if ( CardUtil.cardNum(eventCard, owner.cardInhand) == 1) { + owner.weiGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + CardUtil.removeCard(owner.cardInhand, eventCard, 1); + + int[] tiGroup = new int[4]; + tiGroup[0] = eventCard; + tiGroup[1] = eventCard; + tiGroup[2] = eventCard; + tiGroup[3] = eventCard; + + owner.liuGroup.add(tiGroup); + + //内毫 + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, Paixing.caclHuxi(RuleWeight.TYPE_TI, eventCard), false, RuleWeight.HAO_NUI, eventCard)); + break; + }else { + + for (int j = 0; j < owner.cardInhand.size(); j++) { + if (owner.cardInhand.get(j) == owner.weiGroup.get(i)[0]) { + eventCard = owner.cardInhand.get(j); + owner.weiGroup.remove(i); + CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0)); + CardUtil.removeCard(owner.cardInhand, eventCard, 1); + + int[] tiGroup = new int[4]; + tiGroup[0] = eventCard; + tiGroup[1] = eventCard; + tiGroup[2] = eventCard; + tiGroup[3] = eventCard; + + owner.liuGroup.add(tiGroup); + + //内毫 + owner.opCardList.add(new OpCard(RuleWeight.TYPE_TI, eventCard, eventCard, eventCard, Paixing.caclHuxi(RuleWeight.TYPE_TI, eventCard), false, RuleWeight.HAO_NUI, eventCard)); + break; + } + } + } + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + opcard.addInt(eventCard); + + EXMainServer.gameCtr.actionCard(owner, eventCard, eventCard, RuleWeight.TYPE_TI, owner.seat, opcard); + + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner); + owner.handleDeadPut(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + + timer(owner); + } + + public static void timer(EXPlayer owner) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java new file mode 100644 index 0000000..eff03ea --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWeiState.java @@ -0,0 +1,128 @@ +package extend.zp.player.rulestate; + +import com.game.Global; +import com.game.state.StateBase; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import extend.zp.*; +import extend.zp.player.state.EXPlayerDiscardState; +import extend.zp.uitl.Paixing; + +import java.util.concurrent.TimeUnit; + +/** + * ��Ӧ���ƴ���״̬ + * + * + * + * 2017��8��30�� PRPongState.java + */ +public class PRWeiState extends StateBase { + + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + owner.isDiHu = false; + logger.info("jefe weistate :" +owner.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI)); + if (owner.getRoom().config.getInt(Config.ROOM_CONFIG_KA_WAI) != 0) + { + handleWai(owner); + } + else { + //handleWai(owner); + timer(owner, this); + } + } + + public static void timer(EXPlayer owner, PRWeiState state) { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + state.handleWai(owner); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + + public void handleWai(EXPlayer owner) + { + int card = owner.opCard.getInt(0); + int kan = owner.opCard.getInt(2); + int[] weiGroup = new int[3]; + weiGroup[0] = card; + weiGroup[1] = card; + weiGroup[2] = card; + + owner.weiGroup.add(weiGroup); + + int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI; + if (kan == 0) + { + boolean firstChi = false; + for (int i = 0; i < owner.chowGroup.size(); i++) { + //if (card == owner.chowGroup.get(i)[0] || card == owner.chowGroup.get(i)[1] || card == owner.chowGroup.get(i)[2]) { + if ( card == owner.chowGroup.get(i)[1]) { + firstChi = true; + break; + } + } + //先吃后歪,算外毫 + if (firstChi) + { + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card), false, RuleWeight.HAO_WAI, card)); + } + else + { + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card))); + } + } + else + { + owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card), false, RuleWeight.HAO_NUI, card)); + } + + ITArray opcard = TArray.newInstance(); + opcard.addInt(card); + opcard.addInt(card); + + EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard); + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.WAI_LIU_RULE, owner); + + owner.handleDeadPut(); + } + + @Override + public void toNextState(EXPlayer owner) { + owner.isTingHu = false; + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java new file mode 100644 index 0000000..7050ece --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/rulestate/PRWinState.java @@ -0,0 +1,38 @@ +package extend.zp.player.rulestate; + +import com.game.state.StateBase; + +import extend.zp.EXPlayer; +import extend.zp.EXRoom; + + +public class PRWinState extends StateBase { + @Override + public void enter(EXPlayer owner) { + EXRoom room = owner.getRoom(); + if (!room.isplaying) { + owner.stateMachine.curState = owner.stateMachine.lastState; + return; + } + EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat); + room.win(owner, activePlayer); + } + + @Override + public void toNextState(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java new file mode 100644 index 0000000..1f6c831 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDisCardTipState.java @@ -0,0 +1,52 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.tip.Tip; + + +public class EXPlayerDisCardTipState extends EXPlayerTipState { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.choicAction(id,biid); + + // Global.logger.error("EXPlayerDisCardTipState" + id); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)){ + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + //if (tip.type == RuleWeight.TYPE_WIN) { + // id = tip.id; + // break; + //} + } + owner.tipMgr.choicAction(id,null); + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java new file mode 100644 index 0000000..4ff1c20 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDiscardState.java @@ -0,0 +1,222 @@ +package extend.zp.player.state; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.Router; +import com.game.Util; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.Config; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.room.state.EXRoomSetpState; + + +public class EXPlayerDiscardState extends StateBase { + + Logger logger = Logger.getLogger(getClass()); + + @Override + public void enter(EXPlayer owner) { + + for (Map.Entry entry : owner.room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + player.notChiSet.clear(); + } + + owner.getRoom().tipMap.clear(); + logger.info("jefe EXPlayerDiscardState:" +owner.cardInhand); + owner.isGuoliu = false; + if (owner.cardInhand.isEmpty()) { + + owner.isLaoYe = true; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + + } else { + boolean flag = true; + for(int card : owner.cardInhand) + { + if (!owner.notPutSet.contains(card)) + { + flag = false; + break; + } + } + + if (flag) + { + + if (owner.kanGroup.size() > 0 || owner.tiGroup.size() > 0) + { + flag = false; + } + } + + if (flag) + { + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + else + { + EXMainServer.gameCtr.discardTipEvent(owner); + owner.startActionTimer(); + } + } + } + + @Override + public void toNextState(EXPlayer owner) { + logger.info("jefe EXPlayerDiscardState toNextState:" +owner.isGuoliu); + owner.isGuoliu = false; + + timer(owner); + } + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + switch (cmd) { + case EXActionEvent.EVENT_DISCARD: + ITObject netParam = (ITObject) param; + int discard = netParam.getInt("card"); + discard(owner, discard); + break; + case ActionEvent.EVENT_ENTRUST: + owner.startActionTimer(); + break; + case ActionEvent.EVENT_TIMER_AUTO: + discard(owner, owner.autoDiscard()); + break; + default: + break; + } + } + + private void discard(EXPlayer owner, int discard) { + + if (!Util.checkCard(discard, owner.cardInhand)) { + boolean flag = false; + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (discard == owner.kanGroup.get(i)[0]) { + flag = true; + break; + } + } + for (int i = 0; i < owner.tiGroup.size(); i++) { + if (discard == owner.tiGroup.get(i)[0]) { + flag = true; + break; + } + } + if (!flag) + { + ITObject param = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + } + logger.info("discard,player:" + owner + ",card:" + discard); + if (owner.seat == owner.room.bankerSeat) { + + if (owner.outcardExList.size() > 0) { + owner.isTingHu = false; + } + } else { + owner.isTingHu = false; + } + + if (owner.notPutSet.contains(discard)) { + ITObject param = new TObject(); + owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, param); + return; + } + + owner.outcardExList.add(discard); + exit(owner); + EXMainServer.gameCtr.outCard(owner, discard); + + owner.getRoom().isDiHu = false; + + if (owner.getRoom().tipMap.size() != 0) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } else { + + if (owner.getRoom().activeCard != 0) { + this.toNextState(owner); + } + } + } + + public static void timer(EXPlayer owner) { + Global.logger.info("timer"+owner.getRoom().isAllPass); + if (owner.getRoom().isAllPass) { + + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + owner.outcardList.add(owner.getRoom().activeCard); + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + + } else { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + + if (owner.room.isDestroy) + return; + + owner.room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + + ITObject resData = new TObject(); + resData.putInt("card", owner.getRoom().activeCard); + resData.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, resData); + + owner.outcardList.add(owner.getRoom().activeCard); + + owner.getRoom().throwCardsSet.add(owner.getRoom().activeCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.getRoom().activeCard); + + owner.getRoom().activeCard = 0; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java new file mode 100644 index 0000000..fa8169f --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawState.java @@ -0,0 +1,438 @@ +package extend.zp.player.state; + +import java.util.ArrayList; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; + +import extend.zp.*; +import extend.zp.room.state.EXRoomSetpState; +import extend.zp.uitl.CardUtil; +import extend.zp.uitl.Paixing; + + +public class EXPlayerDrawState extends StateBase { + Logger logger = Logger.getLogger(getClass()); + @Override + public void enter(EXPlayer owner) { + owner.notChiSet.clear(); + + EXRoom room = owner.getRoom(); + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + room.isAllPass = false; + owner.getRoom().tipMap.clear(); + if (owner.seat == room.adminSeat) { + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.popsub(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (!player.is_white) { + if (Paixing.checkWin((EXPlayer) player, drawCard, true)) { + flag = true; + break; + } + } + } + + if (flag) { + if (rand > room.white_value && room.card.cardList.size() != 0 && count++ <= 5) { + tempCardList.add(drawCard); + Global.logger.info("no white:" + owner.playerid + " to hu:" + drawCard); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else + { + owner.drawCard = room.card.popsub(); + } + } else { + if (room.while_list) + { + double rand = Math.random() % 100 * 100; + if (rand > room.white_value) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.is_white) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + else { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = false; + } + } + } + } + + if (owner.is_white) { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + } + else { + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = false; + } + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else + { + if(owner.black_white_status == 2) { + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (!flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else if(owner.black_white_status == 1) { + double rand = Math.random() % 100 * 100; + if (rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + if (IsGoodCard((EXPlayer) owner, drawCard)) { + flag = true; + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + //Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + else { + boolean black_flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + black_flag = true; + } + } + } + + double rand = Math.random() % 100 * 100; + if (black_flag && rand <= owner.black_white_rate) + { + ArrayList tempCardList = new ArrayList(); + int count = 0; + do { + int drawCard = room.card.pop(); + + boolean flag = false; + for (Map.Entry entry : room.playerMapBySeat.entrySet()) { + Player player = entry.getValue(); + + if (player.playerid != owner.playerid) { + if (player.black_white_status == 1) + { + if (IsGoodCard2((EXPlayer) player, drawCard)) { + flag = true; + break; + } + } + } + } + + if (flag) { + if (room.card.cardList.size() > 0 && count++ <= room.card.cardList.size()) { + tempCardList.add(drawCard); + Global.logger.info("not good card:" + drawCard + " for white player"); + continue; + } + } + + owner.drawCard = drawCard; + break; + } + while(true); + room.card.cardList.addAll(tempCardList); + } + else { + owner.drawCard = room.card.pop(); + } + } + } + } + + room.step++; + int tempStep = room.step; + // if (owner.seat == 2) { + // owner.drawCard = 102; + // } + logger.info("drawCard,player:" + owner + ",card:" + owner.drawCard); + room.drawCard = owner.drawCard; + + int leftCount = room.card.getCount(); + ((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + int card = owner.drawCard; + /* + for (int i = 0; i < owner.kanGroup.size(); i++) { + if (owner.drawCard == owner.kanGroup.get(i)[0]) { + card = 0; + break; + } + } + for (int i = 0; i < owner.weiGroup.size(); i++) { + if (owner.drawCard == owner.weiGroup.get(i)[0]) { + card = 0; + break; + } + } + if (CardUtil.cardNum(owner.drawCard, owner.cardInhand) >= 2) { + card = 0; + } + */ + + ITObject otherParam = new TObject(); + otherParam.putInt("card", card); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.TI_RULE, owner); + if (owner.drawCard != 0 && tempStep == room.step) { + this.toNextState(owner); + } + } + + private boolean IsGoodCard(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard, true)) { + return true; + } + + for (int i = 0; i < player.kanGroup.size(); i++) { + if (drawCard == player.kanGroup.get(i)[0]) { + return true; + } + } + + for (int i = 0; i < player.weiGroup.size(); i++) { + if (drawCard == player.weiGroup.get(i)[0]) { + return true; + } + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + private boolean IsGoodCard2(EXPlayer player, int drawCard) { + if (Paixing.checkWin((EXPlayer) player, drawCard, true)) { + return true; + } + + if (CardUtil.cardNum(drawCard, player.cardInhand) >= 2) + { + return true; + } + + return false; + } + + @Override + public void toNextState(EXPlayer owner) { + if (!owner.getRoom().isAllPass) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_RULE, owner); + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DRAW, null); + if (owner.getRoom().tipMap.size() != 0) { + for (Map.Entry entry : owner.getRoom().playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.isDiHu) + { + if (owner.getRoom().tipMap.containsKey(player.playerid)) + { + if (player.tipMgr.getTip(RuleWeight.TYPE_WIN) == null) + { + player.isDiHu = false; + } + } + else { + player.isDiHu = false; + } + } + } + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + int tempStep = owner.getRoom().step; + for (Map.Entry entry : owner.getRoom().playerMapBySeat.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player != null) + { + player.isDiHu = false; + } + } + + //EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + //owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_PAO, null); + + if (owner.drawCard != 0 && tempStep == owner.getRoom().step) { + + timer(owner); + } + } + + public static void timer(EXPlayer owner) { + if (owner.getRoom().card.getCount() == 0) { + owner.getRoom().liuju = true; + owner.getRoom().liujuNum++; + owner.getRoom().endGame(); + return; + } + if (owner.getRoom().isAllPass) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } else { + TPServer.me().getTimerPool().schedule(new Runnable() { + @Override + public void run() { + if (owner.room == null) { + Global.logger.error("EXPlayerDrawState room is null"); + return; + } + if (owner.room.isDestroy) + return; + owner.room.enqueueRunnable(new Runnable() { + @Override + public void run() { + if(owner.drawCard != 0) { + ITObject param = new TObject(); + param.putInt("card", owner.drawCard); + param.putInt("seat", owner.seat); + owner.room.broadCastToClient(0, Config.GAME_EVT_THROW_CARD, param); + owner.outcardList.add(owner.drawCard); + owner.getRoom().throwCardsSet.add(owner.drawCard); + owner.getRoom().getPlayBack().addThrowCardCommand(owner.seat, owner.drawCard); + + owner.drawCard = 0; + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class)); + } + } + }); + } + }, 1, TimeUnit.SECONDS); + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java new file mode 100644 index 0000000..645bf75 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerDrawTipState.java @@ -0,0 +1,51 @@ +package extend.zp.player.state; + +import java.util.Map.Entry; + +import com.game.ActionEvent; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; + +import extend.zp.EXActionEvent; +import extend.zp.EXPlayer; +import extend.zp.tip.Tip; + + +public class EXPlayerDrawTipState extends EXPlayerTipState { + public void enter(EXPlayer owner) { + super.enter(owner); + owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr); + } + + @Override + public void exit(EXPlayer owner) { + // TODO Auto-generated method stub + super.exit(owner); + owner.getRoom().tipMap.remove(owner.playerid); + } + + public void reload(EXPlayer owner) { + this.enter(owner); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_ACTION)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null; + owner.tipMgr.doAction(id,biid); + }else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) { + int id = owner.tipMgr.getUid(); + for (Entry entry : owner.tipMgr.tipMap.entrySet()) { + Tip tip = entry.getValue(); + //if (tip.type == RuleWeight.TYPE_WIN) { + // id = tip.id; + // break; + //} + } + owner.tipMgr.doAction(id,null); + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPiaoNiaoTipState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPiaoNiaoTipState.java new file mode 100644 index 0000000..2a71329 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPiaoNiaoTipState.java @@ -0,0 +1,62 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.Global; +import com.game.player.state.PlayerWaitState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public class EXPlayerPiaoNiaoTipState extends StateBase{ + + @Override + public void enter(EXPlayer owner) { + if(!owner.isEntrust()) { + EXMainServer.gameCtr.piaoTipEvent(owner,0); + } + owner.startActionTimer(); + } + + /** + * 重连 + * @param owner + */ + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.piaoTipEvent(owner,1); + owner.startActionTimer(); + } + + + @Override + public void exit(EXPlayer owner) { + owner.stopActionTimer(); + } + + private void _action(EXPlayer owner,int id,int gid) { + owner.piao = id; + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().piaoCount --; + EXMainServer.gameCtr.piaoEvent(owner); + owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_PIAO, gid, null); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + super.execute(owner, cmd, gid, param); + if (cmd.equals(EXActionEvent.EVENT_PIAO)) { + ITObject netParam = (ITObject) param; + int id = netParam.getInt("id"); + _action(owner, id, gid); + }else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) { + _action(owner,0,gid); + } + else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) { + owner.startActionTimer(); + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java new file mode 100644 index 0000000..5fb1074 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerPreDrawState.java @@ -0,0 +1,130 @@ +package extend.zp.player.state; + +import java.util.Collections; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; + +import extend.zp.*; + + +public class EXPlayerPreDrawState extends StateBase { + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + room.isAllPass = false; + + + //owner.drawCard = room.card.pop(); + + //room.drawCard = owner.drawCard; + + //发消息给自己,并记录玩家抓牌的日志 + int leftCount = room.card.getCount(); + //((EXGameController) Global.gameCtr).getCard(owner, leftCount); + + //通知所有其他的玩家 + ITObject otherParam = new TObject(); + otherParam.putInt("card", owner.drawCard); + otherParam.putInt("seat", owner.room.activeSeat); + otherParam.putInt("left_count", leftCount); + //jefe + for (Entry entry : room.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + //owner.room.broadCastToClient(player.playerid, Config.GAME_EVT_DRAW, otherParam); + //player.sendEvent(Config.GAME_EVT_DRAW, otherParam); + if (player.room.bankerSeat==player.seat){ + //owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_ACTION, otherParam); + } + player.sendEvent(Config.GAME_EVT_DRAW, otherParam); + } + //owner.room.broadCastToClient(owner.playerid, Config.GAME_EVT_DRAW, otherParam); + + + //启动定时器 + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + + if (!owner.getRoom().isAllPass) { + //根据规则判定自己能不能胡 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_LIU_RULE, owner); + //看看其他玩家能不能胡 + owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_DEAL, null); + + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + owner.getRoom().isTianHu = false; + + //判断玩家抓牌之后可以进行的操作 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + + //判断玩家是否有坎的操作 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.KAN_RULE, owner); + + int drawCard = owner.drawCard; + owner.drawCard = 0; + + if (drawCard != 0) { + + owner.cardInhand.add(drawCard); + Collections.sort(owner.cardInhand); + + ITObject param = new TObject(); + param.putInt("card", drawCard); + param.putInt("seat", owner.room.activeSeat); + owner.room.broadCastToClient(0, Config.GAME_EVT_ADD_CARD, param); + + owner.getRoom().getPlayBack().addAddCardCommand(owner.room.activeSeat, drawCard); + } + + owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class)); + } + + public static void timer(EXPlayer owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + + if (owner.room.isDestroy) + return; + + owner.room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, owner); + + owner.stateMachine.toNextState(); + } + }); + } + }, 1500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTianHuState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTianHuState.java new file mode 100644 index 0000000..8eaca7a --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTianHuState.java @@ -0,0 +1,76 @@ +package extend.zp.player.state; + +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.player.state.PlayerPauseState; +import com.game.state.StateBase; +import com.taurus.permanent.TPServer; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayerRuleManager; + + +public class EXPlayerTianHuState extends StateBase { + @Override + public void enter(EXPlayer owner) { + + EXRoom room = owner.getRoom(); + + room.isAllPass = false; + + //启动定时器 + timer(owner); + } + + @Override + public void toNextState(EXPlayer owner) { + + if (!owner.getRoom().isAllPass) { + + //根据规则判定自己能不能胡 + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.HU_RULE, owner); + + // 如果有玩家能胡 + if (owner.getRoom().tipMap.size() != 0) { + + if (!(owner.stateMachine.curState instanceof EXPlayerDrawTipState)) { + owner.stateMachine.changeState(Global.getState(PlayerPauseState.class)); + } + return; + } + } + + owner.getRoom().isTianHu = false; + + owner.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + public static void timer(EXPlayer owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner.room == null) { + Global.logger.error("EXPlayerDiscardState room is null"); + return; + } + + if (owner.room.isDestroy) + return; + + owner.room.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 500, TimeUnit.MILLISECONDS); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java new file mode 100644 index 0000000..af786e1 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerTipState.java @@ -0,0 +1,40 @@ +package extend.zp.player.state; + +import com.game.ActionEvent; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; + + +public abstract class EXPlayerTipState extends StateBase { + @Override + public void enter(EXPlayer owner) { + // TODO Auto-generated method stub + EXMainServer.gameCtr.tipEvent(owner); + owner.startActionTimer(); + } + + @SuppressWarnings("unchecked") + @Override + public void toNextState(EXPlayer owner) { + owner.stateMachine.lastState.toNextState(owner); + } + + @Override + public void exit(EXPlayer owner) { + owner.tipMgr.clean(); + owner.stopActionTimer(); + } + + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + if (ActionEvent.EVENT_ENTRUST.equals(cmd)) { + owner.startActionTimer(); + } + } + @Override + public void reload(EXPlayer owner) { + EXMainServer.gameCtr.tipEvent(owner); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java new file mode 100644 index 0000000..55aff7c --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/player/state/EXPlayerWaitState.java @@ -0,0 +1,31 @@ +package extend.zp.player.state; + +import com.game.state.StateBase; + +import extend.zp.EXActionEvent; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.PlayerRuleManager; + +public class EXPlayerWaitState extends StateBase { + @Override + public void execute(EXPlayer owner, String cmd, int gid, Object param) { + // TODO Auto-generated method stub + switch (cmd) { + case EXActionEvent.EVENT_OTHER_DISCARD: + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DISCARD_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_DRAW: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_DRAW_RULE, owner); + break; + case EXActionEvent.EVENT_DEAL: + EXMainServer.playerRuleMgr.condition(PlayerRuleManager.OTHER_HU_RULE, owner); + break; + case EXActionEvent.EVENT_OTHER_PAO: + //EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DRAW_PAO_RULE, owner); + break; + default: + break; + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java new file mode 100644 index 0000000..5388dfd --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomDealState.java @@ -0,0 +1,141 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import com.taurus.permanent.TPServer; +import extend.zp.Config; +import extend.zp.EXMainServer; +import extend.zp.EXPlayer; +import extend.zp.EXRoom; +import extend.zp.PlayBack; +import extend.zp.PlayerRuleManager; +import extend.zp.player.state.EXPlayerPreDrawState; + + +public class EXRoomDealState extends StateBase { + + @Override + public void enter(EXRoom owner) { + boolean donghua = false; + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.xi_pai) + { + donghua = true; + break; + } + } + + if (donghua) + { + owner.notifyXiPai(); + //启动定时器 + timer(owner); + } + else { + this.toNextState(owner); + } + } + + public static void timer(EXRoom owner) { + + TPServer.me().getTimerPool().schedule(new Runnable() { + + @Override + public void run() { + + if (owner == null) { + Global.logger.error("room is null"); + return; + } + + if (owner.isDestroy) + return; + + owner.enqueueRunnable(new Runnable() { + + @Override + public void run() { + owner.stateMachine.toNextState(); + } + }); + } + }, 4000, TimeUnit.MILLISECONDS); + } + + @Override + public void toNextState(EXRoom owner) { + //洗牌 + owner.card.init(); + + // 如果没有庄家,确定一个庄家 + if (owner.bankerSeat == 0) { + if (owner.config.getBoolean(Config.ROOM_CONFIG_FIRST_RAND_ZHUANG)) + { + owner.bankerSeat = getBankerSeat(owner); + } + else + { + owner.bankerSeat = 1; + } + } + + //发牌 + EXMainServer.gameCtr.dealCard(owner); + + // 去底牌 + if (owner.maxPlayers == 2 ) { + int qupaiV = owner.config.getInt(Config.ROOM_CONFIG_QUPAI); + if(qupaiV > 0) { + + int num = qupaiV * 5 + 5; + for (int index = 0; index < num; index++) { + owner.throwCardsList.add(owner.card.pop()); + } + } + } + + // 生成游戏记录对象 + owner.playBackData = new PlayBack(owner); + + // 不是庄家的玩家要进行规则判定 + for (Entry entry : owner.playerMapById.entrySet()) { + EXPlayer player = (EXPlayer) entry.getValue(); + if (player.seat != owner.bankerSeat) { + EXMainServer.playerRuleMgr.conditionEx(PlayerRuleManager.DEAL_RULE, player); + } + } + + EXPlayer player = (EXPlayer) owner.playerMapBySeat.get(owner.bankerSeat); + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerPreDrawState.class)); + } + + private int getBankerSeat(EXRoom owner) { + int seat = 0; + + //如果是兩人的情況 + if (owner.maxPlayers == 2) { + // 如果是随机确定庄家 + Random random = new Random(); + seat = random.nextInt(2) + 1; + } + else if (owner.maxPlayers == 3) { + // 如果是随机确定庄家 + Random random = new Random(); + seat = random.nextInt(3) + 1; + } + else if (owner.maxPlayers == 4) { + // 如果是随机确定庄家 + Random random = new Random(); + seat = random.nextInt(4) + 1; + } + return seat; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomPiaoState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomPiaoState.java new file mode 100644 index 0000000..c4e176f --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomPiaoState.java @@ -0,0 +1,30 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; +import extend.zp.EXActionEvent; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerPiaoNiaoTipState; + +import java.util.Map.Entry; + +public class EXRoomPiaoState extends StateBase{ + + @Override + public void enter(EXRoom owner) { + owner.piaoCount = owner.maxPlayers; + for (Entry entry : owner.playerMapById.entrySet()) { + Player player = entry.getValue(); + player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class)); + } + } + + public void execute(EXRoom owner, String cmd, int gid, Object param) { + if(cmd.equals(EXActionEvent.EVENT_PIAO)) { + if(owner.piaoCount==0) { + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + } + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java new file mode 100644 index 0000000..ba45043 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomSetpState.java @@ -0,0 +1,26 @@ +package extend.zp.room.state; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.EXMainServer; +import extend.zp.EXRoom; +import extend.zp.player.state.EXPlayerDrawState; + +public class EXRoomSetpState extends StateBase { + @Override + public void enter(EXRoom owner) { + Player player; + // TODO Auto-generated method stub + if (owner.activeSeat == 0) { + player = owner.playerMapBySeat.get(owner.bankerSeat); + } else { + player = owner.playerMapBySeat.get(owner.activeSeat); + int nextSeat = player.nextSeat; + player = owner.playerMapBySeat.get(nextSeat); + } + EXMainServer.gameCtr.changeActiveSeat(owner, player.seat); + player.stateMachine.changeState(Global.getState(EXPlayerDrawState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java new file mode 100644 index 0000000..d02b1e5 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/room/state/EXRoomStartGameState.java @@ -0,0 +1,41 @@ +package extend.zp.room.state; + +import java.util.Map.Entry; + +import com.game.Global; +import com.game.data.Player; +import com.game.state.StateBase; + +import extend.zp.Config; +import extend.zp.EXRoom; + + +public class EXRoomStartGameState extends StateBase { + + @Override + public void enter(EXRoom owner) { + + for (Entry entry : owner.playerMapById.entrySet()) { + + Player player = entry.getValue(); + player.clear(); + player.initSeat(); + player.ready = false; + } + + owner.startGame(); + + this.toNextState(owner); + } + + @Override + public void toNextState(EXRoom owner) { + if(owner.config.containsKey(Config.ROOM_CONFIG_PIAO) && owner.config.getInt(Config.ROOM_CONFIG_PIAO) != 0) { + owner.stateMachine.changeState(Global.getState(EXRoomPiaoState.class)); + } + else{ + owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } + //owner.stateMachine.changeState(Global.getState(EXRoomDealState.class)); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Action.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Action.java new file mode 100644 index 0000000..f13c301 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Action.java @@ -0,0 +1,20 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + +public class Action { + public Tip tip; + public EXPlayer player; + + public Action(Tip tip, EXPlayer player) { + this.tip = tip; + this.player = player; + + } + + public void run() { + this.player.actionTip = tip; + this.player.initOpCard(tip.opcard); + this.tip.rule.action(this.player); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/IRuleBase.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/IRuleBase.java new file mode 100644 index 0000000..ef77712 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/IRuleBase.java @@ -0,0 +1,14 @@ +package extend.zp.tip; + +import extend.zp.EXPlayer; + + +public interface IRuleBase { + + + public abstract boolean condition(EXPlayer player); + + + public abstract void action(EXPlayer player); + +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Tip.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Tip.java new file mode 100644 index 0000000..c075788 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/Tip.java @@ -0,0 +1,38 @@ +package extend.zp.tip; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + + +public class Tip { + public int id; + public IRuleBase rule; + public int weight; + public int card; + public ITArray opcard; + public int type; + public ITArray bi_list; + public ITArray biid; + + public Tip(int card, ITArray opcard, int weight, IRuleBase rule, int type) { + this.rule = rule; + this.weight = weight; + this.opcard = opcard; + this.card = card; + this.type = type; + } + + public ITObject toMP() { + ITObject tipMp = new TObject(); + tipMp.putInt("id", id); + tipMp.putInt("weight", weight); + tipMp.putInt("type", type); + tipMp.putInt("card", card); + tipMp.putTArray("opcard", opcard); + if(bi_list!=null&&bi_list.size()>0) { + tipMp.putTArray("bi_list", bi_list); + } + return tipMp; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/TipManager.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/TipManager.java new file mode 100644 index 0000000..235c1ee --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/tip/TipManager.java @@ -0,0 +1,218 @@ +package extend.zp.tip; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import com.game.Global; +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 extend.zp.EXPlayer; +import extend.zp.RuleWeight; + + +public class TipManager { + + private int id = 0; + private int uid = 100; + + public HashMap tipMap = null; + public Tip actionTip; + public int weight = 0; + public EXPlayer owner = null; + + public TipManager(EXPlayer owner) { + this.tipMap = new HashMap(); + this.owner = owner; + + } + + public void addTip(Tip tip) { + int id = this.getId(); + this.weight = this.weight | tip.weight; + tip.id = id; + this.tipMap.put(id, tip); + } + + public Tip getTip(int type) + { + for (Entry entry : this.tipMap.entrySet()) + { + Tip tip = entry.getValue(); + if (tip.type == type) + { + return tip; + } + } + return null; + } + + public int getUid(){ + return this.uid; + } + public void choicAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + + Global.logger.info(" =====>Adddd user: "+ this.owner.playerid+" notChiSet = "+this.owner.notChiSet); + this.owner.chouChiSet.addAll(this.owner.notChiSet); + this.owner.chouChiTypeMap.putAll(this.owner.notChiTypeMap); + + Global.logger.info(" =====> user: "+ this.owner.playerid+" chouChiSet = "+this.owner.chouChiSet); + } + if (tip.type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (tip.type == RuleWeight.TYPE_WIN) { + this.owner.isDiHu = false; + } + } + this.owner.notChiSet.clear(); + this.owner.notChiTypeMap.clear(); + this.owner.isMingTang = true; + this.owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass discardtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type == RuleWeight.TYPE_PONG) { + this.owner.chouPongSet.add(tip.card); + } + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } else if (tip.type == RuleWeight.TYPE_PONG) { + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_PONG) { + it.remove(); + } + } + } + + owner.notChiSet.clear(); + owner.notChiTypeMap.clear(); + + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + this.owner.notChiSet.clear(); + this.owner.notChiTypeMap.clear(); + throw new Error("tip map has no id" + id); + } + } + + @SuppressWarnings("unchecked") + public void doAction(int id,ITArray biid) { + if (id == this.uid) { + // ���Գԣ�����ȡ���ˣ���¼���� + Iterator> it = this.tipMap.entrySet().iterator(); + int card = 0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + Tip tip = entry.getValue(); + card = tip.card; + if (tip.type == RuleWeight.TYPE_CHOW) { + this.owner.chouChiSet.add(tip.card); + this.owner.chouChiSet.addAll(this.owner.notChiSet); + this.owner.chouChiTypeMap.putAll(this.owner.notChiTypeMap); + } + } + this.owner.notChiSet.clear(); + this.owner.notChiTypeMap.clear(); + this.owner.isMingTang = true; + this.owner.stateMachine.curState.exit(owner); + this.owner.stateMachine.curState = this.owner.stateMachine.lastState; + this.owner.getRoom().checkAction(); + + Global.logger.info(this.owner + " pass drawtip, id: " + id + " passcard: " + card); + } else if (this.tipMap.containsKey(id)) { + Tip tip = this.tipMap.get(id); + this.tipMap.remove(id); + if (tip.type == RuleWeight.TYPE_CHOW) { + tip.biid = biid; + Iterator> it = this.tipMap.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().type != RuleWeight.TYPE_CHOW && entry.getValue().type != RuleWeight.TYPE_BI) { + it.remove(); + } + } + } + owner.notChiSet.clear(); + owner.notChiTypeMap.clear(); + owner.stateMachine.changeState(Global.getState(PlayerWaitState.class)); + owner.getRoom().addAction(new Action(tip, owner)); + } else { + owner.notChiSet.clear(); + owner.notChiTypeMap.clear(); + throw new Error("tip map has no id" + id); + } + } + + public ITObject toMP() { + ITObject mp = new TObject(); + mp.putInt("weight", this.weight); + mp.putInt("uid", this.uid); + ITArray tipList = new TArray(); + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + ITObject tipMp = tip.toMP(); + tipList.addTObject(tipMp); + } + mp.putTArray("tip_list", tipList); + return mp; + + } + + private int getId() { + this.id += 1; + this.id += uid; + return this.id; + } + + public int getWeightest() { + int result = 0; + for (Entry entry : this.tipMap.entrySet()) { + Tip tip = entry.getValue(); + if (tip.weight > result) { + result = tip.weight; + } + } + return result; + } + + public void cleanTip() { + this.weight = 0; + this.id = 0; + this.uid += 100; + this.tipMap = new HashMap(); + } + + public void clean() { + this.cleanTip(); + } + +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/CardUtil.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/CardUtil.java new file mode 100644 index 0000000..7608fca --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/CardUtil.java @@ -0,0 +1,116 @@ +package extend.zp.uitl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import extend.zp.OpCard; + +public class CardUtil { + static public int cardNum(int eventCard, List cardList) { + int result = 0; + for (Integer card : cardList) { + if (card == eventCard) { + result += 1; + } + } + return result; + } + + static public boolean checkCard(int eventCard,Map cardMap) { + if(cardMap.containsKey(eventCard)&&cardMap.get(eventCard)>=1) { + return true; + } + return false; + } + + static public void addCard(int eventCard,Map cardMap,int add) { + if(cardMap.containsKey(eventCard)) { + int num = cardMap.get(eventCard); + cardMap.put(eventCard, num+add); + }else if(add >0){ + cardMap.put(eventCard, add); + } + } + + static public int cardType(int card) { + return card / 100; + } + + static public boolean isRedCard(int card) { + return card % 100 == 2 || card % 100 == 7 || card % 100 == 10; + } + + static public Map getCardNumMap(List cardList) { + Map result = new HashMap(); + 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; + } + + static public void removeCard(List cardList, int card, int count) { + int curCount = 0; + for (int i = 0; i < cardList.size(); i++) { + if (count == curCount) { + return; + } + if (cardList.get(i) == card) { + + cardList.remove(i); + i--; + curCount++; + } + } + } + + static public void removeGroup(List group, int card) { + for (int i = 0; i < group.size(); i++) { + int[] cardArray = group.get(i); + if (cardArray[0] == card) { + group.remove(cardArray); + return; + } + } + } + + static public void removeOpcard(List opcards, OpCard param) { + for (int i = 0; i < opcards.size(); i++) { + if (param.card1 == opcards.get(i).card1 && param.card2 == opcards.get(i).card2 && param.card3 == opcards.get(i).card3) { + opcards.remove(i); + return; + } + } + } + + public static List deepCopy(List src) throws IOException, ClassNotFoundException { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(src); + + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream in = new ObjectInputStream(byteIn); + @SuppressWarnings("unchecked") + List dest = (List) in.readObject(); + return dest; + } + + public static void distinctList(List cardList) { + Set set = new HashSet<>(cardList); + cardList.clear(); + cardList.addAll(set); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/ChowCard.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/ChowCard.java new file mode 100644 index 0000000..2833998 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/ChowCard.java @@ -0,0 +1,108 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.game.Util; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TObject; + +public class ChowCard { + private Map cardMap; + private int eventCard; + private int biCard; + private int eventCardType; + private int modCard; + + public ChowCard(List cardInhand,int eventCard) { + this.eventCard = eventCard; + this.eventCardType = eventCard / 100; + int bg_num = this.eventCardType == 1 ? 100 : -100; + this.biCard = eventCard+bg_num; + this.modCard = eventCard % 100; + this.cardMap = Util.getCardNumMap(cardInhand); + } + + private boolean handle(ITArray p_list,int opcard1,int opcard2) { + ITArray opcard = TArray.newInstance(); + opcard.addInt(opcard1); + opcard.addInt(opcard2); + boolean result = true; + ITObject obj = TObject.newInstance(); + ITArray list = TArray.newInstance(); + obj.putTArray("opcard", opcard); + obj.putTArray("bi_list", list); + //没有比 + /* + if(CardUtil.checkCard(eventCard, cardMap)) { + CardUtil.addCard(eventCard, cardMap, -1); + CardUtil.addCard(opcard1, cardMap, -1); + CardUtil.addCard(opcard2, cardMap, -1); + result = tryChow(list); + CardUtil.addCard(eventCard, cardMap, 1); + CardUtil.addCard(opcard1, cardMap, 1); + CardUtil.addCard(opcard2, cardMap, 1); + } + */ + if(list.size()==0)obj.remove("bi_list"); + if(result)p_list.addTObject(obj); + return result; + } + + + public boolean tryChow(ITArray list){ + boolean result = false; + if (CardUtil.checkCard(eventCard - 1, cardMap) && CardUtil.checkCard(eventCard - 2, cardMap)) { + result = handle(list,eventCard-1,eventCard-2) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) { + result = handle(list,eventCard+1,eventCard-1) || result; + } + + if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) { + result = handle(list,eventCard+1,eventCard+2) || result; + } + int type = this.eventCardType; + int bi_card = this.biCard; + int mod_card = this.modCard; + + if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+7,type*100+10) || result; + }else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) { + result = handle(list,type*100+2,type*100+10) || result; + }else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) { + result = handle(list,type*100+2,type*100+7) || result; + } + + //if (cardMap.containsKey(bi_card) && cardMap.get(bi_card) == 2) { + // result = handle(list,bi_card,bi_card) || result; + //} + //if (CardUtil.checkCard(eventCard, cardMap) &&CardUtil.checkCard(bi_card, cardMap)) { + // CardUtil.addCard(eventCard, cardMap, -1); + // result = handle(list,eventCard,bi_card) || result; + // CardUtil.addCard(eventCard, cardMap, 1); + //} + + return result; + } + + public static void main(String[] args) { + ArrayList cardInhand = new ArrayList(); + String cardStr = "101, 102, 102, 103, 104, 106, 106, 110, 110, 201, 201, 202, 203, 204, 205, 206, 209, 209, 209, 210"; + String[] cards = cardStr.split(", "); + for(String c : cards) { + Integer card = Integer.valueOf(c); + cardInhand.add(card); + } + + + ChowCard chow = new ChowCard(cardInhand, 101); + ITArray list = TArray.newInstance(); + chow.tryChow(list); + System.out.println(list); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/Paixing.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/Paixing.java new file mode 100644 index 0000000..7970d80 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/Paixing.java @@ -0,0 +1,342 @@ +package extend.zp.uitl; + +import com.game.Global; +import com.taurus.core.util.Logger; +import extend.zp.EXPlayer; +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +import java.util.ArrayList; +import java.util.Map; + +public class Paixing { + Logger logger = Logger.getLogger(getClass()); + + public static boolean checkWin(EXPlayer player, int drawCard, boolean isSelfCard) { + player.resetHuXi(); + boolean isWin = false; + WinCard win = new WinCard(player, player.cardInhand, drawCard); + EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat); + if (win.tryWin(player)) { + if (player.huXi >= 8) { + isWin = true; + } + } + + int duziNum = 0; + int siduiNum = 0; + ArrayList duiList = new ArrayList<>(); + duiList.addAll(player.cardInhand); + for (int i = 0; i < player.tiGroup.size(); i++) { + int card = player.tiGroup.get(i)[0]; + duiList.add(card); + duiList.add(card); + duiList.add(card); + duiList.add(card); + } + for (int i = 0; i < player.kanGroup.size(); i++) { + int card = player.kanGroup.get(i)[0]; + duiList.add(card); + duiList.add(card); + duiList.add(card); + } + + if (activePlayer != null & activePlayer.drawCard > 0) { + duiList.add(activePlayer.drawCard); + } + + Map cardNumList = CardUtil.getCardNumMap(duiList); + for (Map.Entry card : cardNumList.entrySet()) { + if (card.getValue() == 2 || card.getValue() == 3) { + duziNum++; + } + else if (card.getValue() == 4) { + siduiNum++; + } + } + Global.logger.info("jefe pxbf: duziNum "+ duziNum+" siduiNum = "+siduiNum ); + if(duziNum==0&&siduiNum==1){ + duziNum = 1; + }else if (duziNum==1&&siduiNum>0){ + duziNum = 2; + }else if (duziNum>1&&siduiNum>0){ + duziNum = duziNum + siduiNum*2; + } + + // + Global.logger.info("jefe px: duziNum "+ duziNum+" siduiNum = "+siduiNum ); + if (duiList.size() >19) + { + if (duziNum==1){ + isWin = true; + } + if (duziNum == 9){ + isWin = true; + } + if(duziNum==0){ + isWin = true; + } + if (duziNum == 10 ){ + isWin = true; + } + } + + + if (isWin) { + player.handCard.clear(); + player.handCardEx.clear(); + int haoCard = 0; + int haoType = 0; + for (int x = 0; x < win.stack.size(); x++) { + OpCard opcard = new OpCard(); + opcard.card1 = win.stack.get(x).get(0); + opcard.card2 = win.stack.get(x).get(1); + opcard.type = 1; + haoCard = 0; + haoType = 0; + if (win.stack.get(x).size() > 2) { + opcard.card3 = win.stack.get(x).get(2); + opcard.type = 2; + + if (opcard.card1 != opcard.card2) + { + if (opcard.card1 == drawCard || opcard.card2 == drawCard || opcard.card3 == drawCard) + { + if (haoCard == 0) + { + for (int j = 0; j < player.kanGroup.size(); j++) { + if (drawCard == player.kanGroup.get(j)[0]) { + if (!isSelfCard) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + else { + haoCard = drawCard; + haoType = RuleWeight.HAO_NUI; + } + break; + } + } + } + + if (haoCard == 0) + { + for (int j = 0; j < player.pongGroup.size(); j++) { + if (drawCard == player.pongGroup.get(j)[0]) { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + break; + } + } + } + + if (haoCard == 0) + { + for (int j = 0; j < player.weiGroup.size(); j++) { + if (drawCard == player.weiGroup.get(j)[0]) { + if (isSelfCard) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_NUI; + } + else + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + break; + } + } + } + + if (haoCard == 0) + { + int handNum = CardUtil.cardNum(drawCard, player.cardInhand); + for (int j = 0; j < player.chowGroup.size(); j++) { + if (drawCard == player.chowGroup.get(j)[0]) { + handNum++; + } + if (drawCard == player.chowGroup.get(j)[2]) { + handNum++; + } + } + + //算出吃到的 + int chiNum = 1; //本次算一次 + for (int j = 0; j < player.chowGroup.size(); j++) { + if (drawCard == player.chowGroup.get(j)[1]) { + chiNum++; + } + } + + //加上本次,相当于吃了4张一样的 + if (handNum == 0 && chiNum == 4) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 1 && chiNum == 3) { + haoCard = drawCard; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 2 && chiNum == 2) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + } + } + } + else { + if (opcard.card1 == drawCard) + { + for (int j = 0; j < player.chowGroup.size(); j++) { + if (player.chowGroup.get(j)[1] == drawCard) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + break; + } + } + + int handNum = CardUtil.cardNum(drawCard, player.cardInhand) - 2; + if (handNum > 0) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + } + } + } + else { + if (opcard.card1 == drawCard || opcard.card2 == drawCard) + { + if (haoCard == 0) + { + for (int j = 0; j < player.kanGroup.size(); j++) { + if (drawCard == player.kanGroup.get(j)[0]) { + if (!isSelfCard) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + else { + haoCard = drawCard; + haoType = RuleWeight.HAO_NUI; + } + break; + } + } + } + + if (haoCard == 0) + { + for (int j = 0; j < player.pongGroup.size(); j++) { + if (drawCard == player.pongGroup.get(j)[0]) { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + break; + } + } + } + + if (haoCard == 0) + { + for (int j = 0; j < player.weiGroup.size(); j++) { + if (drawCard == player.weiGroup.get(j)[0]) { + if (isSelfCard) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_NUI; + } + else + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + break; + } + } + } + + if (haoCard == 0) + { + int handNum = CardUtil.cardNum(drawCard, player.cardInhand); + for (int j = 0; j < player.chowGroup.size(); j++) { + if (drawCard == player.chowGroup.get(j)[0]) { + handNum++; + } + if (drawCard == player.chowGroup.get(j)[2]) { + handNum++; + } + } + + //算出吃到的 + int chiNum = 1; //本次算一次 + for (int j = 0; j < player.chowGroup.size(); j++) { + if (drawCard == player.chowGroup.get(j)[1]) { + chiNum++; + } + } + + //加上本次,相当于吃了4张一样的 + if (handNum == 0 && chiNum == 4) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 1 && chiNum == 3) { + haoCard = drawCard; + haoType = RuleWeight.HAO_SHAN; + } + else if (handNum == 2 && chiNum == 2) + { + haoCard = drawCard; + haoType = RuleWeight.HAO_WAI; + } + } + } + } + opcard.huXi = win.stackHuxi.get(x); + opcard.hao = haoType; + opcard.haoCard = haoCard; + player.handCard.push(opcard); + } + if (!win.cardList.isEmpty()) { + player.handCardEx.addAll(win.cardList); + } + } + //判断是否是十对 + return isWin; + } + + public static int caclHuxi(int type, int card) { + int cardType = CardUtil.cardType(card); + int huXi = 0; + switch (type) { + case RuleWeight.TYPE_TI: + huXi = 5; + break; + case RuleWeight.TYPE_PAO: + huXi = 0; + break; + case RuleWeight.TYPE_WEI: + case RuleWeight.TYPE_CHOUWEI: + huXi = 4; + break; + case RuleWeight.TYPE_KAN: + huXi = 3; + break; + case RuleWeight.TYPE_CHOW: + huXi = 1; + break; + case RuleWeight.TYPE_PONG: + huXi = 1; + break; + default: + break; + } + return huXi; + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCard.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCard.java new file mode 100644 index 0000000..100035f --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCard.java @@ -0,0 +1,681 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.EXPlayer; +import extend.zp.RuleWeight; + +public class WinCard { + public int pair_count; + public int long_count; + public Stack> stack; + public Stack stackHuxi; + public List cardList; + public int drawCard; + + private void push(List cardGroup) { + this.stack.push(cardGroup); + } + + private void rollBack() { + List cardGroup = this.stack.pop(); + for (Integer card : cardGroup) { + this.cardList.add(card); + } + Collections.sort(this.cardList); + } + + private boolean tryKezi(int card, EXPlayer player) { + if (CardUtil.cardNum(card, this.cardList) >= 3) { + CardUtil.removeCard(this.cardList, card, 3); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + int huXi = 0; + if (player.getRoom().isTianHu && card == player.getRoom().drawCard) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } else { + boolean flag = false; + for (int i = 0; i < player.tiGroup.size(); i++) { + int ti_card = player.tiGroup.get(i)[0]; + if (ti_card == card) + { + flag = true; + } + } + if (flag) + { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_KAN, card); + } + else { + if (card == player.getRoom().drawCard) + { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_WEI, card); + } + else { + //不可能出现这种情况 + huXi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + } + } + } + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi1(int card, EXPlayer player) { + if (card < 200 && card % 100 > 8) { + return false; + } + if (CardUtil.cardNum(card + 1, this.cardList) > 0 && CardUtil.cardNum(card + 2, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 1, 1); + CardUtil.removeCard(this.cardList, card + 2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 1); + cardGroup.add(card + 2); + this.push(cardGroup); + + int huXi = 0; + if (card % 100 == 1) { + //huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + //player.huXi += huXi; + } + + this.stackHuxi.push(huXi); + return true; + } + return false; + } + + private boolean tryShunzi2(int card) { + if (CardUtil.cardType(card) == RuleWeight.SMALL_CARD) { + if (CardUtil.cardNum(card + 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card + 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card + 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 100); + cardGroup.add(card + 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } else { + if (CardUtil.cardNum(card - 100, this.cardList) >= 1 && CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + CardUtil.removeCard(this.cardList, card - 100, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + if (CardUtil.cardNum(card - 100, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 100, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 100); + cardGroup.add(card - 100); + this.push(cardGroup); + this.stackHuxi.push(0); + return true; + } + } + return false; + } + + private boolean tryShunzi3(int card, EXPlayer player) { + if (card % 100 == 2) { + if (CardUtil.cardNum(card + 5, this.cardList) > 0 && CardUtil.cardNum(card + 8, this.cardList) > 0) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + cardGroup.add(card + 8); + this.push(cardGroup); + + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, card); + player.huXi += huXi; + this.stackHuxi.push(huXi); + return true; + } + } + return false; + } + + private boolean isSanHao(int card, EXPlayer player) + { + int handNum = CardUtil.cardNum(card, player.cardInhand); + for (int i = 0; i < player.chowGroup.size(); i++) { + if (card == player.chowGroup.get(i)[0]) { + handNum++; + } + if (card == player.chowGroup.get(i)[2]) { + handNum++; + } + } + + //算出吃到的 + int chiNum = 1; //本次算一次 + for (int i = 0; i < player.chowGroup.size(); i++) { + if (card == player.chowGroup.get(i)[1]) { + chiNum++; + } + } + + if (handNum == 1 && chiNum == 3) + { + return true; + } + return false; + } + + private boolean tryPair(int card, EXPlayer player) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 2) { + CardUtil.removeCard(this.cardList, card, 2); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + else if (CardUtil.cardNum(card, this.cardList) >= 1) { + if (card % 100 <= 9) + { + if (CardUtil.cardNum(card+1, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card+1, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card+1); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + } + if (card % 100 <= 8) + { + if (CardUtil.cardNum(card+2, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card+2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card+2); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + } + if (card % 100 >= 2) + { + if (CardUtil.cardNum(card-1, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card-1, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card-1); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + } + + if (card % 100 >= 3) + { + if (CardUtil.cardNum(card-2, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card-2, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card-2); + this.push(cardGroup); + this.pair_count = 1; + this.stackHuxi.push(0); + return true; + } + } + + if (card % 100 == 2) + { + if (CardUtil.cardNum(card + 5, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card + 8, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 8); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + + if (card % 100 == 7) + { + if (CardUtil.cardNum(card - 5, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 5, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 5); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card + 3, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 3, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 3); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + + if (card % 100 == 10) + { + if (CardUtil.cardNum(card - 8, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 8); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card - 3, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 3, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 3); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + } + return false; + } + + private boolean tryPair2(int card, EXPlayer player) { + if (this.pair_count > 0) { + return false; + } + if (CardUtil.cardNum(card, this.cardList) >= 1) { + if (card % 100 == 2) + { + if (CardUtil.cardNum(card + 5, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 5, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 5); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card + 8, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 8); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + + if (card % 100 == 7) + { + if (CardUtil.cardNum(card - 5, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 5, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 5); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card + 3, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card + 3, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card + 3); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + + if (card % 100 == 10) + { + if (CardUtil.cardNum(card - 8, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 8, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 8); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + + if (CardUtil.cardNum(card - 3, this.cardList) >= 1) { + CardUtil.removeCard(this.cardList, card, 1); + CardUtil.removeCard(this.cardList, card - 3, 1); + List cardGroup = new ArrayList(); + cardGroup.add(card); + cardGroup.add(card - 3); + this.push(cardGroup); + this.pair_count = 1; + player.huXi += 1; + this.stackHuxi.push(1); + return true; + } + } + } + return false; + } + + public boolean tryWin(EXPlayer player) { + if (this.cardList.size() == 0) { + if (player.huXi < 8) + { + return false; + } + if (this.pair_count == 1) + { + return true; + } + else if (this.pair_count == 2 && this.stack.size() == 2) + { + List list = new ArrayList(); + for (int i = 0; i < this.stack.size(); i++) { + int card1 = this.stack.get(i).get(0); + int card2 = this.stack.get(i).get(1); + + list.add(card1 % 100); + list.add(card2 % 100); + } + + if (list.size() != 4) + { + return false; + } + + Collections.sort(list); + + if (list.get(0) == list.get(1)+1 && list.get(1) == list.get(2)+1 && list.get(2) == list.get(3)+1) + { + return true; + } + } + return false; + } + int activeCard = 0; + for (int card : this.cardList) { + if (card == 201 || card == 202) { + activeCard = card; + break; + } + } + if (activeCard == 0) { + activeCard = this.cardList.get(0); + } + if (activeCard % 100 == 1) { + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair2(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + } else if (activeCard % 100 == 2) { + if (tryShunzi3(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair2(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + /*if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + */ + } else { + if (tryKezi(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryPair2(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.pair_count = 0; + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + if (tryShunzi1(activeCard, player)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + int huXi = this.stackHuxi.pop(); + if (huXi > 0) { + player.huXi -= huXi; + } + } + /* + if (tryShunzi2(activeCard)) { + if (tryWin(player)) { + return true; + } + this.rollBack(); + this.stackHuxi.pop(); + } + */ + } + + return false; + } + + public WinCard(EXPlayer player, List cardInhand, int addCard) { + this.stack = new Stack>(); + this.stackHuxi = new Stack(); + this.cardList = new ArrayList(); + this.cardList.addAll(cardInhand); + for (int i = 0; i < player.tiGroup.size(); i++) { + int card = player.tiGroup.get(i)[0]; + this.cardList.add(card); + this.cardList.add(card); + this.cardList.add(card); + this.cardList.add(card); + } + if (addCard > 0) { + this.cardList.add(addCard); + } + this.drawCard = addCard; + Collections.sort(this.cardList); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCardNew.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCardNew.java new file mode 100644 index 0000000..aea44ac --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinCardNew.java @@ -0,0 +1,381 @@ +package extend.zp.uitl; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Stack; + +import extend.zp.OpCard; +import extend.zp.RuleWeight; + +public class WinCardNew { + private boolean isJiang = false; + private List cardList; + private Stack>> opCardStack; + private List> lastOpCard; + private Integer addCard; + private int huxi = 0; + private List opCardList; + + public List winList; + + public boolean checkHu() { + try { + + int card = addCard == 0 ? (this.cardList.size() > 0 ? this.cardList.get(0) : 0) : addCard; + List list = new ArrayList(); + if (card > 0) { + list = groupCard(card, this.cardList, true); + } else if (card == 0) { + addWinOpCard(huxi, null); + return true; + } + List tempCardList = new ArrayList<>(); + for (OpCard opCard : list) { + tempCardList.clear(); + tempCardList.addAll(cardList); + Collections.sort(tempCardList); + removeOpCard(tempCardList, opCard); + List opCardS = new ArrayList<>(); + List> opCardS_1 = new ArrayList<>(); + opCardS.add(opCard); + opCardS_1.add(opCardS); + this.opCardStack.push(opCardS_1); + checkWin(tempCardList); + } + } catch (Exception e) { + return false; + } + return Win(); + } + + + private boolean Win() { + List tempCardList = new ArrayList<>(); + boolean hu, isExJiang; + for (List opCards : this.lastOpCard) { + isExJiang = false; + tempCardList.clear(); + tempCardList.addAll(cardList); + hu = false; + int huxi = this.huxi; + for (OpCard tempOpCard : opCards) { + removeOpCard(tempCardList, tempOpCard); + if (tempOpCard.type == RuleWeight.TYPE_JIANG) { + isExJiang = true; + continue; + } + huxi += tempOpCard.huXi; + } + + hu = isJiang ? isExJiang && tempCardList.size() == 0 : tempCardList.size() == 0; + if (hu) { + addWinOpCard(huxi, opCards); + } + } + return !winList.isEmpty(); + } + + private void removeOpCard(List cards, OpCard opCard) { + if (opCard.card1 > 0) { + CardUtil.removeCard(cards, opCard.card1, 1); + } + if (opCard.card2 > 0) { + CardUtil.removeCard(cards, opCard.card2, 1); + } + if (opCard.card3 > 0) { + CardUtil.removeCard(cards, opCard.card3, 1); + } + } + + private boolean isExJiang(List> list) { + for (List opCard : list) { + for (OpCard opCard2 : opCard) { + if (opCard2.type == RuleWeight.TYPE_JIANG) { + return false; + } + } + } + return true; + } + + private void checkWin(List cardList) throws ClassNotFoundException, IOException { + List> opCards = this.opCardStack.pop(); + if (opCards.isEmpty()) { + return; + } + List> list = new ArrayList<>(); + if (cardList.size() == 0) { + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + return; + } + List oplist = null, opList2 = null; + for (Integer card : cardList) { + oplist = groupCard(card, cardList, isExJiang(opCards)); + if (oplist.size() > 0) { + break; + } + } + if (oplist.size() > 0) { + List tempCardList = new ArrayList<>(); + for (OpCard opCard : oplist) { + tempCardList.clear(); + tempCardList.addAll(cardList); + list = new ArrayList<>(); + removeOpCard(tempCardList, opCard); + list = CardUtil.deepCopy(opCards); + for (List tempOpCard : list) { + tempOpCard.add(opCard); + } + for (Integer card : tempCardList) { + opList2 = groupCard(card, tempCardList, isExJiang(list)); + if (opList2.size() > 0) { + break; + } + } + if (opList2 != null && opList2.size() > 0) { + this.opCardStack.push(list); + checkWin(tempCardList); + } else { + this.lastOpCard.addAll(list); + } + + } + } else { + list = new ArrayList<>(); + list = CardUtil.deepCopy(opCards); + this.lastOpCard.addAll(list); + } + + } + + /** + * ij����Ч��� + * + * @param card + * @return + */ + private List groupCard(int card, List cardList, boolean first) { + List opCardList = new ArrayList<>(); + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + shunzi1_10(card, opCardList, tempList); + shunzi2710(card, opCardList, tempList); + jiaopai(card, opCardList, tempList); + kan(card, opCardList, tempList); + if (isJiang && first) { + jiang(card, opCardList, tempList); + } + return opCardList; + } + + /** + * ��һ�Խ� + */ + private void jiang(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + if (isJiang) { + if (CardUtil.cardNum(card, cardList) >= 2) { + OpCard opCard = new OpCard(); + opCard.card1 = card; + opCard.card2 = card; + opCard.huXi = 0; + opCard.type = RuleWeight.TYPE_JIANG; + list.add(opCard); + } + } + } + + /** + * ��С 1 2 3 4 5 6 7 8 9 ˳�� + * + * @param card + */ + private void shunzi1_10(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + List opCardList = new ArrayList<>(); + // AB (C) + if (CardUtil.cardNum(card - 2, cardList) >= 1 && CardUtil.cardNum(card - 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card - 2); + list.add(addOpCard(opCardList)); + + } + // (A) B C + if (CardUtil.cardNum(card + 1, cardList) >= 1 && CardUtil.cardNum(card + 2, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card + 1); + opCardList.add(card + 2); + list.add(addOpCard(opCardList)); + } + // A (B) C + if (CardUtil.cardNum(card - 1, cardList) >= 1 && CardUtil.cardNum(card + 1, cardList) >= 1) { + opCardList.clear(); + opCardList.add(card); + opCardList.add(card - 1); + opCardList.add(card + 1); + list.add(addOpCard(opCardList)); + } + } + + private OpCard addOpCard(List opCardList) { + Collections.sort(opCardList); + int huXi = 0; + // 123 ˳���к�Ϣ С3��6 + if (opCardList.get(0) % 100 == 1) { + huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + } + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + return opCard; + } + + /** + * ��С 2 7 10˳�� �к�Ϣ С3��6 + * + * @param card + */ + private void shunzi2710(int card, List list, List cardList) { + if (card % 100 == 2 || card % 100 == 7 || card % 100 == 10) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + CardUtil.distinctList(tempList); + Collections.sort(tempList); + // (2) 7 10 + List opCardList = new ArrayList<>(); + if (CardUtil.cardNum(card + 5, cardList) >= 1 && CardUtil.cardNum(card + 8, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card + 5); + opCardList.add(card + 8); + // 2 (7) 10 + } else if (CardUtil.cardNum(card - 5, cardList) >= 1 && CardUtil.cardNum(card + 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 5); + opCardList.add(card + 3); + // 2 7 (10) + } else if (CardUtil.cardNum(card - 8, cardList) >= 1 && CardUtil.cardNum(card - 3, cardList) >= 1) { + opCardList.add(card); + opCardList.add(card - 3); + opCardList.add(card - 8); + } + if (opCardList.size() > 0) { + Collections.sort(opCardList); + int huXi = Paixing.caclHuxi(RuleWeight.TYPE_CHOW, opCardList.get(0)); + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, opCardList.get(0), opCardList.get(1), opCardList.get(2), huXi); + list.add(opCard); + if (opCard.card1 != card) { + CardUtil.removeCard(tempList, opCard.card1, 1); + } + if (opCard.card2 != card) { + CardUtil.removeCard(tempList, opCard.card2, 1); + } + if (opCard.card3 != card) { + CardUtil.removeCard(tempList, opCard.card3, 1); + } + shunzi2710(card, list, tempList); + } + return; + } + } + + /** + * aaA AAa ������ ������ û��Ϣ + * + * @param card + */ + private void jiaopai(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + tempList.addAll(cardList); + int type = card / 100; + int bg_num = type == 1 ? 100 : -100; + int bi_card = card + bg_num; + // aaA + if (CardUtil.cardNum(card, cardList) >= 2 && CardUtil.cardNum(bi_card, cardList) >= 1) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, card, bi_card, 0); + list.add(opCard); + // AAa + } else if (CardUtil.cardNum(card, cardList) >= 1 && CardUtil.cardNum(bi_card, cardList) >= 2) { + OpCard opCard = new OpCard(RuleWeight.TYPE_CHOW, card, bi_card, bi_card, 0); + list.add(opCard); + } + } + + /** + * 3�� + * + * @param card + * @param list + */ + private void kan(int card, List list, List cardList) { + List tempList = new ArrayList<>(); + List opCardList = new ArrayList<>(); + tempList.addAll(cardList); + if (CardUtil.cardNum(card, cardList) == 3) { + opCardList.add(card); + opCardList.add(card); + opCardList.add(card); + int huxi = Paixing.caclHuxi(RuleWeight.TYPE_PONG, card); + OpCard opCard = new OpCard(RuleWeight.TYPE_PONG, opCardList.get(0), opCardList.get(1), opCardList.get(2), huxi); + list.add(opCard); + } + } + + private void addWinOpCard(int huxi, List opCard) { + if (opCard == null) { + opCard = new ArrayList<>(); + } + opCard.addAll(this.opCardList); + WinOpCard wo = new WinOpCard(opCard, huxi); + winList.add(wo); + } + + public static void main(String[] args) throws ClassNotFoundException, IOException { + List list = new ArrayList<>(); + String str = "106"; + for (String card : str.split(", ")) { + list.add(Integer.parseInt(card)); + } + List op = new ArrayList(); + OpCard opCard=new OpCard(3, 102, 102, 102, 9); + op.add(opCard); + WinCardNew winCard2 = new WinCardNew(list, 106, 9, true, op); + /* op = winCard2.groupCard(207); */ + System.out.println(winCard2.checkHu()); + winCard2.winList.forEach(wl -> System.out.println(wl.toString())); + + } + + /** + * + * @param cardInhand + * :����,�������� + * @param addCard + * : �Ӵ����Ƿ��ܺ���������������������Ҫ��0 + * @param huxi + * ��������еĺ�Ϣ + * @param isJiang + * ���Ƿ���Ҫ�� + */ + public WinCardNew(List cardInhand, int addCard, int huxi, boolean isJiang, List opCardList) { + this.opCardStack = new Stack<>(); + this.lastOpCard = new ArrayList<>(); + this.cardList = new ArrayList(cardInhand); + this.opCardList = new ArrayList<>(opCardList); + if (addCard > 0) { + this.cardList.add(addCard); + } + Collections.sort(this.cardList); + this.isJiang = isJiang; + this.addCard = addCard; + this.huxi = huxi; + this.winList = new ArrayList<>(); + } +} diff --git a/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinOpCard.java b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinOpCard.java new file mode 100644 index 0000000..f18ba15 --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/main/java/extend/zp/uitl/WinOpCard.java @@ -0,0 +1,31 @@ +package extend.zp.uitl; + +import java.util.ArrayList; +import java.util.List; + +import extend.zp.OpCard; + +public class WinOpCard { + public List opCard; + + public int huXi = 0; + + public WinOpCard(List opCard, int huXi) { + this.opCard = new ArrayList(opCard); + this.huXi = huXi; + } + + @Override + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("total_huxi : " + huXi + ", "); + for (OpCard opCard : opCard) { + sb.append(opCard.card1 + " "); + sb.append(opCard.card2 + " "); + sb.append(opCard.card3==0?"":opCard.card3); + sb.append(",type:" + opCard.type + ",huxi=" + opCard.huXi + " | "); + } + return sb.toString(); + } + +} diff --git a/game_zp_yueyangwaihuzi/src/test/java/game_zp_yueyangwaihuzi/Main.java b/game_zp_yueyangwaihuzi/src/test/java/game_zp_yueyangwaihuzi/Main.java new file mode 100644 index 0000000..16063ae --- /dev/null +++ b/game_zp_yueyangwaihuzi/src/test/java/game_zp_yueyangwaihuzi/Main.java @@ -0,0 +1,9 @@ +package game_zp_yueyangwaihuzi; + +import com.taurus.permanent.TPServer; + +public class Main { + public static void main(String[] args) { + TPServer.me().start(); + } +} diff --git a/group_mgr/build/local/log4j.properties b/group_mgr/build/local/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/group_mgr/build/local/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/group_mgr/build/local/mgr-config.xml b/group_mgr/build/local/mgr-config.xml new file mode 100644 index 0000000..aab4767 --- /dev/null +++ b/group_mgr/build/local/mgr-config.xml @@ -0,0 +1,6 @@ + + + 127.0.0.1:11050 + 1000 + true + \ No newline at end of file diff --git a/group_mgr/build/local/taurus-core.xml b/group_mgr/build/local/taurus-core.xml new file mode 100644 index 0000000..61a95c1 --- /dev/null +++ b/group_mgr/build/local/taurus-core.xml @@ -0,0 +1,98 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/group_mgr/build/local/taurus-permanent.xml b/group_mgr/build/local/taurus-permanent.xml new file mode 100644 index 0000000..e72685d --- /dev/null +++ b/group_mgr/build/local/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 128 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 3 + 3 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + com.mgr.group.MainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/group_mgr/build/pro/log4j.properties b/group_mgr/build/pro/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/group_mgr/build/pro/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/group_mgr/build/pro/mgr-config.xml b/group_mgr/build/pro/mgr-config.xml new file mode 100644 index 0000000..0d5a539 --- /dev/null +++ b/group_mgr/build/pro/mgr-config.xml @@ -0,0 +1,6 @@ + + + wegame.hlkj123.cn:11050 + 1000 + true + \ No newline at end of file diff --git a/group_mgr/build/pro/taurus-core.xml b/group_mgr/build/pro/taurus-core.xml new file mode 100644 index 0000000..bad1582 --- /dev/null +++ b/group_mgr/build/pro/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 160 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 160 + + 16 + + 10 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group_mgr/build/pro/taurus-permanent.xml b/group_mgr/build/pro/taurus-permanent.xml new file mode 100644 index 0000000..108342f --- /dev/null +++ b/group_mgr/build/pro/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 128 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 3 + 20 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + com.mgr.group.MainServer + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/group_mgr/build/test/log4j.properties b/group_mgr/build/test/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/group_mgr/build/test/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/group_mgr/build/test/mgr-config.xml b/group_mgr/build/test/mgr-config.xml new file mode 100644 index 0000000..ddf6174 --- /dev/null +++ b/group_mgr/build/test/mgr-config.xml @@ -0,0 +1,6 @@ + + + 39.101.179.66:11050 + 1000 + true + \ No newline at end of file diff --git a/group_mgr/build/test/taurus-core.xml b/group_mgr/build/test/taurus-core.xml new file mode 100644 index 0000000..bde0e53 --- /dev/null +++ b/group_mgr/build/test/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 1 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group_mgr/build/test/taurus-permanent.xml b/group_mgr/build/test/taurus-permanent.xml new file mode 100644 index 0000000..e72685d --- /dev/null +++ b/group_mgr/build/test/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 128 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 3 + 3 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 8080 +
+ + + + extension - group_mgr + com.mgr.group.MainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/group_mgr/pom.xml b/group_mgr/pom.xml new file mode 100644 index 0000000..351b98a --- /dev/null +++ b/group_mgr/pom.xml @@ -0,0 +1,126 @@ + + 4.0.0 + com.mgr.group + group_mgr + war + 1.0.0 + + UTF-8 + 1.8 + 1.8 + pro + + + + + junit + junit + 3.8.1 + test + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + + mysql + mysql-connector-java + 5.1.48 + + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + org.quartz-scheduler + quartz + 2.2.3 + + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + + + ROOT + + + org.apache.maven.plugins + maven-war-plugin + + 1.8 + 1.8 + UTF-8 + logs/**,config/** + + + config/ + ${project.basedir}/build/${build.type}/ + + + + + + + + diff --git a/group_mgr/src/main/java/com/mgr/group/Config.java b/group_mgr/src/main/java/com/mgr/group/Config.java new file mode 100644 index 0000000..81d0b9d --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/Config.java @@ -0,0 +1,9 @@ +package com.mgr.group; + +public class Config { + public int mgrId; + public String host; + public String webHost; + public int webPort; + public boolean loggerDebug; +} diff --git a/group_mgr/src/main/java/com/mgr/group/Global.java b/group_mgr/src/main/java/com/mgr/group/Global.java new file mode 100644 index 0000000..2d23c52 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/Global.java @@ -0,0 +1,28 @@ +package com.mgr.group; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.mgr.group.data.Group; +import com.taurus.core.util.Logger; + +public class Global { + /** + * debug模式 + */ + public static boolean loggerDebug = false; + // 日志 + public static Logger logger; + + public static SessionManager sessionMgr; + public static GroupController groupCtr; + public static ConcurrentMap groupMap; + + public static void init() { + groupMap = new ConcurrentHashMap<>(); + sessionMgr = new SessionManager(); + groupCtr = new GroupController(); + } + + +} diff --git a/group_mgr/src/main/java/com/mgr/group/GroupController.java b/group_mgr/src/main/java/com/mgr/group/GroupController.java new file mode 100644 index 0000000..f4fd84b --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/GroupController.java @@ -0,0 +1,320 @@ +package com.mgr.group; + +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import com.data.bean.AccountBean; +import com.data.bean.GroupMemberBean; +import com.data.bean.GroupPlayBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupMemberCache; +import com.data.util.ErrorCode; +import com.mgr.group.data.CommandData; +import com.mgr.group.data.Group; +import com.mgr.group.data.Room; +import com.mgr.group.data.User; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.routes.IController; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Session; + +import com.taurus.web.WebException; +import redis.clients.jedis.Jedis; + +/** + * 基本游戏控制器 + * + */ +public class GroupController implements IController { + + /** + * 请求进入房间 + */ + @ActionKey(Router.FGMGR_ENTER_GROUP) + public void RouterJoinGroup(Session sender, ITObject params, int gid) { + String session_id = params.getUtfString("session"); + 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"); + String key = session_id + "_token"; + + Global.logger.info("---------------key,参数params:{}" + key); + + Set canTokenList = Redis.use("group1_db0").smembers(key); + Global.logger.info("---------------canTokenList,参数params:{}" + canTokenList); + Global.logger.info("---------------token,参数params:{}" + token); + Global.logger.info("---------------session_id,参数params:{}" + session_id); + +// if (canTokenList.size() == 0) { +// TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); +// return; +// +// } +// boolean canEnter = false; +// for (String canToken : canTokenList) { +// if (canToken.equalsIgnoreCase(token)) { +// canEnter = true; +// } +// } +// if (!canEnter) { +// TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); +// return; +// +// } + + if (StringUtil.isEmpty(token_session)) { + TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); + return; + } else { + if (!token_session.equals(session_id)) { + TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); + return; + } + } + } else { + TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); + return; + } + } + sender.setHashId(session_id); + int groupId = params.getInt("groupId"); + Global.groupCtr.joinGroup(sender, groupId, gid); + + } + + private static AtomicInteger invi_id = new AtomicInteger(0); + + public void joinGroup(Session sender, int groupId, int gid) { + Group group = null; + synchronized (Global.groupMap) { + if (Global.groupMap.containsKey(groupId)) { + group = Global.groupMap.get(groupId); + } else { + group = new Group(groupId); + Global.groupMap.put(groupId, group); + } + group.lastTime = System.currentTimeMillis(); + } + + group.start(); + if (group.isDestroy) { + TPServer.me().getController().sendResponse(gid, ErrorCode._FAILED, null, sender); + return; + } + + group.enqueueRunnable(new Runnable() { + + @Override + public void run() { + Group group = Global.groupMap.get(groupId); + User user = null; + AccountBean acc = null; + if (sender != null && StringUtil.isNotEmpty(sender.getHashId())) { + acc = AccountCache.getAccount(sender.getHashId()); + } else { + if (sender != null) { + if (StringUtil.isNotEmpty(sender.getHashId())) { + Global.logger.info("---------------session.id:" + sender.getId() + " hashId null"); + } + } else { + Global.logger.info("---------------session为null,"); + } + } + if (acc == null) { + TPServer.me().getController().sendResponse(gid, ErrorCode._NO_SESSION, null, sender); + return; + } + int uid = acc.id; + if (!group.userMap.containsKey(uid)) { + user = new User(); + user.uid = uid; + user.session_key = AccountCache.genKey(uid); + user.group = group; + user.setSender(sender); + group.userMap.put(uid, user); + } else { + user = group.userMap.get(uid); + user.setSender(sender); + } + if (user.gm_key == null) { + user.gm_key = GroupMemberCache.genKey(groupId, uid); + } + String gm_key = user.gm_key; + sender.setHashId(gm_key); + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + if (gmb == null) { + user.response(null, gid, ErrorCode._FAILED); + return; + } + int partnerLev = gmb.partnerLev; + int lev = gmb.lev; + long hp = 0; + int permission = gmb.permission; + int ban = gmb.ban; + int mail_tip = 0; + int queueid = 0; + int seeid = gmb.seeid; + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + hp = Long.parseLong(jedis10.hget(gm_key, "hp")); + queueid = Integer + .parseInt(jedis10.hget(gm_key, "queueid") == null ? "0" : jedis10.hget(gm_key, "queueid")); + seeid = Integer + .parseInt(jedis10.hget(gm_key, "seeid") == null ? "0" : jedis10.hget(gm_key, "seeid")); + long last_time = System.currentTimeMillis() / 1000; + jedis10.hset(gm_key, "last_time", last_time + ""); + jedis10.hset(gm_key, "on_line", 1 + ""); + String mail_tip_key = GroupCache.genMailTipKey(groupId); + Double tem = jedis10.zscore(mail_tip_key, uid + ""); + if (tem != null && tem > 0) { + mail_tip = 1; + } + } finally { + jedis10.close(); + } + String fp = Redis.use("group1_db1").hget("alllook", uid + ""); + user.partnerLev = partnerLev; + if (fp != null) { + user.lev = 1; + } else { + user.lev = lev; + } + + user.hp = hp; + // user.queueid = queueid; + user.ban = ban; + ITObject info = group.getInfo(lev, uid); + + if (fp != null) { + info.putInt("lev", 1); + } else { + info.putInt("lev", lev); + } + + // info.putInt("lev", lev); + info.putInt("partnerLev", partnerLev); + info.putInt("permission", permission); + info.putLong("hp", hp); + info.putInt("mail_tip", mail_tip); + info.putInt("queueid", queueid); + info.putInt("seeid", seeid); + user.response(info, gid, 0); + + // Global.logger.info("joinGroup / playlist --> info: "+info); + } + }); + + } + + public void addRoom(Group group, String roomid) { + Room room = group.addRoom(roomid); + if (room == null) + return; + ITObject param = room.data; + group.addRoomCommand(roomid, CommandData.ADD_ROOM, param); + } + + public void delRoom(Group group, String roomid) { + group.delRoom(roomid); + ITObject param = TObject.newInstance(); + param.putUtfString("roomid", roomid); + group.addRoomCommand(roomid, CommandData.DEL_ROOM, param); + } + + public void updateRoom(Group group, String roomid) { + Room room = group.updateRoom(roomid); + if (room == null) + return; + if (room.priorityValue == 0) { + ITObject param = TObject.newInstance(); + param.putUtfString("roomid", roomid); + group.addRoomCommand(roomid, CommandData.DEL_ROOM, param); + } else { + ITObject param = room.data; + group.addRoomCommand(roomid, CommandData.UPDATE_ROOM, param); + } + + } + + public void delPlay(Group group, int pid) { + group.delPlay(pid); + ITObject param = TObject.newInstance(); + param.putInt("pid", pid); + group.broadCastToClient(Router.FGMGR_EVT_DEL_PLAY, param); + } + + public void addPlay(Group group, int pid) { + GroupPlayBean gp = group.addPlay(pid); + if (gp != null) { + // + group.broadCastToClient(Router.FGMGR_EVT_ADD_PLAY, gp.data); + + Global.logger.info("addPlay: -------------> " + gp.data); + } + } + + public void updatePlay(Group group, int pid) { + GroupPlayBean gp = group.addPlay(pid); + if (gp != null) { + group.broadCastToClient(Router.FGMGR_EVT_UPDATE_PLAY, gp.data); + + Global.logger.info("updatePlay: -------------> " + gp.data); + } + } + + public void updateGroup(Group group, String name, int ban, String notice, int option, int showNum) { + ITObject param = TObject.newInstance(); + param.putUtfString("name", name); + param.putInt("ban", ban); + param.putUtfString("notice", notice); + param.putInt("option", option); + param.putInt("show_num", showNum); + group.broadCastToClient(Router.FGMGR_EVT_UPDATE_GROUP, param); + } + + public void updateJoins(Group group, int joins) { + if (joins <= 0) + return; + List list = group.getSessionListByMgr(); + if (list.size() == 0) + return; + ITObject param = TObject.newInstance(); + param.putInt("joins", joins); + TPServer.me().getController().sendEvent(Router.FGMGR_EVT_UPDATE_JOINS, param, list); + } + + public void updateMember(Group group, int uid, int type, int value) { +// User user = group.userMap.get(uid); +// if(user!=null) { +// ITObject param = TObject.newInstance(); +// param.putInt("type", type); +// param.putInt("value", value); +// MainServer.instance.sendEvent(Router.FGMGR_EVT_UPDATE_MEMBER, param, user.sender); +// } + } + + public void updateMailTip(Group group, int uid) { + User user = group.userMap.get(uid); + if (user != null) { + ITObject param = TObject.newInstance(); + TPServer.me().getController().sendEvent(Router.FGMGR_EVT_UPDATE_MAILTIP, param, user.sender); + } + } +} diff --git a/group_mgr/src/main/java/com/mgr/group/GroupSubscriber.java b/group_mgr/src/main/java/com/mgr/group/GroupSubscriber.java new file mode 100644 index 0000000..c394265 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/GroupSubscriber.java @@ -0,0 +1,161 @@ +package com.mgr.group; + +import com.mgr.group.data.Group; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; + +import redis.clients.jedis.JedisPubSub; + +public class GroupSubscriber extends JedisPubSub { + + public static final String CHANNEL_NAME = "mgr_group"; + + private static final String CMD_UPDATE_ROOM="update_room"; + private static final String CMD_DEL_ROOM="del_room"; + private static final String CMD_ADD_ROOM="add_room"; + private static final String CMD_DEL_PLAY="del_play"; + private static final String CMD_ADD_PLAY="add_play"; + private static final String CMD_UPDATE_PLAY="update_play"; + private static final String CMD_DEL_GROUP="del_group"; + private static final String CMD_UPDATE_GROUP="update_group"; + + + private static final String CMD_UPDATE_JOINS="update_joins"; + private static final String CMD_UPDATE_MEMBER="update_member"; + private static final String CMD_UPDATE_MAIL_TIP = "update_mail_tip"; + + private Logger log; + + public GroupSubscriber() { + log = Logger.getLogger(this.getClass()); + } + + private void updateRoomEvt(Group group,ITObject param) { + String roomid = param.getUtfString("roomid"); + Global.groupCtr.updateRoom(group,roomid); + } + + private void addRoomEvt(Group group,ITObject param) { + String roomid = param.getUtfString("roomid"); + Global.groupCtr.addRoom(group, roomid); + } + + private void delRoomEvt(Group group,ITObject param) { + String roomid = param.getUtfString("roomid"); + Global.groupCtr.delRoom(group, roomid); + } + + private void addPlay(Group group,ITObject param) { + int pid = param.getInt("pid"); + Global.groupCtr.addPlay(group, pid); + } + + private void updatePlay(Group group,ITObject param) { + int pid = param.getInt("pid"); + Global.groupCtr.updatePlay(group, pid); + } + + private void delPlay(Group group,ITObject param) { + int pid = param.getInt("pid"); + Global.groupCtr.delPlay(group, pid); + } + + private void updateGroup(Group group,ITObject param) { + String name = param.getUtfString("name"); + int ban = param.getBoolean("ban")?1:0; + String notice = param.getUtfString("notice"); + int option = param.getInt("option"); + int showNum = param.getInt("show_num"); + Global.groupCtr.updateGroup(group, name, ban,notice,option,showNum); + } + + private void updateJoins(Group group,ITObject param) { + int joins = param.getInt("joins"); + Global.groupCtr.updateJoins(group, joins); + } + + private void updateMailTip(Group group,ITObject param) { + int uid = param.getInt("uid"); + Global.groupCtr.updateMailTip(group, uid); + } +// private void updateMember(Group group,ITObject param) { +// int uid = param.getInt("uid"); +// int type = param.getInt("type"); +// int value = param.getInt("value"); +// Global.groupCtr.updateMember(group, uid, type, value); +// } + + + + + public void onMessage(String channel, String message) { + if(channel.equals(CHANNEL_NAME)) { + if(Global.loggerDebug) { + log.info(message); + } + try { + ITObject data = TObject.newFromJsonData(message); + final int groupId = data.getInt("gid"); + Group group = Global.groupMap.get(groupId); + if(group!=null) { + group.enqueueRunnable(new Runnable() { + @Override + public void run() { + String cmd = data.getUtfString("cmd"); + Group group = Global.groupMap.get(groupId); + switch(cmd) { + case CMD_UPDATE_ROOM: + updateRoomEvt(group,data); + break; + case CMD_DEL_ROOM: + delRoomEvt(group,data); + break; + case CMD_ADD_ROOM: + addRoomEvt(group,data); + break; + case CMD_DEL_GROUP: + group.destroy(); + break; + case CMD_UPDATE_GROUP: + updateGroup(group,data); + break; + case CMD_ADD_PLAY: + addPlay(group,data); + break; + case CMD_UPDATE_PLAY: + updatePlay(group, data); + break; + case CMD_DEL_PLAY: + delPlay(group,data); + break; + case CMD_UPDATE_JOINS: + updateJoins(group,data); + break; + case CMD_UPDATE_MEMBER: +// updateMember(group,data); + break; + case CMD_UPDATE_MAIL_TIP: + updateMailTip(group,data); + break; + } + } + }); + } + }catch (Exception e) { + log.error(e); + } + } + } + + public void onSubscribe(String channel, int subscribedChannels) { + System.out.println(String.format("subscribe redis channel success, channel %s, subscribedChannels %d", + channel, subscribedChannels)); + } + + public void onUnsubscribe(String channel, int subscribedChannels) { + System.out.println(String.format("unsubscribe redis channel, channel %s, subscribedChannels %d", + channel, subscribedChannels)); + + } +} diff --git a/group_mgr/src/main/java/com/mgr/group/MainServer.java b/group_mgr/src/main/java/com/mgr/group/MainServer.java new file mode 100644 index 0000000..a223ed0 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/MainServer.java @@ -0,0 +1,161 @@ +package com.mgr.group; + +import java.io.FileInputStream; +import java.util.ArrayList; +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.mgr.group.data.Group; +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; +import com.taurus.web.TWebServer; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.exceptions.JedisConnectionException; + +/** + * + * + */ +public class MainServer extends Extension implements IEventListener { + + public static MainServer instance; + + private GroupSubscriber subscriber; + public Config config; + + @Override + public void onStart() { + try { + instance = this; + + Global.logger = Logger.getLogger(MainServer.class); + Global.init(); + + try { + loadConfig(); + } catch (Exception e1) { + Global.logger.error(e1); + } + + final String svr_key = "svr_mgr_" + config.mgrId; + Global.loggerDebug = config.loggerDebug; + TPServer.me().getEventManager().addEventListener(TPEvents.EVENT_SESSION_DISCONNECT, this); + + TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + try { + int size = Global.sessionMgr.size(); + final Map svr_info = new HashMap<>(); + svr_info.put("host", config.host); + svr_info.put("conns", size + ""); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + try { + jedis11.hmset(svr_key, svr_info); + jedis11.expire(svr_key, 15); + jedis11.zadd(GroupSubscriber.CHANNEL_NAME, size, svr_key); + }finally { + jedis11.close(); + } + } catch (Exception e) { + Global.logger.error(e); + } + } + }, 0, 5, TimeUnit.SECONDS); + + TPServer.me().getTimerPool().scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + List list = new ArrayList(Global.groupMap.values()); + for (Group group : list) { + if ((System.currentTimeMillis() - group.lastTime) >= 360000000) { + group.enqueueRunnable(new Runnable() { + + @Override + public void run() { + group.destroy(); + } + }); + } + } + } + }, 10, 10, TimeUnit.SECONDS); + + subscriber = new GroupSubscriber(); + Thread subscribeThread = new Thread(new Runnable() { + + @Override + public void run() { + try { + Redis.use("group1_db11").subscribe(subscriber, GroupSubscriber.CHANNEL_NAME); + } catch (JedisConnectionException e) { + Redis.use("group1_db11").subscribe(subscriber, GroupSubscriber.CHANNEL_NAME); + } + } + }); + subscribeThread.start(); + + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + + @Override + public void run() { + Redis.use("group1_db11").unsubscribe(subscriber); + Redis.use("group1_db11").zrem(GroupSubscriber.CHANNEL_NAME, svr_key); + } + })); + }catch (Exception e){ + Global.logger.error(e); + } + } + + protected void loadConfig() throws Exception { + FileInputStream is = new FileInputStream(TWebServer.me().getContextRealPath()+"/config/mgr-config.xml"); + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(is); + Element root = document.getRootElement(); + Config config = new Config(); + config.host = root.getChildTextTrim("host"); + config.mgrId = Integer.parseInt(root.getChildTextTrim("mgrId")); + config.loggerDebug = Boolean.parseBoolean(root.getChildTextTrim("loggerDebug")); + this.config = config; + } + + public void onStop() { + super.onStop(); + } + + @Override + public void handleEvent(Event evt) { + String evtName = evt.getName(); + switch (evtName) { + case TPEvents.EVENT_SESSION_DISCONNECT: + Session session = (Session) evt.getParameter(TPEvents.PARAM_SESSION); + Global.sessionMgr.disconnect(session); + break; + } + } + + @Override + public void configRoute(Routes me) { + Global.groupCtr = new GroupController(); + me.add("", Global.groupCtr); + } + + +} diff --git a/group_mgr/src/main/java/com/mgr/group/Router.java b/group_mgr/src/main/java/com/mgr/group/Router.java new file mode 100644 index 0000000..5f2a3ba --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/Router.java @@ -0,0 +1,87 @@ +package com.mgr.group; + +import com.taurus.core.entity.ITObject; +import com.taurus.permanent.data.Session; + +/** + * 网络路由处理 + * + */ +public abstract class Router { + /** + * 进入圈子 + */ + public static final String FGMGR_ENTER_GROUP = "11001"; + /** + * 获取在线邀请玩家 + */ + public static final String FGMGR_GET_ONLINE_LIST = "11002"; + /** + * 邀请玩家 + */ + public static final String FGMGR_INVITATION = "11003"; + /** + * 邀请玩家响应 + */ + public static final String FGMGR_INVITATION_RESPONSE = "11004"; + /** + * 更新房间 + */ + public static final String FGMGR_EVT_UPDATE_ROOM = "12001"; + +// /** +// * 删除房间 +// */ +// public static final String FGMGR_EVT_DEL_ROOM = "12002"; +// +// /** +// * 添加房间 +// */ +// public static final String FGMGR_EVT_ADD_ROOM = "12003"; + + /** + * 删除玩法 + */ + public static final String FGMGR_EVT_DEL_PLAY = "12004"; + + /** + * 添加玩法 + */ + public static final String FGMGR_EVT_ADD_PLAY = "12005"; + /** + * 更新玩法 + */ + public static final String FGMGR_EVT_UPDATE_PLAY = "12006"; + /** + * 更新申请 + */ + public static final String FGMGR_EVT_UPDATE_JOINS = "12007"; + /** + * 更新圈子 + */ + public static final String FGMGR_EVT_UPDATE_GROUP = "12008"; + /** + * 更新成员 + */ + public static final String FGMGR_EVT_UPDATE_MEMBER = "12009"; + + /** + * 邀请事件 + */ + public static final String FGMGR_EVT_INVITATION = "12010"; + + /** + * 更新玩家网络 + */ + public static final String FGMGR_EVT_UPDATE_NET = "update_net"; + /** + * 更新邮件提示 + */ + public static final String FGMGR_EVT_UPDATE_MAILTIP = "update_mail_tip"; + + + public void handel(Session sender, ITObject params, int gid){ + + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/SessionManager.java b/group_mgr/src/main/java/com/mgr/group/SessionManager.java new file mode 100644 index 0000000..639a4e0 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/SessionManager.java @@ -0,0 +1,81 @@ +package com.mgr.group; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.mgr.group.data.User; +import com.taurus.core.util.json.JSONUtils; +import com.taurus.permanent.data.Session; + +/** + * 当前节点 玩家session管理类 + * + * + */ +public class SessionManager { + + private ConcurrentMap sessionMap = null; + + public SessionManager() { + this.sessionMap = new ConcurrentHashMap(); + } + + /** + * 通过sessionid获取User + * @param sessionid + * @return + */ + public User getUser(Session sessionid) { + return this.sessionMap.get(sessionid); + } + + /** + * 增加session + * @param session + * @param player + */ + public void putUser(Session session, User user) { + this.sessionMap.put(session, user); + } + + /** + * 删除session + * @param session + */ + public User delSession(Session session) { + Global.logger.info("delSession----------------清理session:"+session.toString()); + if(session == null)return null; + session.setHashId(null); + User user =this.sessionMap.remove(session); + return user; + } + + /** + * 当前圈子在线人数 + * @return + */ + public int size() { + return this.sessionMap.size(); + } + + /** + * 断线 + * @param sender + */ + public void disconnect(Session sender) { + User user = this.delSession(sender); + if (user == null) { + return; + } + user.group.enqueueRunnable(new Runnable() { + + @Override + public void run() { + if (user.sender == sender) { + user.isConnect = false; + } + } + }); + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/WebMain.java b/group_mgr/src/main/java/com/mgr/group/WebMain.java new file mode 100644 index 0000000..689df49 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/WebMain.java @@ -0,0 +1,34 @@ +package com.mgr.group; + +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.DefaultConstants; +import com.taurus.web.TWebServer; + +public class WebMain extends Extension { + + public void onStart() { + DefaultConstants.SERVER_CFG_FILE = TWebServer.me().getContextRealPath()+"/" + DefaultConstants.SERVER_CFG_FILE; + TPServer.me().start(); + } + + @Override + public void onStop() { + TPServer.me().shutdown(); + } + + + + + @Override + public void configRoute(Routes me) { + // TODO Auto-generated method stub + + } + + public int getConcurrentSize() { + return Global.sessionMgr.size(); + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/CommandData.java b/group_mgr/src/main/java/com/mgr/group/data/CommandData.java new file mode 100644 index 0000000..0d0c846 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/CommandData.java @@ -0,0 +1,36 @@ +package com.mgr.group.data; + +import com.taurus.core.entity.ITObject; + +public class CommandData { + public static final int ADD_ROOM = 1; + public static final int UPDATE_ROOM = 2; + public static final int DEL_ROOM = 3; + + private static final String TYPE_KEY = "$ct"; + public ITObject param; + /**1添加 2更新 3删除*/ + public int type = ADD_ROOM; + + public void setData(int type,ITObject param) { + if(type>=this.type) { + this.type = type; + this.param = param; + this.param.putInt(TYPE_KEY, type); + } + } + +// public void send(Group group,List list) { +// this.param.putInt(TYPE_KEY, type); +// if(type==1) { +// MainServer.instance.sendEvent(Router.FGMGR_EVT_UPDATE_ROOM, param, list); +// }else { +// MainServer.instance.sendEvent(Router.FGMGR_EVT_DEL_ROOM, param, list); +// } +// } + + + + + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/Group.java b/group_mgr/src/main/java/com/mgr/group/data/Group.java new file mode 100644 index 0000000..bb0c0f2 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/Group.java @@ -0,0 +1,361 @@ +package com.mgr.group.data; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.data.bean.GroupBean; +import com.data.bean.GroupPlayBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupPlayCache; +import com.mgr.group.Global; +import com.mgr.group.Router; +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.StringUtil; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Session; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Pipeline; + +public class Group implements Runnable { + public int id; + public String group_key = ""; + /** + * 圈主 + */ + public int owner; + /** + * 圈主session + */ + public String owner_session; + /** + * 圈主钻石 + */ + public int owner_diamo; + /** + * 是否被激活 + */ + public volatile boolean isActive = false; + /** + * 是否被销毁 + */ + public volatile boolean isDestroy = false; + private Thread updateThread; + public volatile long lastTime; + final Queue updateHandleList = new LinkedList(); + public ConcurrentMap userMap; + public GroupPlayCache playCache; + public RoomCache roomCache; + public Map cmdMap = new HashMap<>(); + private long lastSendTime; +// private long lastUpdateOnline; + + public Group(int id) { + this.userMap = new ConcurrentHashMap<>(); + this.id = id; + this.group_key = GroupCache.genKey(id); + String pay_type = Redis.use("group1_db11").hget(group_key, "pay_type"); + this.playCache = new GroupPlayCache(id, Integer.parseInt(pay_type)); + this.roomCache = new RoomCache(id); + } + + public synchronized void start() { + if (isActive || isDestroy) + return; + isActive = true; + GroupBean gb = GroupCache.getGroup(id); + this.owner = gb.owner; + this.owner_session = AccountCache.genKey(owner); + String _diamo = Redis.use("group1_db0").hget(owner_session, "diamo"); + if(StringUtil.isNotEmpty(_diamo)) { + owner_diamo = Integer.parseInt(_diamo); + } + updateThread = new Thread(this, this.group_key); + updateThread.start(); + lastTime = System.currentTimeMillis(); + } + + private void handleTask(Runnable tem) { + if (isDestroy) { + return; + } + + try { + tem.run(); + } catch (Throwable t) { + Global.logger.error("[" + id + "] exception!", t); + } + + handleBroadcast(); + } + + public void handleBroadcast() + { + long curTime = System.currentTimeMillis(); + if(curTime - lastSendTime >=2000) { + try { + if (cmdMap.size()>0) { + List list = this.getSessionList(); + if(list.size()>0) { + ITArray arr = TArray.newInstance(); + ITObject param = TObject.newInstance(); + param.putTArray("cmds", arr); + for (Entry entry : cmdMap.entrySet()) { + CommandData cmd = entry.getValue(); + arr.addTObject(cmd.param); + } + TPServer.me().getController().sendEvent(Router.FGMGR_EVT_UPDATE_ROOM, 0, param, list); + } + } + List u_list = null; + synchronized (userMap) { + u_list = new ArrayList(userMap.values()); + } + List r_list = null; + Jedis jedis = Redis.use("group1_db10").getJedis(); + try { + Pipeline pip = jedis.pipelined(); + for (User user : u_list) { + pip.hget(user.gm_key, "hp"); + } + r_list = pip.syncAndReturnAll(); + + }finally { + jedis.close(); + } + + for(int i=0;i 0) { + this.lastTime = System.currentTimeMillis(); + Runnable tem = null; + synchronized (updateHandleList) { + tem = updateHandleList.poll(); + } + if (tem != null){ + try { + handleTask(tem); + } catch (Throwable t) { + Global.logger.error("[" + id + "] exception!", t); + } + } + } + + handleBroadcast(); + + if (isDestroy) + continue; + Thread.sleep(5); + } catch (InterruptedException e) { + isActive = false; + Global.logger.error("[" + id + "] thread interrupted!"); + } catch (Throwable t) { + //isActive = false; + Global.logger.error("[" + id + "] exception!", t); + } + } + } + + public void enqueueRunnable(Runnable runnable) { + if (runnable == null) + return; + synchronized (updateHandleList) { + updateHandleList.add(runnable); + } + } + + public void addRoomCommand(String roomid,int type,ITObject param) { + CommandData cmd = cmdMap.get(roomid); + if(cmd==null) { + cmd = new CommandData(); + cmdMap.put(roomid, cmd); + } + cmd.setData(type, param); + } + + public ITObject getInfo(int lev,int uid) { + ITObject info = TObject.newInstance(); + + GroupBean gb = GroupCache.getGroup(this.group_key); + info.putBoolean("ban", gb.ban == 1 ? true : false); + String joins_key = GroupCache.genJoinsKey(id); + int joins = Redis.use("group1_db11").scard(joins_key).intValue(); + info.putInt("joins", joins); + info.putInt("diamo", owner_diamo); + info.putInt("dissolve_opt", gb.dissolve_opt); + info.putInt("kick_opt", gb.kick_opt); + info.putBoolean("ban_chat1", gb.ban_chat1); + info.putBoolean("ban_chat2", gb.ban_chat2); + info.putInt("ban_apply", gb.ban_apply); + info.putInt("exit_opt", gb.exit_opt); + info.putInt("option", gb.option); + ITArray rooms = this.roomCache.getRoomList(); + info.putTArray("rooms", rooms); + ITArray arrPlayList = TArray.newInstance(); + Utils.arrayCopy(this.playCache.getPlayList(lev,uid), arrPlayList); + info.putTArray("play_list", arrPlayList); + return info; + } + + public boolean delRoom(String roomid) { + String key = "room:" + roomid; + boolean result =false; + + if (this.roomCache.delBean(key)) { + this.roomCache.updateRoom(); + result = true; + } + String grooms_key = GroupCache.genRoomsKey(id); + Redis.use("group1_db11").zrem(grooms_key, key); + return result; + } + + public Room updateRoom(String roomid) { + String key = "room:" + roomid; + String grooms_key = GroupCache.genRoomsKey(id); + Room room = this.roomCache.getBean(key); + this.roomCache.updateRoom(); + if (room == null) { + Redis.use("group1_db11").zrem(grooms_key, key); + } else { + Redis.use("group1_db11").zadd(grooms_key, room.priorityValue, key); + } + + return room; + } + + public Room addRoom(String roomid) { + String key = "room:" + roomid; + String grooms_key = GroupCache.genRoomsKey(id); + Room room = this.roomCache.getBean(key); + + this.roomCache.updateRoom(); + if (room == null) { + Redis.use("group1_db11").zrem(grooms_key, key); + } else { + Redis.use("group1_db11").zadd(grooms_key, room.priorityValue, key); + } + return room; + } + + public GroupPlayBean addPlay(int pid) { + GroupPlayBean gp = this.playCache.getBean(pid); + this.playCache.updatePlay(); + return gp; + } + + public boolean delPlay(int pid) { + boolean del = this.playCache.delBean(pid); + this.playCache.updatePlay(); + return del; + } + + /** + * 广播消息到客户端 + * + * @param cmd 协议指令 + * @param param 协议数据 + */ + public void broadCastToClient(String cmd, ITObject param) { + if (!isActive) + return; + List list = getSessionList(); + if (list == null || list.size() == 0) + return; + TPServer.me().getController().sendEvent(cmd, param, list); + } + + public List getSessionList() { + List list = new ArrayList(); + List tem = null; + synchronized (userMap) { + tem = new ArrayList(userMap.values()); + } + + for (User user : tem) { + if (user.isConnect) { + list.add(user.sender); + } + } + return list; + } + + public List getSessionListByMgr() { + List list = new ArrayList(); + List tem = null; + synchronized (userMap) { + tem = new ArrayList(userMap.values()); + } + + for (User user : tem) { + if (user.isConnect && user.lev < 3) { + list.add(user.sender); + } + } + return list; + } + + public void destroy() { + if (this.isDestroy) + return; + this.isDestroy = true; + Global.groupMap.remove(id); + Collection tem = userMap.values(); + for (User user : tem) { + if (user.isConnect) { + TPServer.me().getController().disconnect(user.sender); + } + } + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/Player.java b/group_mgr/src/main/java/com/mgr/group/data/Player.java new file mode 100644 index 0000000..92851b4 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/Player.java @@ -0,0 +1,45 @@ +package com.mgr.group.data; + +import com.data.bean.AccountBean; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +/** + * 基本玩家对象 + * + * + */ +public class Player extends AccountBean{ + /** + * 座位 + */ + public int seat = 0; + public int off_time = 0; + public long hp =0; + + public int queueid = 0; + + public int seeid = 0; + + private ITObject playerData = new TObject(); + + /** + * 获取玩家信息 + * @return + */ + public ITObject getInfo() { + playerData.putInt("aid", this.id); + playerData.putUtfString("nick", this.nick); + playerData.putUtfString("portrait", this.portrait); + playerData.putInt("seat", this.seat); + playerData.putInt("off_time", off_time); + playerData.putLong("hp", hp); + playerData.putInt("queueid",queueid); + playerData.putInt("seeid",seeid); + return playerData; + } + + public String toString() { + return redis_key; + } +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/PlayerCache.java b/group_mgr/src/main/java/com/mgr/group/data/PlayerCache.java new file mode 100644 index 0000000..0020d2c --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/PlayerCache.java @@ -0,0 +1,25 @@ +package com.mgr.group.data; + +import com.data.bean.BaseBean; +import com.data.cache.AccountCache; + +public class PlayerCache extends AccountCache{ + + protected BaseBean newBean() { + return new Player(); + } + + static PlayerCache inst; + + + public static Player getPlayer(int id) { + if(inst==null)inst = new PlayerCache(); + return inst.getBean(id); + } + + public static Player getPlayer(String session) { + if(inst==null)inst = new PlayerCache(); + return inst.getBean(session); + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/Room.java b/group_mgr/src/main/java/com/mgr/group/data/Room.java new file mode 100644 index 0000000..e97a676 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/Room.java @@ -0,0 +1,179 @@ +package com.mgr.group.data; + +import java.util.Map; + +import com.data.bean.BaseBean; +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.StringUtil; +import com.taurus.core.util.Utils; + +/** + * 基本房间对象 + * + * + */ +public class Room extends BaseBean { + /** + * 房间ID + */ + public String roomid = ""; + /** + * 玩家列表ID映射 + */ + public final ITArray players = TArray.newInstance(); + /** + * 房间最大人数 + */ + public int maxPlayers; + + public int limitInRoom; + + /** + * 圈子玩法ID + */ + public int groupPlayId; + /** + * 局數 + */ + public int round = 0; + /** + * 最大回合数 + */ + public int maxRound = 0; + /** + * 0 未开始 1开始 2标记需要删除 3删除 + */ + public int status = 0; + /** + * 0 关闭 1打开 + */ + public int open = 1; + + /** + * 房间匹配权重 + * pid open status 剩余空位 + * 11 1 1 00 + */ + public int priorityValue = 1; + + /* + 假房间 + */ + public boolean fake = false; + /** + * 最后操作时间 + */ + public long lastTime = 0; + + public ITObject data = TObject.newInstance(); + + private void setInfo() { + data.putUtfString("id", roomid); + data.putInt("round", round); + data.putInt("times", maxRound); + data.putInt("status", status); + data.putInt("maxPlayers", maxPlayers); + data.putInt("pid", groupPlayId); + ITArray arr = TArray.newInstance(); + Utils.arrayCopy(players, arr); + data.putTArray("plist", arr); + data.putInt("limitInRoom", limitInRoom); + + } + + public void fillData(Map redis_map) { + String _id = redis_map.get("id"); + String _status = redis_map.get("status"); + if (StringUtil.isEmpty(_id)) { + this.del = true; + return; + } + if(StringUtil.isNotEmpty(_status)) { + this.status = Integer.parseInt(_status); + } + + if (this.status == 2 || this.status == 3) { + this.del = true; + return; + } + this.roomid = _id; + this.id = Integer.parseInt(_id); + this.groupPlayId = Integer.parseInt(redis_map.get("gpid")); + this.round = Integer.parseInt(redis_map.get("round")); + this.maxRound = Integer.parseInt(redis_map.get("times")); + this.maxPlayers = Integer.parseInt(redis_map.get("maxPlayers")); + this.limitInRoom = Integer.parseInt(redis_map.get("limitInRoom")); + this.open = Integer.parseInt(redis_map.get("open")); + if (StringUtil.isEmpty(redis_map.get("fake"))) + { + this.fake = false; + } + else { + this.fake = true; + } + + this.loadRedisPlayer(redis_map.get("players"), redis_map.get("seats"),redis_map); + setInfo(); + updatePriority(); + } + + /** + * 重新加载玩家 + */ + private void loadRedisPlayer(String players_json, String seats_json,Map redis_map) { + players.clear(); + if (StringUtil.isEmpty(players_json)) + return; + ITArray players = TArray.newFromJsonData(players_json); + + ITArray seats = TArray.newFromJsonData(seats_json); + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + Player player = PlayerCache.getPlayer(player_id); + player.seat = seats.getInt(i); + Object tem = redis_map.get("net_"+player_id); + player.off_time =tem ==null?0:(int)(Long.parseLong((String)tem)/1000); + + String strGroup = redis_map.get("group"); + int groupId = strGroup ==null?0:(Integer.parseInt((String)strGroup)); + String gm_key1 = GroupMemberCache.genKey(groupId, player.id); + if (this.fake) + { + String strHp = Redis.use("group1_db10").hget("fake_"+player.id, "fake_hp"); + player.hp = strHp ==null?0:(Long.parseLong((String)strHp)); + } + else { + String strHp = Redis.use("group1_db10").hget(gm_key1, "hp"); + player.hp = strHp ==null?0:(Long.parseLong((String)strHp)); + } + + String strQuid = Redis.use("group1_db10").hget(gm_key1, "queueid"); + player.queueid = strQuid ==null?0:(Integer.parseInt((String)strQuid)); + + String strseeid = Redis.use("group1_db10").hget(gm_key1, "seeid"); + player.seeid = strseeid ==null?0:(Integer.parseInt((String)strseeid)); + + this.players.addTObject(player.getInfo()); + } + } + + /** + * 房间匹配权重 + */ + public void updatePriority() { + if (this.status == 2 || this.status == 3) { + this.priorityValue = 0; + return; + } + int t_status = this.status == 0 ? 1 : 0; + int t_mc = this.players.size() + 1; + t_mc = this.players.size() == this.maxPlayers ? 0 : t_mc; + this.priorityValue = this.groupPlayId * 10000 + this.open * 1000 + t_status * 100 + t_mc; + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/RoomCache.java b/group_mgr/src/main/java/com/mgr/group/data/RoomCache.java new file mode 100644 index 0000000..a43b9d7 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/RoomCache.java @@ -0,0 +1,87 @@ +package com.mgr.group.data; + +import java.util.Map.Entry; +import java.util.Set; + +import com.data.bean.BaseBean; +import com.data.cache.BaseCache; +import com.data.cache.GroupCache; +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.Utils; + +import redis.clients.jedis.Jedis; + +public class RoomCache extends BaseCache{ + private int groupId; + private long last_time; + private ITArray rooms; + + protected RoomCache(int groupId) { + super("room:","group1_db0"); + this.groupId = groupId; + this.fillSize = 6; + this.readTime = 1; + rooms = TArray.newInstance(); + } + + @Override + protected BaseBean newBean() { + return new Room(); + } + + public final void updateRoom() { + rooms.clear(); + Set> set = this.mapById.entrySet(); + for(Entry entry : set) { + Room gp =(Room)entry.getValue(); + if(!gp.del) { + rooms.addTObject(gp.data); + }else { + this.mapById.remove(gp.id); + this.mapByKey.remove(gp.redis_key); + } + } + } + + /** + * 获取房间列表 + * @return + */ + public final ITArray getRoomList(){ + if(System.currentTimeMillis() - last_time < 10000) { + ITArray arr = TArray.newInstance(); + Utils.arrayCopy(rooms, arr); + return arr; + } + + rooms.clear(); + last_time = System.currentTimeMillis(); + String grooms_key = GroupCache.genRoomsKey(groupId); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Set rooms = jedis11.zrangeByScore(grooms_key, 100000, 2000000); + try { + for (String tem : rooms) { + Room room = this.getBean(tem); + if(room==null) { + jedis11.zrem(grooms_key, tem); + continue; + } + room.del = false; + jedis11.zadd(grooms_key, room.priorityValue, tem); + this.rooms.addTObject(room.data); + } + jedis11.zremrangeByScore(grooms_key, 0, 0); + }finally { + jedis11.close(); + } + + ITArray arr = TArray.newInstance(); + Utils.arrayCopy(this.rooms, arr); + return arr; + } + +} diff --git a/group_mgr/src/main/java/com/mgr/group/data/User.java b/group_mgr/src/main/java/com/mgr/group/data/User.java new file mode 100644 index 0000000..bccd632 --- /dev/null +++ b/group_mgr/src/main/java/com/mgr/group/data/User.java @@ -0,0 +1,135 @@ +package com.mgr.group.data; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import com.data.bean.AccountBean; +import com.data.cache.AccountCache; +import com.mgr.group.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.plugin.redis.Redis; +import com.taurus.core.util.StringUtil; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Session; + +/** + * 长连接用户 + * + */ +public class User { + public int uid; + public String session_key; + /** + * 合伙人等级 + */ + public int partnerLev; + /** + * 职位等级 + */ + public int lev; + + public volatile Group group = null; + /** + * 是否正在链接 + */ + public volatile boolean isConnect = false; + /** + * mpnet session + */ + public volatile Session sender = null; + + public long hp =0; + public int mail_tip = 0; + public int ban =0; + + public int queueid = 0; + + public int seeid = 0; + + public String gm_key; + + /**最后邀请时间*/ + public long last_invitation_time; + /**拒绝邀请时间*/ + public long invitation_refuse_time; + public int last_invitation_id; + + /**最后刷新时间*/ + public long last_refresh_time; + + public boolean updateOffline; + + private List onlineList = new ArrayList<>(); + + public ITArray getOnlineList(){ + if((System.currentTimeMillis() - last_refresh_time)>=2000) { + last_refresh_time = System.currentTimeMillis(); + onlineList.clear(); + Collection tem = group.userMap.values(); + for (User user : tem) { + if (user!=this&&user.isConnect&&user.ban==0) { + String room = Redis.use("group1_db0").hget(user.session_key, "room"); + if(StringUtil.isEmpty(room)) { + onlineList.add(user); + } + } + } + } + Collections.shuffle(onlineList); + int size = Math.min(onlineList.size(), 9); + ITArray arr = TArray.newInstance(); + for(int i=0;i + + + + taurus-web + com.taurus.web.WebFilter + + main + com.mgr.group.WebMain + + + + + taurus-web + /* + + diff --git a/group_mgr/src/main/webapp/config/log4j.properties b/group_mgr/src/main/webapp/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/group_mgr/src/main/webapp/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/group_mgr/src/main/webapp/config/mgr-config.xml b/group_mgr/src/main/webapp/config/mgr-config.xml new file mode 100644 index 0000000..5d3467a --- /dev/null +++ b/group_mgr/src/main/webapp/config/mgr-config.xml @@ -0,0 +1,6 @@ + + + 192.168.14.1:8050 + 1000 + true + \ No newline at end of file diff --git a/group_mgr/src/main/webapp/config/taurus-core.xml b/group_mgr/src/main/webapp/config/taurus-core.xml new file mode 100644 index 0000000..ada2d5e --- /dev/null +++ b/group_mgr/src/main/webapp/config/taurus-core.xml @@ -0,0 +1,98 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.134.123.86:8060/wb_game + root + cssq@2020 + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/group_mgr/src/main/webapp/config/taurus-permanent.xml b/group_mgr/src/main/webapp/config/taurus-permanent.xml new file mode 100644 index 0000000..b9dfbb3 --- /dev/null +++ b/group_mgr/src/main/webapp/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 1 + + 512 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 1 + 3 + 3 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + false +
0.0.0.0
+ 80 +
+ + + + extension - group_mgr + com.mgr.group.MainServer + + + + + Sys + 2 + 8 + 60000 + 20000 + + + + + Ext + 2 + 8 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/group_mgr/src/test/java/group_room_mgr/Main.java b/group_mgr/src/test/java/group_room_mgr/Main.java new file mode 100644 index 0000000..7842b6f --- /dev/null +++ b/group_mgr/src/test/java/group_room_mgr/Main.java @@ -0,0 +1,12 @@ +package group_room_mgr; + +import com.taurus.web.JettyServer; + +public class Main { + + public static void main(String[] args) { + new JettyServer("src/main/webapp",8082,"/").start(); + + } + +} diff --git a/pack_tools/pom.xml b/pack_tools/pom.xml new file mode 100644 index 0000000..81968eb --- /dev/null +++ b/pack_tools/pom.xml @@ -0,0 +1,119 @@ + + 4.0.0 + com.pack + pack_tools + war + 1.0.0 + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 3.8.1 + test + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + mysql + mysql-connector-java + 8.0.16 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + + com.aliyun.oss + aliyun-sdk-oss + 3.8.0 + + + + + com.alibaba + fastjson + 1.2.62 + + + + + pack_tools + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + diff --git a/pack_tools/src/main/java/com/pack/MainServer.java b/pack_tools/src/main/java/com/pack/MainServer.java new file mode 100644 index 0000000..0b6fba7 --- /dev/null +++ b/pack_tools/src/main/java/com/pack/MainServer.java @@ -0,0 +1,63 @@ +package com.pack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; + +import com.pack.service.CommandService; +import com.pack.service.PackUtilService; +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; + +public class MainServer extends Extension { + + public static Element packConfig; + public static Element ossListConfig; + public static String probjectName; + public MainServer() { + super(); + String path = System.getProperty("WORKDIR"); + File file = new File(path+"/config/pack-config.xml"); + if(file.exists()) { + try { + InputStream is = new FileInputStream(file); + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(is); + packConfig = document.getRootElement(); + ossListConfig = packConfig.getChild("oss-list"); + probjectName = packConfig.getChildTextTrim("project-name"); + }catch (Exception e) { + e.printStackTrace(); + } + } + + } + + + + + @Override + public void configRoute(Routes me) { + + me.add("cmd", CommandService.class); + me.add("pack", PackUtilService.class); + } + + @Override + public void onStart() { + + + } + + @Override + public void onStop() { + // TODO Auto-generated method stub + + + } + +} diff --git a/pack_tools/src/main/java/com/pack/Utils.java b/pack_tools/src/main/java/com/pack/Utils.java new file mode 100644 index 0000000..045b08b --- /dev/null +++ b/pack_tools/src/main/java/com/pack/Utils.java @@ -0,0 +1,98 @@ +package com.pack; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.List; + +import org.jdom.Element; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.CannedAccessControlList; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; + +import redis.clients.jedis.Jedis; + +public class Utils { + + public static final String[] svr_list= {"local","test","pro"}; + + public static ITObject getGameData(Jedis jedis1,int game_id,boolean version_add) { + List list = jedis1.hmget("game:"+game_id,"id","name","bundle","version"); + ITObject obj = TObject.newInstance(); + obj.putInt("game_id", Integer.parseInt(list.get(0))); + obj.putUtfString("name", list.get(1)); + obj.putUtfString("bundle", list.get(2)); + String version = list.get(3); + if(version_add) { + String tem[] = version.split("\\."); + version = tem[0]+"."+tem[1]+"."+(Integer.parseInt(tem[2])+1); + } + obj.putUtfString("version", version); + return obj; + } + + public static byte[] httpGet(String url) { + try { + URL realUrl = new URL(url); + // 打开和URL之间的连接 + HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection(); + if(conn.getResponseCode() == 200) { + InputStream is = conn.getInputStream(); + ByteArrayOutputStream o = new ByteArrayOutputStream(1024); + int i = 1024; + byte[] buf = new byte[i]; + + while ((i = is.read(buf, 0, i)) > 0) { + o.write(buf, 0, i); + } + return o.toByteArray(); + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + + public static void uploadOssPack(String objectName,String path) throws Exception{ + List list = MainServer.ossListConfig.getChildren(); + for (Object o : list) { + Element ossConfig = (Element)o; + String endpoint = ossConfig.getChildTextTrim("endpoint"); + String accessKeyId = ossConfig.getChildTextTrim("accessKeyId"); + String accessKeySecret = ossConfig.getChildTextTrim("accessKeySecret"); + String bucketName = ossConfig.getChildTextTrim("bucketName"); + // 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + FileInputStream is = new FileInputStream(path+"/"+objectName); + String temName = MainServer.probjectName+"/" + objectName; + ossClient.putObject(bucketName, temName, is); + is.close(); + ossClient.setObjectAcl(bucketName, temName, CannedAccessControlList.PublicRead); + // 关闭OSSClient。 + ossClient.shutdown(); + } + + } + + + public static void uploadOss(Element ossConfig,String objectName,byte[] bytes) throws Exception{ + String endpoint = ossConfig.getChildTextTrim("endpoint"); + String accessKeyId = ossConfig.getChildTextTrim("accessKeyId"); + String accessKeySecret = ossConfig.getChildTextTrim("accessKeySecret"); + String bucketName = ossConfig.getChildTextTrim("bucketName"); + // 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(bytes)); + ossClient.setObjectAcl(bucketName, objectName, CannedAccessControlList.PublicRead); + // 关闭OSSClient。 + ossClient.shutdown(); + } +} diff --git a/pack_tools/src/main/java/com/pack/service/CommandService.java b/pack_tools/src/main/java/com/pack/service/CommandService.java new file mode 100644 index 0000000..80e0879 --- /dev/null +++ b/pack_tools/src/main/java/com/pack/service/CommandService.java @@ -0,0 +1,69 @@ +package com.pack.service; + +import com.data.util.ErrorCode; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.util.StringUtil; +import com.taurus.web.Controller; + +public class CommandService extends Controller { + + + @ActionKey(value = "get_user") + public final void getUser() throws Exception { + ITObject params = this.getParams(); + String key = params.getUtfString("key"); + int uid = params.getInt("uid"); + ITObject resData = TObject.newInstance(); + String res_v = null; + switch(key) { + case "acc": + res_v = Redis.use("group1_db0").hget("{user}:"+uid,"acc"); + break; + } + res_v = StringUtil.isEmpty(res_v)?StringUtil.Empty:res_v; + resData.putUtfString("value", res_v); + this.sendResponse(ErrorCode._SUCC, resData); + } + + + @ActionKey(value = "set_user") + public final void setUser() throws Exception { + ITObject params = this.getParams(); + String key = params.getUtfString("key"); + int uid = params.getInt("uid"); + int value = params.getInt("value"); + String sql = null; + switch(key) { + case "diamo": + sql = String.format("update account set diamo=%s where id=%s", value,uid); + if(DataBase.use().executeUpdate(sql)==0) { + this.sendResponse(ErrorCode._FAILED, null); + return; + } + Redis.use("group1_db0").hset("{user}:"+uid, "diamo", value+""); + + break; + case "type": + sql = String.format("update account set type=%s where id=%s", value,uid); + if(DataBase.use().executeUpdate(sql)==0) { + this.sendResponse(ErrorCode._FAILED, null); + return; + } + Redis.use("group1_db0").hset("{user}:"+uid, "type", value+""); + break; + case "mng": + sql = String.format("update account set mng=%s where id=%s", value,uid); + if(DataBase.use().executeUpdate(sql)==0) { + this.sendResponse(ErrorCode._FAILED, null); + return; + } + Redis.use("group1_db0").hset("{user}:"+uid, "mng", value+""); + break; + } + this.sendResponse(ErrorCode._SUCC, null); + } +} diff --git a/pack_tools/src/main/java/com/pack/service/PackServerProject.java b/pack_tools/src/main/java/com/pack/service/PackServerProject.java new file mode 100644 index 0000000..48eac89 --- /dev/null +++ b/pack_tools/src/main/java/com/pack/service/PackServerProject.java @@ -0,0 +1,103 @@ +package com.pack.service; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.util.Logger; + +public class PackServerProject extends HttpServlet{ + /** + * + */ + private static final long serialVersionUID = 990146541904048926L; + + + private static final Object lock = new Object(); + + private static final String[] project_path = {"E:/elipse_work/leying/game_java/","E:/elipse_work/leying/server_web/"}; + private static final String[] upload_path = {"E:/upload/leying/update_game_java/","E:/upload/leying/"}; + + private static void findall(HttpServletResponse resp) throws Exception{ + ITArray arr = DataBase.use("db2").executeQueryByTArray("select * from leying"); + String t = ""; + for (int i = 0; i < arr.size(); i++) { + ITObject obj = arr.getTObject(i); + int id = obj.getInt("id"); + String name = obj.getUtfString("name"); + String file_name = obj.getUtfString("file_name"); + String upload_path = obj.getUtfString("upload_path"); + String pro_path = obj.getUtfString("pro_path"); + t +=String.format("", name,pro_path,upload_path,file_name,id); + } + t+="
项目名称项目路径上传路径包文件名操作
%s%s%s%s打包
"; + resp.getOutputStream().write(t.getBytes("GBK")); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + if(req.getParameterMap().containsKey("id")){ + try { + int id = Integer.parseInt(req.getParameter("id")); + synchronized (lock) { + ITArray arr = DataBase.use("db2").executeQueryByTArray("select * from leying where id="+id); + if(arr.size()>0){ + ITObject obj = arr.getTObject(0); + int type = obj.getInt("type"); + String name = obj.getUtfString("name"); + Logger log = Logger.getLogger(name); + String path = project_path[type-1]; + String file_name = obj.getUtfString("file_name"); + String upload = upload_path[type-1] + obj.getUtfString("upload_path")+"/"+file_name; + PackUtilService.exeCmd(path+"build.bat " +obj.getUtfString("pro_path")+" "+file_name+" " +upload ,log); + PackUtilService.exeCmd("svn update "+upload_path[1], log); + String tem_path = path + obj.getUtfString("pro_path")+"/target/"+file_name; + Files.copy(new File(tem_path).toPath(), new File(upload).toPath(),StandardCopyOption.REPLACE_EXISTING); + PackUtilService.exeCmd(upload_path[type-1]+"svn_add.bat \""+getIpAddr(req)+"["+name+"]\"",log); + String t="

打包成功!

返回"; + resp.getOutputStream().write(t.getBytes("GBK")); + } + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }else { + try { + findall(resp); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + private static String getIpAddr(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } +} diff --git a/pack_tools/src/main/java/com/pack/service/PackUtilService.java b/pack_tools/src/main/java/com/pack/service/PackUtilService.java new file mode 100644 index 0000000..c0dfcdf --- /dev/null +++ b/pack_tools/src/main/java/com/pack/service/PackUtilService.java @@ -0,0 +1,289 @@ +package com.pack.service; + +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.jdom.Element; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.parser.Feature; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.pack.MainServer; +import com.pack.Utils; +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.routes.ActionKey; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.web.Controller; + +import redis.clients.jedis.Jedis; + +public class PackUtilService extends Controller{ + private static final Object lock = new Object(); + + static void exeCmd(String cmdCode,Logger log) { + BufferedReader br = null; + try { + Process p = Runtime.getRuntime().exec(cmdCode); + br = new BufferedReader(new InputStreamReader(p.getInputStream(), "GBK")); + String line; + while ((line = br.readLine()) != null) { + log.info(line); + } + p.waitFor(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + private void asynBuild(String threadName,String cmd,String os,ITArray arr) { + Thread thread = new Thread(new Runnable() { + + @Override + public void run() { + logger.info("building "+os+"..."); + exeCmd(cmd,logger); + for (int i = 0; i < arr.size(); i++) { + ITObject obj = arr.getTObject(i); + String tem_ver = obj.getUtfString("version"); + String bundle = obj.getUtfString("bundle"); + bundle = bundle.replaceAll("\\.", "/"); + String obj_name = "/"+bundle+"/asset_pack"+tem_ver+".bytes"; + logger.info(obj.getUtfString("name")+"["+tem_ver + "] pack to oss..."); + try { + String path = MainServer.packConfig.getChildTextTrim("temp-pack-path"); + Utils.uploadOssPack(os+obj_name, path); + } catch (Exception e) { + logger.error(e); + buildCount ++; + throw new RuntimeException(e); + } + logger.info(obj.getUtfString("name")+"["+tem_ver + "] upload oss ok!"); + } + + buildCount ++; + } + }); + thread.setName(threadName + "-" + os); + thread.start(); + + } + private volatile int buildCount; + @ActionKey(value = "pack_extend") + public final void packExtend() throws Exception { + ITObject params = this.getParams(); + ITArray list = params.getTArray("list"); + if(list.size()==0) { + this.sendResponse(0, null); + return; + } + String threadName = this.getRemoteAddr()+"(extend)"; + Thread.currentThread().setName(threadName); + synchronized(lock) { + buildCount = 0; + int svr_type = params.getInt("svr_type"); + List> redis_list = new ArrayList<>(); + for(int i=0;i()); + } + logger.info("start build pack ..."); + + String svr = Utils.svr_list[svr_type]; + Jedis jedis1 = Redis.use(svr+"_db1").getJedis(); + try { + ITArray arr = TArray.newInstance(); + for(int i=0;i redis_map = redis_list.get(i); + String ver = gameObj.getUtfString("version"); + redis_map.put("version", ver); + arr.addTObject(gameObj); + } + String temp_path = MainServer.packConfig.getChildTextTrim("temp-pack-path"); + ITObject tem = TObject.newInstance(); + tem.putTArray("data", arr); + tem.putUtfString("hotpath", temp_path); + String data_path = MainServer.packConfig.getChildTextTrim("data-path"); + FileOutputStream fos = new FileOutputStream(data_path); + fos.write(StringUtil.getBytes(tem.toJson())); + fos.close(); + String cmd_params = " \""+data_path+"\""; + String bat_path = MainServer.packConfig.getChildTextTrim("android-path")+"build-extend.bat"; + String cmd = bat_path + cmd_params + " \"android\""; + asynBuild(threadName,cmd,"Android",arr); + bat_path = MainServer.packConfig.getChildTextTrim("ios-path")+"build-extend.bat"; + cmd = bat_path + cmd_params + " \"ios\""; + asynBuild(threadName,cmd,"iOS",arr); + bat_path = MainServer.packConfig.getChildTextTrim("win-path")+"build-extend.bat"; + cmd = bat_path + cmd_params + " \"win\""; + asynBuild(threadName,cmd,"Win",arr); + + while(buildCount < 3) { + Thread.sleep(100); + } + + for (int i = 0; i < redis_list.size(); i++) { + Map map = redis_list.get(i); + int game_id = list.getInt(i); + String key = "game:"+game_id; + jedis1.hmset(key, map); + jedis1.hincrBy(key, "cache_ver", 1); + } + }finally { + jedis1.close(); + } + } + + + } + + + @SuppressWarnings("unchecked") + @ActionKey(value = "pack_base") + public final void packBase() throws Exception { + ITObject params = this.getParams(); + ITArray list = params.getTArray("list"); + if(list.size()==0) { + this.sendResponse(0, null); + return; + } + String threadName = this.getRemoteAddr()+"(base)"; + Thread.currentThread().setName(threadName); + synchronized (lock) { + buildCount = 0; + logger.info("start build pack ..."); + List config_list = new ArrayList<>(); + Element init_json_list = MainServer.packConfig.getChild("init-json-list"); + @SuppressWarnings("rawtypes") + List base_config = init_json_list.getChildren(); + for (int i = 0; i < base_config.size(); i++) { + Element elem = (Element)base_config.get(i); + String url = elem.getChildTextTrim("url"); + String oss_key = elem.getChildTextTrim("oss_key"); + String init_json = elem.getChildTextTrim("init_json"); + BaseConfigData bcd = new BaseConfigData(); + byte[] bytes = Utils.httpGet(url); + if(bytes==null)continue; + String str = StringUtil.getString(bytes); + bcd.init_config_map = JSON.parseObject(str,LinkedHashMap.class, Feature.OrderedField); + Map obj = (Map) bcd.init_config_map.get("Android"); + bcd.old_ver = (String) obj.get("version"); + String v_tem[] = bcd.old_ver.split("\\."); + bcd.new_ver = v_tem[0]+"."+v_tem[1]+"."+(Integer.parseInt(v_tem[2])+1); + bcd.oss_key = oss_key; + bcd.init_json = init_json; + config_list.add(bcd); + } + String ver = config_list.get(0).old_ver; + String config_url = MainServer.packConfig.getChildTextTrim("config-url"); + byte[] bytes = Utils.httpGet(config_url+"asset_config"+ver+".json"); + if(bytes==null)return; + String str = StringUtil.getString(bytes); + ITArray config_arr = TArray.newFromJsonData(str); + ITArray arr = TArray.newInstance(); + for(int i=0;i init_config_map; + + public String old_ver; + + public String new_ver; + + public ITArray config_arr; + public String init_json; + + public String oss_key; + + @SuppressWarnings("unchecked") + public void writeNewVer() throws Exception { + List object= JSON.parseObject(config_arr.toJson(),ArrayList.class,Feature.OrderedField); + String json_str = JSON.toJSONString(object, SerializerFeature.PrettyFormat); + String config_path = "/config/asset_config"+new_ver+".json"; + byte[] config_bytes = StringUtil.getBytes(json_str); + List list = MainServer.ossListConfig.getChildren(); + for (Object o : list) { + Element ossConfig = (Element)o; + Utils.uploadOss(ossConfig,MainServer.probjectName+config_path,config_bytes); + } + + Map obj = (Map) init_config_map.get("Android"); + obj.put("version", new_ver); + obj = (Map) init_config_map.get("iOS"); + obj.put("version", new_ver); + obj = (Map) init_config_map.get("Win"); + obj.put("version", new_ver); + json_str = JSON.toJSONString(init_config_map, SerializerFeature.PrettyFormat); + + Element ossConfig = MainServer.ossListConfig.getChild(oss_key); + Utils.uploadOss(ossConfig,"configure/test1/"+init_json,StringUtil.getBytes(json_str)); + } + } +} diff --git a/pack_tools/src/main/java/com/pack/service/ServletAllGame.java b/pack_tools/src/main/java/com/pack/service/ServletAllGame.java new file mode 100644 index 0000000..8674e34 --- /dev/null +++ b/pack_tools/src/main/java/com/pack/service/ServletAllGame.java @@ -0,0 +1,56 @@ +package com.pack.service; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Set; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.pack.Utils; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.StringUtil; + +import redis.clients.jedis.Jedis; + +public class ServletAllGame extends HttpServlet { + + /** + * + */ + private static final long serialVersionUID = 1L; + + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String _svr_type = request.getParameter("svr_type"); + int svr_type = 1; + if(StringUtil.isNotEmpty(_svr_type)) { + svr_type = Integer.parseInt(_svr_type); + } + String svr = Utils.svr_list[svr_type]; + ITArray gameArray = TArray.newInstance(); + Jedis jedis1 = Redis.use(svr+"_db1").getJedis(); + try { + Set all = jedis1.keys("game:[0-9]*"); + for(String key : all) { + key = key.replaceAll("game:", ""); + ITObject gameObj = Utils.getGameData(jedis1, Integer.parseInt(key),false); + gameArray.addTObject(gameObj); + } + }finally { + jedis1.close(); + } + + OutputStream os =response.getOutputStream(); + os.write(StringUtil.getBytes(gameArray.toJson())); + os.flush(); + os.close(); + } +} diff --git a/pack_tools/src/main/webapp/WEB-INF/web.xml b/pack_tools/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..4f12630 --- /dev/null +++ b/pack_tools/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,38 @@ + + + + taurus-web + com.taurus.web.WebFilter + + main + com.pack.MainServer + + + + + taurus-web + /* + + + + allGame + com.pack.service.ServletAllGame + + + + allGame + /allGame + + + + pack_server + com.pack.service.PackServerProject + + + + pack_server + /pack_server + + + + \ No newline at end of file diff --git a/pack_tools/src/main/webapp/config/log4j.properties b/pack_tools/src/main/webapp/config/log4j.properties new file mode 100644 index 0000000..e10e427 --- /dev/null +++ b/pack_tools/src/main/webapp/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/pack_tools.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/pack_tools/src/main/webapp/config/mpnet-tools.xml b/pack_tools/src/main/webapp/config/mpnet-tools.xml new file mode 100644 index 0000000..d50acec --- /dev/null +++ b/pack_tools/src/main/webapp/config/mpnet-tools.xml @@ -0,0 +1,97 @@ + + + + + + 80 + + 2 + + 10 + + -1 + + true + + true + + true + + select 1 + + 180000 + + 60000 + + 30000 + + false + + 300000 + + false + + -1 + + + + + db1 + com.mysql.jdbc.Driver + jdbc:mysql://rm-uf6k4q27s99k5w1p1co.mysql.rds.aliyuncs.com/lygame_test + ly002 + ly2019!@#$ + + + db2 + com.mysql.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/pack_config + proto_ff + 37du_game + + + + + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + \ No newline at end of file diff --git a/pack_tools/src/main/webapp/config/pack-config.xml b/pack_tools/src/main/webapp/config/pack-config.xml new file mode 100644 index 0000000..4086759 --- /dev/null +++ b/pack_tools/src/main/webapp/config/pack-config.xml @@ -0,0 +1,28 @@ + + + + + http://oss-cn-zhangjiakou.aliyuncs.com + LTAI4Fr18Esz5FBT9fPvSr6Y + 5oGollnfotRsnXwsWZIW7aNlNCMYVa + jingduliansai + + + + + jdls_pack + E:/wb_pro/pack_data.bin + E:/wb_pro/wb_win/ + E:/wb_pro/wb_ios/ + E:/wb_pro/wb_android/ + E:/wb_pack_temp + https://jingduliansai.oss-cn-zhangjiakou.aliyuncs.com/jdls_pack/config/ + + + + init1_0.json + https://jingduliansai.oss-cn-zhangjiakou.aliyuncs.com/configure/test1/init1_0.json + test + + + \ No newline at end of file diff --git a/pack_tools/src/main/webapp/config/taurus-core.xml b/pack_tools/src/main/webapp/config/taurus-core.xml new file mode 100644 index 0000000..2892976 --- /dev/null +++ b/pack_tools/src/main/webapp/config/taurus-core.xml @@ -0,0 +1,94 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + \ No newline at end of file diff --git a/pack_tools/src/test/java/pack_tools/Main.java b/pack_tools/src/test/java/pack_tools/Main.java new file mode 100644 index 0000000..1f53045 --- /dev/null +++ b/pack_tools/src/test/java/pack_tools/Main.java @@ -0,0 +1,9 @@ +package pack_tools; + +import com.taurus.web.JettyServer; + +public class Main { + public static void main(String[] args) { + new JettyServer("src/main/webapp",9091,"/").start(); + } +} diff --git a/pack_tools/src/test/java/pack_tools/TT.java b/pack_tools/src/test/java/pack_tools/TT.java new file mode 100644 index 0000000..c098de5 --- /dev/null +++ b/pack_tools/src/test/java/pack_tools/TT.java @@ -0,0 +1,9 @@ +package pack_tools; + +import com.taurus.web.JettyServer; + +public class TT { + public static void main(String[] args) { + new JettyServer("src/main/webapp",9091,"/").start(); + } +} diff --git a/taurus-permanent/config/log4j.properties b/taurus-permanent/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/taurus-permanent/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/taurus-permanent/config/taurus-core.xml b/taurus-permanent/config/taurus-core.xml new file mode 100644 index 0000000..1a2267f --- /dev/null +++ b/taurus-permanent/config/taurus-core.xml @@ -0,0 +1,97 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 80 + + 2 + + 5 + + -1 + + true + + true + + true + + select 1 + + 180000 + + 60000 + + 30000 + + false + + 300000 + + false + + -1 + + + + + db1 + com.mysql.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/db_haoyou + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + \ No newline at end of file diff --git a/taurus-permanent/config/taurus-permanent.xml b/taurus-permanent/config/taurus-permanent.xml new file mode 100644 index 0000000..6c629f3 --- /dev/null +++ b/taurus-permanent/config/taurus-permanent.xml @@ -0,0 +1,75 @@ + + + 4 + + 100 + + Heap + + Heap + + 524288 + + 1024 + + 32768 + + 160 + + + 2 + 3 + 3 + + + true + + 15 + + + + + + + + + + 1.2.3.4 + + + 127.0.0.1 + + 10000 + + + + true +
0.0.0.0
+ 8080 +
+ + + + extension - test + com.taurus.TestExtension + + + + + Sys + 4 + 16 + 60000 + 20000 + + + + + Ext + 4 + 16 + 60000 + 20000 + + +
\ No newline at end of file diff --git a/taurus-permanent/pom.xml b/taurus-permanent/pom.xml new file mode 100644 index 0000000..7fa00c5 --- /dev/null +++ b/taurus-permanent/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + com.taurus + taurus-server + 1.0.1 + + jar + taurus-permanent + 1.0.1 + + + + + junit + junit + + + + + com.taurus + taurus-core + + + + + io.undertow + undertow-core + 2.0.16.Final + + + diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/Main.java b/taurus-permanent/src/main/java/com/taurus/permanent/Main.java new file mode 100644 index 0000000..9156073 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/Main.java @@ -0,0 +1,9 @@ +package com.taurus.permanent; + +public class Main { + + public static void main(String[] args) { + TPServer taurus = TPServer.me(); + taurus.start(); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/TPServer.java b/taurus-permanent/src/main/java/com/taurus/permanent/TPServer.java new file mode 100644 index 0000000..b7b2c9f --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/TPServer.java @@ -0,0 +1,319 @@ +package com.taurus.permanent; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +import com.taurus.core.events.Event; +import com.taurus.core.events.EventManager; +import com.taurus.core.events.IEventListener; +import com.taurus.core.plugin.PluginService; +import com.taurus.core.routes.Extension; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.task.TaskScheduler; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.core.DefaultConstants; +import com.taurus.permanent.core.ServerConfig; +import com.taurus.permanent.core.ServerConfig.ExecutorConfig; +import com.taurus.permanent.core.ServerState; +import com.taurus.permanent.core.SessionManager; +import com.taurus.permanent.core.SystemController; +import com.taurus.permanent.core.TPEvents; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.util.GhostUserHunter; + +/** + * The server main class. + * + * + * + */ +public final class TPServer { + /** + * The server version. + */ + private final String version = "1.0.1"; + /** + * The server class instance. + */ + private static TPServer _instance = null; + private final BitSwarmEngine bitSwarmEngine; + private final Logger log; + private volatile ServerState state = ServerState.STARTING; + private volatile boolean initialized = false; + private volatile long serverStartTime; + private ServerConfig config; + private IEventListener networkEvtListener; + private ScheduledThreadPoolExecutor timerPool; + private TaskScheduler taskScheduler; + private EventManager eventManager; + private GhostUserHunter ghostUserHunter; + private SystemController controller; + private Extension extension; + private ThreadPoolExecutor systemExecutor; + private ThreadPoolExecutor extensionExecutor; + + /** + * get main instance + */ + public static TPServer me() { + if (_instance == null) { + _instance = new TPServer(); + } + return _instance; + } + + private TPServer() { + bitSwarmEngine = BitSwarmEngine.getInstance(); + + networkEvtListener = new NetworkEvtListener(); + timerPool = new ScheduledThreadPoolExecutor(1); + log = Logger.getLogger(getClass()); + + } + + public String getVersion() { + return version; + } + + private static final ServerConfig loadServerSettings() throws Exception { + FileInputStream is = new FileInputStream(DefaultConstants.SERVER_CFG_FILE); + ServerConfig config = new ServerConfig(); + config.load(is); + return config; + } + + public void start() { + System.out.println("\n==============================================================================\n" + + ">>Begin start taurus-permanent server....\n" + + "============================================================================== \n"); + if (!initialized) { + initialize(); + } + + try { + + PluginService.me().loadConfig(); + log.info("Load taurus-core config finish"); + + this.config = loadServerSettings(); + initExecutors(); + + this.taskScheduler = new TaskScheduler(); + this.taskScheduler.init(null); + + this.eventManager = new EventManager(systemExecutor); + eventManager.init(null); + + timerPool.setCorePoolSize(config.timerThreadPoolSize); + bitSwarmEngine.init(null); + + log.info("\n\n==============================================================================\n" + + ">>Init Extension...\n"+ + "============================================================================== \n"); + controller = new SystemController(); + ghostUserHunter = new GhostUserHunter(); + extension = instanceExtension(); + controller.init(null); + extension.onStart(); + + state = ServerState.STARTED; + log.info("\n\n==============================================================================\n" + + ">>Server(" + version + ") ready!\n" + + "============================================================================== \n"); + + serverStartTime = System.currentTimeMillis(); + } catch (FileNotFoundException e) { + log.error("Not find taurus-core.xml and taurus-permanent.xml", e); + } catch (Exception e) { + log.error("Server start exception!", e); + } + } + + private void initExecutors() { + final ExecutorConfig sys_cfg = this.config.systemThreadPoolConfig; + this.systemExecutor = new ThreadPoolExecutor(sys_cfg.corePoolSize, sys_cfg.maxPoolSize, sys_cfg.keepAliveTime, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(sys_cfg.maxQueueSize), new TPThreadFactory(sys_cfg.name)); + + final ExecutorConfig ext_cfg = this.config.extensionThreadPoolConfig; + this.extensionExecutor = new ThreadPoolExecutor(ext_cfg.corePoolSize, ext_cfg.maxPoolSize, ext_cfg.keepAliveTime, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue(ext_cfg.maxQueueSize), new TPThreadFactory(ext_cfg.name)); + } + + /** + * shut down server. + */ + public void shutdown() { + try { + log.info("Server shutdown!"); + List awaitingExecution = timerPool.shutdownNow(); + log.info("stopping timer pool: " + awaitingExecution.size()); + + bitSwarmEngine.destroy(null); + eventManager.destroy(null); + this.controller.destroy(null); + extension.onStop(); + } catch (Exception e) { + log.error("shut down exception!", e); + } + } + + public ScheduledThreadPoolExecutor getTimerPool() { + return timerPool; + } + + public TaskScheduler getTaskScheduler() { + return taskScheduler; + } + + public ThreadPoolExecutor getSystemExecutor() { + return systemExecutor; + } + + public ThreadPoolExecutor getExtensionExecutor() { + return extensionExecutor; + } + + public EventManager getEventManager() { + return eventManager; + } + + public SessionManager getSessionManager() { + return bitSwarmEngine.getSessionManager(); + } + + public SystemController getController() { + return controller; + } + + public Extension getExtension() { + return extension; + } + + public ServerState getState() { + return state; + } + + public ServerConfig getConfig() { + return config; + } + + /** + * 获取服务器启动时间 + * + * @return + */ + public long getUptime() { + if (serverStartTime == 0L) { + throw new IllegalStateException("Server not ready yet, cannot provide uptime!"); + } + return System.currentTimeMillis() - serverStartTime; + } + + private void initialize() { + if (initialized) { + throw new IllegalStateException("SmartFoxServer engine already initialized!"); + } + bitSwarmEngine.addEventListener(TPEvents.SESSION_LOST, networkEvtListener); + bitSwarmEngine.addEventListener(TPEvents.SESSION_IDLE, networkEvtListener); + bitSwarmEngine.addEventListener(TPEvents.SESSION_IDLE_CHECK_COMPLETE, networkEvtListener); + + initialized = true; + } + + private Extension instanceExtension() { + ServerConfig.ExtensionConfig extensionConfig = config.extensionConfig; + if (StringUtil.isEmpty(extensionConfig.className)) { + throw new RuntimeException("Extension className parameter is missing!"); + } + if (StringUtil.isEmpty(extensionConfig.name)) { + throw new RuntimeException("Extension name parameter is missing!"); + } + Extension extension = null; + try { + Class extensionClass = Class.forName(extensionConfig.className); + if (!Extension.class.isAssignableFrom(extensionClass)) { + throw new RuntimeException("Extension does not extends Extension: " + extensionConfig.name); + } + extension = (Extension) extensionClass.newInstance(); + extension.setName(extensionConfig.name); + } catch (IllegalAccessException e) { + throw new RuntimeException("Illegal access while instantiating class: " + extensionConfig.className); + } catch (InstantiationException e) { + throw new RuntimeException("Cannot instantiate class: " + extensionConfig.className); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Class not found: " + extensionConfig.className); + } + return extension; + } + + private void onSessionClosed(Session session) { + controller.disconnect(session); + } + + private void onSessionIdle(Session idleSession) { + controller.disconnect(idleSession); + } + + /** + * session 网络事件监听 + */ + private class NetworkEvtListener implements IEventListener { + private NetworkEvtListener() { + } + + public void handleEvent(Event event) { + String evtName = event.getName(); + + if (evtName.equals(TPEvents.SESSION_LOST)) { + Session session = (Session) event.getParameter(TPEvents.PARAM_SESSION); + + if (session == null) { + throw new RuntimeException("session is null!"); + } + onSessionClosed(session); + } else if ((evtName.equals(TPEvents.SESSION_IDLE_CHECK_COMPLETE))) { + ghostUserHunter.hunt(); + } else if (evtName.equals(TPEvents.SESSION_IDLE)) { + onSessionIdle((Session) event.getParameter(TPEvents.PARAM_SESSION)); + } + } + } + + private static final class TPThreadFactory implements ThreadFactory { + private static final AtomicInteger POOL_ID; + private static final String THREAD_BASE_NAME = "%s:%s"; + private final AtomicInteger threadId; + private final String poolName; + + static { + POOL_ID = new AtomicInteger(0); + } + + public TPThreadFactory(final String poolName) { + this.threadId = new AtomicInteger(1); + this.poolName = poolName; + TPThreadFactory.POOL_ID.incrementAndGet(); + } + + @Override + public Thread newThread(final Runnable r) { + final Thread t = new Thread(r, + String.format(THREAD_BASE_NAME, (this.poolName != null) ? this.poolName : TPThreadFactory.POOL_ID.get(), this.threadId.getAndIncrement())); + if (t.isDaemon()) { + t.setDaemon(false); + } + if (t.getPriority() != 5) { + t.setPriority(5); + } + return t; + } + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/BaseCoreService.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/BaseCoreService.java new file mode 100644 index 0000000..c750488 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/BaseCoreService.java @@ -0,0 +1,46 @@ +package com.taurus.permanent.core; + +import java.util.concurrent.atomic.AtomicInteger; + +import com.taurus.core.events.EventDispatcher; +import com.taurus.core.service.IService; + +/** + * BaseCoreService + * + */ +public abstract class BaseCoreService extends EventDispatcher implements IService { + private static final AtomicInteger serviceId = new AtomicInteger(0); + private static final String DEFAULT_NAME = "Service-"; + protected String name; + protected volatile boolean active = false; + + public void init(Object o) { + name = getServiceId(); + active = true; + } + + public void destroy(Object o) { + active = false; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isActive() { + return active; + } + + public String toString() { + return "[Core Service]: " + name + ", State: " + (isActive() ? "active" : "not active"); + } + + protected static String getServiceId() { + return DEFAULT_NAME + serviceId.getAndIncrement(); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/BitSwarmEngine.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/BitSwarmEngine.java new file mode 100644 index 0000000..e733060 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/BitSwarmEngine.java @@ -0,0 +1,337 @@ +package com.taurus.permanent.core; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import com.taurus.core.events.Event; +import com.taurus.core.events.IEventListener; +import com.taurus.core.service.IService; +import com.taurus.core.util.FixedIndexThreadPool; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.ServerConfig.SocketAddress; +import com.taurus.permanent.data.BindableSocket; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.data.SessionType; +import com.taurus.permanent.io.IOHandler; +import com.taurus.permanent.io.ProtocolHandler; +import com.taurus.permanent.normal.SocketAcceptor; +import com.taurus.permanent.normal.SocketReader; +import com.taurus.permanent.normal.SocketWriter; +import com.taurus.permanent.websocket.WebSocketService; + +/** + * 核心网络字节群处理类 + * + */ +public final class BitSwarmEngine extends BaseCoreService { + private static BitSwarmEngine __engine__; + private SocketAcceptor socketAcceptor; + private SocketReader socketReader; + private SocketWriter socketWriter; + + private Logger logger; + private ServerConfig config; + private SessionManager sessionManager; + private volatile boolean inited = false; + private Map coreServicesByName; + private Map configByService; + private IEventListener eventHandler; + private WebSocketService webSocketService; + private ProtocolHandler protocolHandler; + private ConnectionFilter connectionFilter; + private FixedIndexThreadPool threadPool; + + public static BitSwarmEngine getInstance() { + if (__engine__ == null) { + __engine__ = new BitSwarmEngine(); + } + return __engine__; + } + + private BitSwarmEngine() { + setName("BitSwarmEngine"); + } + + private void initializeServerEngine() { + logger = Logger.getLogger(BitSwarmEngine.class); + this.config = TPServer.me().getConfig(); + inited = true; + } + + + private final void bootSequence() throws Exception { + startCoreServices(); + + bindSockets(config.socketAddresses); + for (IService service : coreServicesByName.values()) { + if (service != null) { + service.init(configByService.get(service)); + } + } + } + + private final void setConnectionFilterConfig() { + for (String blockedIp : config.ipFilter.addressBlackList) { + this.connectionFilter.addBannedAddress(blockedIp); + } + + for (String allowedIp : config.ipFilter.addressWhiteList) { + this.connectionFilter.addWhiteListAddress(allowedIp); + } + + this.connectionFilter.setMaxConnectionsPerIp(config.ipFilter.maxConnectionsPerAddress); + } + + /** + * write response packet. no blocking + * @param response + */ + public void write(Packet response) { + try { + if (this.config.webSocketConfig.isActive) { + final List webSocketRecipients = new ArrayList(); + final List socketRecipients = new ArrayList(); + for (final Session session : response.getRecipients()) { + if (session.getType() == SessionType.WEBSOCKET) { + webSocketRecipients.add(session); + } + else { + socketRecipients.add(session); + } + } + if (webSocketRecipients.size() > 0) { + response.setRecipients(socketRecipients); + final Packet webSocketResponse = response.clone(); + webSocketResponse.setRecipients(webSocketRecipients); + if (response.getId() != SystemController.ACTION_PINGPONG) { + long index = Thread.currentThread().getId(); + this.threadPool.execute((int) index, webSocketResponse); + } else { + writeToWebSocket(response); + } + } + } + }finally { + if (response.getId() != SystemController.ACTION_PINGPONG) { + long index = Thread.currentThread().getId(); + this.threadPool.execute((int) index, response); + } else { + writeToSocket(response); + } + } + + } + + /** + * write response packet. no blocking + * @param response 广播服,没有前后顺序的需求,需要尽可能的把包分发给不同的线程 + */ + public void write(Packet response, int weightId) { + if (weightId == 0) + { + weightId = (int)(Math.random() * 1000); + } + try { + if (this.config.webSocketConfig.isActive) { + final List webSocketRecipients = new ArrayList(); + final List socketRecipients = new ArrayList(); + for (final Session session : response.getRecipients()) { + if (session.getType() == SessionType.WEBSOCKET) { + webSocketRecipients.add(session); + } + else { + socketRecipients.add(session); + } + } + if (webSocketRecipients.size() > 0) { + response.setRecipients(socketRecipients); + final Packet webSocketResponse = response.clone(); + webSocketResponse.setRecipients(webSocketRecipients); + if (response.getId() != SystemController.ACTION_PINGPONG) { + this.threadPool.execute(weightId, webSocketResponse); + } else { + writeToWebSocket(response); + } + } + } + }finally { + if (response.getId() != SystemController.ACTION_PINGPONG) { + this.threadPool.execute(weightId, response); + } else { + writeToSocket(response); + } + } + + } + + private void writeToSocket(Packet res) { + socketWriter.getIOHandler().onDataWrite(res); + } + + private void writeToWebSocket(Packet res) { + webSocketService.onDataWrite(res); + } + + + private void startCoreServices() throws Exception { + sessionManager = SessionManager.getInstance(); + sessionManager.setName(DefaultConstants.SERVICE_SESSION_MANAGER); + + socketReader = new SocketReader(config.socketReaderThreadPoolSize); + // instance io handler + IOHandler ioHandler = new IOHandler(); + socketReader.setIoHandler(ioHandler); + + // instance socket acceptor + socketAcceptor = new SocketAcceptor(config.socketAcceptorThreadPoolSize); + // instance socket writer + socketWriter = new SocketWriter(config.socketWriterThreadPoolSize); + socketWriter.setIOHandler(ioHandler); + threadPool = new FixedIndexThreadPool(config.socketWriterThreadPoolSize, "PacketWrite", PacketWriteWork.class); + + if(config.webSocketConfig.isActive) { + webSocketService = new WebSocketService(); + webSocketService.setName(DefaultConstants.SERVICE_WEB_SOCKET); + coreServicesByName.put(DefaultConstants.SERVICE_WEB_SOCKET, webSocketService); + } + + socketAcceptor.setName(DefaultConstants.SERVICE_SOCKET_ACCEPTOR); + socketReader.setName(DefaultConstants.SERVICE_SOCKET_READER); + socketWriter.setName(DefaultConstants.SERVICE_SOCKET_WRITER); + + coreServicesByName.put(DefaultConstants.SERVICE_SESSION_MANAGER, sessionManager); + coreServicesByName.put(DefaultConstants.SERVICE_SOCKET_ACCEPTOR, socketAcceptor); + coreServicesByName.put(DefaultConstants.SERVICE_SOCKET_READER, socketReader); + coreServicesByName.put(DefaultConstants.SERVICE_SOCKET_WRITER, socketWriter); + + } + + private void stopCoreServices() throws Exception { + socketWriter.destroy(null); + socketReader.destroy(null); + if(webSocketService!=null) { + webSocketService.destroy(null); + } + int pw_count = threadPool.shutdown(); + logger.info("PacketWrite stopped. Unprocessed tasks: " + pw_count); + Thread.sleep(2000L); + + sessionManager.destroy(null); + socketAcceptor.destroy(null); + } + + private void bindSockets(List bindableSockets) { + for (SocketAddress socketCfg : bindableSockets) { + try { + this.socketAcceptor.bindSocket(socketCfg); + } catch (IOException e) { + logger.error(e); + logger.warn("Was not able to bind socket: " + socketCfg); + } + } + + List sockets = socketAcceptor.getBoundSockets(); + String message = "Listening Sockets: "; + for (BindableSocket socket : sockets) { + message = message + socket.toString() + " "; + } + logger.info(message); + } + + public IService getServiceByName(String serviceName) { + return coreServicesByName.get(serviceName); + } + + public SocketAcceptor getSocketAcceptor() { + return this.socketAcceptor; + } + + public SocketReader getSocketReader() { + return this.socketReader; + } + + public SocketWriter getSocketWriter() { + return this.socketWriter; + } + + public ProtocolHandler getProtocolHandler() { + return this.protocolHandler; + } + + public Logger getLogger() { + return this.logger; + } + + public void setLogger(Logger logger) { + this.logger = logger; + } + + public ServerConfig getConfig() { + return this.config; + } + + public ConnectionFilter getConnectionFilter() { + return connectionFilter; + } + + public SessionManager getSessionManager() { + return this.sessionManager; + } + + public void init(Object o) { + if (!inited) { + initializeServerEngine(); + } + logger.info("Start Bit Swarm Engine!"); + + eventHandler = new IEventListener() { + public void handleEvent(Event event) { + dispatchEvent(event); + } + }; + + protocolHandler = new ProtocolHandler(); + connectionFilter = new ConnectionFilter(); + setConnectionFilterConfig(); + coreServicesByName = new ConcurrentHashMap(); + configByService = new HashMap(); + + try { + bootSequence(); + } catch (Exception e) { + throw new RuntimeException(e); + } + socketReader.addEventListener(TPEvents.SESSION_LOST, this.eventHandler); + } + + public void destroy(Object o) { + try { + stopCoreServices(); + } catch (Exception e) { + logger.error("Destroy exception!\n",e); + } + } + + public static final class PacketWriteWork extends FixedIndexThreadPool.Work { + + @Override + protected void handlerTask(Object task) throws Exception { + Packet packet = (Packet) task; + List list = packet.getRecipients(); + if(list.size() > 0) { + SessionType type = list.get(0).getType(); + if(type == SessionType.WEBSOCKET) { + BitSwarmEngine.getInstance().writeToWebSocket(packet); + }else { + BitSwarmEngine.getInstance().writeToSocket(packet); + } + } + } + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/ConnectionFilter.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/ConnectionFilter.java new file mode 100644 index 0000000..e42fa07 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/ConnectionFilter.java @@ -0,0 +1,159 @@ +package com.taurus.permanent.core; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; + +import com.taurus.core.util.Logger; + + +/** + * ip连接过滤 + * + */ +public class ConnectionFilter { + private final Set addressWhiteList; + private final Set bannedAddresses; + private final ConcurrentMap addressMap; + private int maxConnectionsPerIp = 10; + private Logger logger; + + public ConnectionFilter() { + this.addressWhiteList = new HashSet(); + this.bannedAddresses = new HashSet(); + this.addressMap = new ConcurrentHashMap(); + logger = Logger.getLogger(ConnectionFilter.class); + } + /** + * 获取所有黑名单列表 + */ + public void addBannedAddress(String ipAddress) { + synchronized (bannedAddresses) { + bannedAddresses.add(ipAddress); + } + } + + /** + * 获取所有白名单列表 + */ + public void addWhiteListAddress(String ipAddress) { + synchronized (this.addressWhiteList) { + this.addressWhiteList.add(ipAddress); + } + } + + /** + * 获取所有黑名单列表 + */ + public String[] getBannedAddresses() { + String[] set = (String[]) null; + + synchronized (this.bannedAddresses) { + set = new String[bannedAddresses.size()]; + set = (String[]) bannedAddresses.toArray(set); + } + + return set; + } + + /** + * 获取每个IP最大的连接数 + */ + public int getMaxConnectionsPerIp() { + return this.maxConnectionsPerIp; + } + + /** + * 获取白名单列表 + */ + public String[] getWhiteListAddresses() { + String[] set = (String[]) null; + + synchronized (this.addressWhiteList) { + set = new String[this.addressWhiteList.size()]; + set = (String[]) this.addressWhiteList.toArray(set); + } + + return set; + } + + public void removeAddress(String ipAddress) { + synchronized (this.addressMap) { + AtomicInteger count = (AtomicInteger) this.addressMap.get(ipAddress); + + if (count != null) { + int value = count.decrementAndGet(); + + if (value == 0) + this.addressMap.remove(ipAddress); + } + } + } + + /** + * 移除黑名单IP地址 + */ + public void removeBannedAddress(String ipAddress) { + synchronized (this.bannedAddresses) { + this.bannedAddresses.remove(ipAddress); + } + } + + /** + * 移除白名单IP地址 + */ + public void removeWhiteListAddress(String ipAddress) { + synchronized (this.addressWhiteList) { + this.addressWhiteList.remove(ipAddress); + } + } + + /** + * 获取每个IP最大连接数 + */ + public void setMaxConnectionsPerIp(int max) { + this.maxConnectionsPerIp = max; + } + + public boolean validateAndAddAddress(String ipAddress) { + synchronized (this.addressWhiteList) { + if (this.addressWhiteList.contains(ipAddress)) { + return true; + } + } + + if (isAddressBanned(ipAddress)) { + logger.warn("Ip Address: " + ipAddress + " is banned!"); + return false; + } + + synchronized (this.addressMap) { + AtomicInteger count = (AtomicInteger) addressMap.get(ipAddress); + + if ((count != null) && (count.intValue() >= maxConnectionsPerIp)) { + logger.warn("Refused connection. Ip Address: " + ipAddress + " has reached maximum allowed connections."); + return false; + } + + if (count == null) { + count = new AtomicInteger(1); + this.addressMap.put(ipAddress, count); + } else { + count.incrementAndGet(); + } + } + return true; + } + + private boolean isAddressBanned(String ip) { + boolean isBanned = false; + + synchronized (this.bannedAddresses) { + isBanned = this.bannedAddresses.contains(ip); + } + + return isBanned; + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/DefaultConstants.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/DefaultConstants.java new file mode 100644 index 0000000..1e389fc --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/DefaultConstants.java @@ -0,0 +1,20 @@ +package com.taurus.permanent.core; + +/** + * 常量表 + * + */ +public final class DefaultConstants { + public static String SERVER_CFG_FILE = "config/taurus-permanent.xml"; + + + public static final String SERVICE_SOCKET_ACCEPTOR = "socketAcceptor"; + public static final String SERVICE_SOCKET_READER = "socketReader"; + public static final String SERVICE_SOCKET_WRITER = "socketWriter"; + public static final String SERVICE_SESSION_MANAGER = "sessionManager"; + public static final String SERVICE_WEB_SOCKET = "webSocket"; + + + public static final String SESSION_SELECTION_KEY = "SessionSelectionKey"; + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/IConnectionFilter.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/IConnectionFilter.java new file mode 100644 index 0000000..e3f4124 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/IConnectionFilter.java @@ -0,0 +1,61 @@ +package com.taurus.permanent.core; + + +/** + * ip连接过滤通用接口 + * + */ +public interface IConnectionFilter { + /** + * 添加黑名单IP地址 + * @param ipAddress + */ + public void addBannedAddress(String ipAddress); + + /** + * 移除黑名单IP地址 + * @param ipAddress + */ + public void removeBannedAddress(String ipAddress); + + /** + * 获取所有黑名单列表 + * @return + */ + public String[] getBannedAddresses(); + + + public boolean validateAndAddAddress(String ipAddress); + + public void removeAddress(String ipAddress); + + /** + * 添加白名单地址 + * @param ipAddress + */ + public void addWhiteListAddress(String ipAddress); + + /** + * 移除白名单地址 + * @param ipAddress + */ + public void removeWhiteListAddress(String ipAddress); + + /** + * 获取白名单列表 + * @return + */ + public String[] getWhiteListAddresses(); + + /** + * 获取每个IP最大的连接数 + * @return + */ + public int getMaxConnectionsPerIp(); + + /** + * 设置每个IP最大的连接数 + * @param max + */ + public void setMaxConnectionsPerIp(int max); +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerConfig.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerConfig.java new file mode 100644 index 0000000..1bc194d --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerConfig.java @@ -0,0 +1,181 @@ +package com.taurus.permanent.core; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; + +/** + * 服务器配置信息 + * + */ +public class ServerConfig { + public volatile List socketAddresses = new ArrayList(); + public volatile IpFilterConfig ipFilter = new IpFilterConfig(); + public volatile int timerThreadPoolSize = 1; + public volatile int protocolCompression = 512; + + public String readBufferType = "HEAP"; + public String writeBufferType = "HEAP"; + public int maxPacketSize = 4096; + public int maxReadBufferSize = 1024; + public int maxWriteBufferSize = 32768; + public int socketAcceptorThreadPoolSize = 1; + public int socketReaderThreadPoolSize = 1; + public int socketWriterThreadPoolSize = 1; + public int sessionPacketQueueSize = 120; + public int sessionTimeout = 15; + public boolean tcpNoDelay = false; + + public ExecutorConfig systemThreadPoolConfig = new ExecutorConfig(); + public ExecutorConfig extensionThreadPoolConfig = new ExecutorConfig(); + public ExtensionConfig extensionConfig = new ExtensionConfig(); + public WebSocketConfig webSocketConfig = new WebSocketConfig(); + + /** + * ip过滤设置 + * + */ + public static final class IpFilterConfig { + public List addressBlackList = new ArrayList(); + public List addressWhiteList = new ArrayList(); + public volatile int maxConnectionsPerAddress = 99999; + } + + /** + * server ip_port绑定 + * + */ + public static final class SocketAddress { + public static final String TYPE_UDP = "UDP"; + public static final String TYPE_TCP = "TCP"; + public String address = "127.0.0.1"; + public int port = 9339; + public String type = TYPE_TCP; + + public String toString() { + return String.format("[%s]%s:%d", type, address, port); + } + } + + /** + * Taurus Thread pool config + * + * + */ + public static final class ExecutorConfig { + /** + * 线程池名称 + */ + public String name; + /** + * 核心线程大小 + */ + public int corePoolSize=4; + /** + * 最大线程大小 + */ + public int maxPoolSize=16; + /** + * 线程最大空闲时间(毫秒) + */ + public int keepAliveTime =60000; + /** + * 最大队列大小 + */ + public int maxQueueSize=20000; + } + + /** + * 自定义启动控制设置 + * + * + */ + public static final class ExtensionConfig { + public String name = ""; + public String className = ""; + } + + /** + * web socket + * + * + */ + public static final class WebSocketConfig { + public boolean isActive = true; + public String address = "0.0.0.0"; + public int port = 8080; + } + + private static final void loadThreadPoolConfig(Element em,ExecutorConfig config) { + config.name = em.getChildTextTrim("name"); + config.corePoolSize = Integer.parseInt(em.getChildTextTrim("corePoolSize")); + config.maxPoolSize = Integer.parseInt(em.getChildTextTrim("maxPoolSize")); + config.keepAliveTime = Integer.parseInt(em.getChildTextTrim("keepAliveTime")); + config.maxQueueSize = Integer.parseInt(em.getChildTextTrim("maxQueueSize")); + } + + public final void load(InputStream is) throws Exception{ + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(is); + Element root = document.getRootElement(); + + this.timerThreadPoolSize = Integer.parseInt(root.getChildTextTrim("timerThreadPoolSize")); + this.protocolCompression = Integer.parseInt(root.getChildTextTrim("protocolCompression")); + this.readBufferType = root.getChildTextTrim("readBufferType"); + this.writeBufferType = root.getChildTextTrim("writeBufferType"); + this.maxPacketSize = Integer.parseInt(root.getChildTextTrim("maxPacketSize")); + this.maxReadBufferSize = Integer.parseInt(root.getChildTextTrim("maxReadBufferSize")); + this.maxWriteBufferSize = Integer.parseInt(root.getChildTextTrim("maxWriteBufferSize")); + this.socketAcceptorThreadPoolSize = Integer.parseInt(root.getChildTextTrim("socketAcceptorThreadPoolSize")); + this.socketReaderThreadPoolSize = Integer.parseInt(root.getChildTextTrim("socketReaderThreadPoolSize")); + this.socketWriterThreadPoolSize = Integer.parseInt(root.getChildTextTrim("socketWriterThreadPoolSize")); + this.maxPacketSize = Integer.parseInt(root.getChildTextTrim("maxPacketSize")); + this.sessionPacketQueueSize = Integer.parseInt(root.getChildTextTrim("sessionPacketQueueSize")); + this.sessionTimeout = Integer.parseInt(root.getChildTextTrim("sessionTimeout")); + this.tcpNoDelay = Boolean.parseBoolean(root.getChildTextTrim("tcpNoDelay")); + + Element addressesEm = root.getChild("socketAddresses"); + Iterator itr = (addressesEm.getChildren("socket")).iterator(); + while(itr.hasNext()) { + Element socketEm = (Element)itr.next(); + SocketAddress sa = new SocketAddress(); + sa.address = socketEm.getAttributeValue("address", "0.0.0.0"); + sa.port = Integer.parseInt(socketEm.getAttributeValue("port", "9339")); + sa.type = socketEm.getAttributeValue("type", SocketAddress.TYPE_TCP); + socketAddresses.add(sa); + } + + + Element ipFilterEm = root.getChild("ipFilter"); + Element addressBlackListEm = ipFilterEm.getChild("addressBlackList"); + itr = (addressBlackListEm.getChildren("string")).iterator(); + while(itr.hasNext()) { + Element socketEm = (Element)itr.next(); + ipFilter.addressBlackList.add(socketEm.getTextTrim()); + } + Element addressWhiteListEm = ipFilterEm.getChild("addressWhiteList"); + itr = (addressWhiteListEm.getChildren("string")).iterator(); + while(itr.hasNext()) { + Element socketEm = (Element)itr.next(); + ipFilter.addressWhiteList.add(socketEm.getTextTrim()); + } + ipFilter.maxConnectionsPerAddress = Integer.parseInt(ipFilterEm.getChildTextTrim("maxConnectionsPerAddress")); + + Element extensionConfigEm = root.getChild("extensionConfig"); + extensionConfig.className = extensionConfigEm.getChildTextTrim("className"); + extensionConfig.name = extensionConfigEm.getChildTextTrim("name"); + + + Element webSocketEm = root.getChild("webSocket"); + webSocketConfig.isActive = Boolean.parseBoolean(webSocketEm.getChildTextTrim("isActive")); + + loadThreadPoolConfig(root.getChild("systemThreadPoolConfig"),systemThreadPoolConfig); + + loadThreadPoolConfig(root.getChild("extensionThreadPoolConfig"),extensionThreadPoolConfig); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerState.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerState.java new file mode 100644 index 0000000..8b8e1d1 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/ServerState.java @@ -0,0 +1,11 @@ +package com.taurus.permanent.core; + +/** + * 服务器状态 + * + */ +public enum ServerState { + STARTING, + STARTED, + REBOOTING; +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/SessionManager.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/SessionManager.java new file mode 100644 index 0000000..46d7af0 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/SessionManager.java @@ -0,0 +1,313 @@ +package com.taurus.permanent.core; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.taurus.core.events.Event; +import com.taurus.core.service.AbstractService; +import com.taurus.core.util.Logger; +import com.taurus.core.util.task.ITaskHandler; +import com.taurus.core.util.task.Task; +import com.taurus.core.util.task.TaskScheduler; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.IPacketQueue; +import com.taurus.permanent.data.ISocketChannel; +import com.taurus.permanent.data.NonBlockingPacketQueue; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.data.SessionType; + +/** + * session管理器,负责创建,添加和删除session + * + */ +public final class SessionManager extends AbstractService { + private static final String SESSION_CLEANING_TASK_ID = "SessionCleanerTask"; + private static final int SESSION_CLEANING_INTERVAL_SECONDS = 10; + private static SessionManager __instance__; + private Logger logger; + private final ConcurrentMap sessionsById; + private BitSwarmEngine engine = null; + private final List sessionList; + private final ConcurrentMap sessionsByConnection; + private Task sessionCleanTask; + private TaskScheduler systemScheduler; + private int highestCCS = 0; + + public static SessionManager getInstance() { + if (__instance__ == null) { + __instance__ = new SessionManager(); + } + return __instance__; + } + + private SessionManager() { + sessionsById = new ConcurrentHashMap(); + sessionList = new ArrayList(); + sessionsByConnection = new ConcurrentHashMap(); + } + + public void init(Object o) { + name = "DefaultSessionManager"; + engine = BitSwarmEngine.getInstance(); + logger = Logger.getLogger(SessionManager.class); + + systemScheduler = TPServer.me().getTaskScheduler(); + sessionCleanTask = new Task(SESSION_CLEANING_TASK_ID); + systemScheduler.addScheduledTask(sessionCleanTask, SESSION_CLEANING_INTERVAL_SECONDS, true, new SessionCleaner()); + + active = true; + logger.info("session manager init!"); + } + + public void destroy(Object o) { + super.destroy(o); + sessionCleanTask.setActive(false); + shutDownLocalSessions(); + sessionsByConnection.clear(); + } + + /** + * 添加session对象 + * @param session + */ + public void addSession(Session session) { + synchronized (sessionList) { + sessionList.add(session); + } + sessionsById.put(session.getId(), session); + sessionsByConnection.put(session.getConnection().getChannel(), session); + + + if (sessionList.size() > highestCCS) { + highestCCS = sessionList.size(); + } + logger.info("Session created: " + session); + } + + /** + * 检查session是否存在 + * @param session + * @return + */ + public boolean containsSession(Session session) { + return sessionsById.containsKey(session.getId()); + } + + /** + * 移除指定session对象 + * @param session + */ + public void removeSession(Session session) { + if (session == null)return; + if(!sessionsById.containsKey(session.getId()))return; + synchronized (sessionList) { + sessionList.remove(session); + } + ISocketChannel connection = session.getConnection(); + sessionsById.remove(session.getId()); + if (connection != null) { + sessionsByConnection.remove(connection.getChannel()); + } + if ((session.getType() == SessionType.NORMAL) || (session.getType() == SessionType.WEBSOCKET)) { + engine.getConnectionFilter().removeAddress(session.getAddress()); + } + + logger.info("Session removed: " + session); + } + + /** + * 移除指定ID的session + * @param id + * @return + */ + public Session removeSession(int id) { + Session session = sessionsById.get(id); + if (session != null) { + removeSession(session); + } + return session; + } + + /** + * 移除指定channel的session + * @param connection + * @return + */ + public Session removeSession(Object connection) { + Session session = getSessionByConnection(connection); + if (session != null) { + removeSession(session); + } + return session; + } + + /** + * channel链接断开处理 + * @param connection + * @throws IOException + */ + public void onSocketDisconnected(Object connection) throws IOException { + Session session = sessionsByConnection.get(connection); + if (session == null) { + return; + } + sessionsByConnection.remove(connection); + session.setConnected(false); + removeSession(session); + dispatchLostSessionEvent(session); + } + + /** + * 获取服务器所有session + * @return + */ + public List getAllSessions() { + List allSessions = null; + + synchronized (sessionList) { + allSessions = new ArrayList(sessionList); + } + + return allSessions; + } + + /** + * 获取指定channel的session + * @param connection + * @return + */ + public Session getSessionByConnection(Object connection) { + return sessionsByConnection.get(connection); + } + + /** + * 获取指定ID的session + * @param id + * @return + */ + public Session getSessionById(int id) { + return sessionsById.get(Integer.valueOf(id)); + } + + /** + * 获取最高的流量数量 + * @return + */ + public int getHighestCCS() { + return highestCCS; + } + + /** + * 关闭本地所有session + */ + public void shutDownLocalSessions() { + synchronized (sessionList) { + for (Iterator it = sessionList.iterator(); it.hasNext();) { + Session session = (Session) it.next(); + it.remove(); + try { + session.close(); + } catch (IOException e) { + logger.warn("I/O Error while closing session: " + session); + } + } + } + } + + /** + * 创建 session + * @param channel + * @return + */ + public Session createSession(ISocketChannel channel,SessionType type) { + Session session = new Session(); + session.setConnection(channel); + session.setTimeout(engine.getConfig().sessionTimeout); + session.setType(type); + IPacketQueue packetQueue = new NonBlockingPacketQueue(engine.getConfig().sessionPacketQueueSize); + session.setPacketQueue(packetQueue); + return session; + } + + /** + * 获取当前session链接数 + * @return + */ + public int getSessionCount() { + return sessionList.size(); + } + + private void applySessionCleaning() { + if (getSessionCount() > 0) { + for (Session session : getAllSessions()) { + if ((session == null) || (session.isFrozen())) { + continue; + } + if (session.isMarkedForEviction()) { + terminateSession(session); + logger.info("Terminated idle logged-in session: " + session); + } else { + if (!session.isIdle()) { + continue; + } + if (session.getHashId()!=null) { + logger.info("session timeout:" + session); + + session.setMarkedForEviction(); + dispatchSessionIdleEvent(session); + } else { + terminateSession(session); + } + } + } + } + + Event event = new Event(TPEvents.SESSION_IDLE_CHECK_COMPLETE); + engine.dispatchEvent(event); + } + + private void terminateSession(Session session) { + if (session.getType() == SessionType.NORMAL) { + ISocketChannel connection = session.getConnection(); + + try { + connection.close(); + session.setConnected(false); + } catch (Exception err) { + this.logger.warn("Failed closing connection while removing idle Session: " + session); + } + } + + removeSession(session); + dispatchLostSessionEvent(session); + } + + private void dispatchLostSessionEvent(Session closedSession) { + Event event = new Event(TPEvents.SESSION_LOST); + event.setParameter(TPEvents.PARAM_SESSION, closedSession); + engine.dispatchEvent(event); + } + + private void dispatchSessionIdleEvent(Session idleSession) { + Event event = new Event(TPEvents.SESSION_IDLE); + event.setParameter(TPEvents.PARAM_SESSION, idleSession); + engine.dispatchEvent(event); + } + + /** + * 清理session 任务 + */ + private final class SessionCleaner implements ITaskHandler { + private SessionCleaner() { + } + + public void doTask(Task task) throws Exception { + applySessionCleaning(); + } + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/SystemController.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/SystemController.java new file mode 100644 index 0000000..ea6cd03 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/SystemController.java @@ -0,0 +1,322 @@ +package com.taurus.permanent.core; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.events.Event; +import com.taurus.core.events.EventManager; +import com.taurus.core.routes.Action; +import com.taurus.core.routes.ActionMapping; +import com.taurus.core.routes.IController; +import com.taurus.core.routes.Routes; +import com.taurus.core.service.IService; +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; + +/** + * 核心控制器基类 + * + * + */ +public class SystemController implements IService { + public static final String CONNECT_TOKE = "$t"; + public static final String CONNECT_PROT_COMPRESSION = "$pc"; + public static final String REQUEST_CMD = "$c"; + public static final String REQUEST_GID = "$gi"; + public static final String REQUEST_PARM = "$p"; + public static final String REQUEST_RESULT = "$r"; + + /** + * pingpong + */ + public static final int ACTION_PINGPONG = 0; + /** + * 客户端请求 + */ + public static final int ACTION_REQUST_CMD = 1; + /** + * 服务器事件消息 + */ + public static final int ACTION_EVENT_CMD = 2; + + private volatile boolean active; + private String name = "SystemController"; + private ThreadPoolExecutor threadPool; + + private final Logger logger; + private final TPServer taurus; + + private SessionManager sessionManager; + private ActionMapping actionMapping; + private final Routes routes; + + public SystemController() { + logger = Logger.getLogger(SystemController.class); + taurus = TPServer.me(); + sessionManager = taurus.getSessionManager(); + routes = new Routes(Routes.CONTROLLER_INSTANCE) { + public void config() { + } + }; + routes.setAddSlash(false); + } + + public void init(Object o) { + if (active) { + throw new IllegalArgumentException("Object is already initialized. Destroy it first!"); + } + threadPool = taurus.getExtensionExecutor(); + taurus.getExtension().configRoute(routes); + + actionMapping = new ActionMapping(routes); + actionMapping.buildActionMapping(); + active = true; + } + + public void destroy(Object o) { + active = false; + List leftOvers = threadPool.shutdownNow(); + EventManager eventManager = taurus.getEventManager(); + eventManager.removeAllListener(); + logger.info("SystemController stopping: " + getClass().getName() + ", Unprocessed tasks: " + leftOvers.size()); + } + + public void enqueueRequest(Packet request) { + threadPool.execute(new Runnable() { + @Override + public void run() { + if (active) { + try { + processRequest(request); + } catch (Exception e) { + logger.error(e); + } + } + } + }); + } + + private final void processRequest(Packet packet) throws Exception { + Session sender = packet.getSender(); + if (sender.isIdle() || sender.isMarkedForEviction()) + return; + if (!sessionManager.containsSession(sender)) { + logger.warn(" session is already expired!"); + return; + } + + byte reqId = (byte) packet.getId(); + + switch (reqId) { + case ACTION_PINGPONG: + onPingPong(sender); + break; + case ACTION_REQUST_CMD: + onRequest(sender, packet); + break; + } + } + + private final void onPingPong(Session sender) { + Packet packet = new Packet(); + packet.setId(ACTION_PINGPONG); + packet.setRecipient(sender); + packet.setData(new TObject()); + BitSwarmEngine.getInstance().write(packet); + } + + private final void onRequest(Session sender, Packet packet) throws Exception { + ITObject parm = (ITObject) packet.getData(); + String key = parm.getString(REQUEST_CMD); + Action action = actionMapping.getAction(key); + + if (action == null) { + return; + } + + IController controller = action.getController(); + if(controller == null) { + controller = action.getControllerClass().newInstance(); + } + int gid = 0; + if (parm.containsKey(REQUEST_GID)) + gid = parm.getInt(REQUEST_GID); + ITObject p = null; + if (parm.containsKey(REQUEST_PARM)) { + p = parm.getTObject(REQUEST_PARM); + } + if (action.getInterceptor() != null) { + action.getInterceptor().intercept(action, controller,sender,p,gid); + } else { + action.getMethod().invoke(controller,sender,p,gid); + } + + } + + /** + * 断开session + * + * @param session + */ + public void disconnect(Session session) { + if (session == null) { + throw new RuntimeException("Session object is null."); + } + + try { + if (session.getHashId() != null) { + Event evt = new Event(TPEvents.EVENT_SESSION_DISCONNECT); + evt.setParameter(TPEvents.PARAM_SESSION, session); + taurus.getEventManager().dispatchEvent(evt); + session.setHashId(null); + } + if (session.isConnected()) { + session.close(); + } + } catch (IOException err) { + throw new RuntimeException(err); + } + } + + /** + * 发送事件给单一客户端 + * + * @param actionKey 事件协议号 + * @param params 数据参数 + * @param recipient 客户端session + */ + public void sendEvent(String actionKey, ITObject params, Session recipient) { + if(!recipient.isConnected())return; + List msgRecipients = new ArrayList(); + msgRecipients.add(recipient); + sendEvent(actionKey, params, msgRecipients); + } + + /** + * 发送事件给单一客户端 + * + * @param actionKey 事件协议号 + * @param params 数据参数 + * @param recipient 客户端session + */ + public void sendEvent(String actionKey, int weightId, ITObject params, Session recipient) { + if(!recipient.isConnected())return; + List msgRecipients = new ArrayList(); + msgRecipients.add(recipient); + sendEvent(actionKey, weightId, params, msgRecipients); + } + + /** + * 发送事件给客户端 + * + * @param actionKey 事件协议号 + * @param params 数据参数 + * @param recipients 客户端session列表 + */ + public void sendEvent(String actionKey, ITObject params, List recipients) { + ITObject resObj = TObject.newInstance(); + resObj.putString(REQUEST_CMD, actionKey); + if (params != null) { + resObj.putTObject(REQUEST_PARM, params); + } + Packet packet = new Packet(); + packet.setId(ACTION_EVENT_CMD); + packet.setData(resObj); + packet.setRecipients(recipients); + BitSwarmEngine.getInstance().write(packet); + } + + /** + * 发送事件给客户端 + * + * @param actionKey 事件协议号 + * @param params 数据参数 + * @param recipients 客户端session列表 + */ + public void sendEvent(String actionKey, int weightId, ITObject params, List recipients) { + ITObject resObj = TObject.newInstance(); + resObj.putString(REQUEST_CMD, actionKey); + if (params != null) { + resObj.putTObject(REQUEST_PARM, params); + } + Packet packet = new Packet(); + packet.setId(ACTION_EVENT_CMD); + packet.setData(resObj); + packet.setRecipients(recipients); + BitSwarmEngine.getInstance().write(packet, weightId); + } + + /** + * 动态响应客户端请示 + * + * @param gid + * @param result 响应结果 0成功 + * @param params 数据参数 + * @param recipient 客户端session + */ + public void sendResponse(int gid,int result, ITObject params, Session recipient) { + if(gid==0)return; + if(!recipient.isConnected())return; + ITObject resObj = TObject.newInstance(); + resObj.putInt(SystemController.REQUEST_RESULT, result); + resObj.putInt(SystemController.REQUEST_GID, gid); + if (params != null) { + resObj.putTObject(SystemController.REQUEST_PARM, params); + } + Packet packet = new Packet(); + packet.setId(SystemController.ACTION_REQUST_CMD); + packet.setData(resObj); + packet.setRecipient(recipient); + BitSwarmEngine.getInstance().write(packet); + } + + /** + * 动态响应客户端请示 + * + * @param gid + * @param result 响应结果 0成功 + * @param params 数据参数 + * @param recipient 客户端session + */ + public void sendResponse(int gid,int result, int weightId, ITObject params, Session recipient) { + if(gid==0)return; + if(!recipient.isConnected())return; + ITObject resObj = TObject.newInstance(); + resObj.putInt(SystemController.REQUEST_RESULT, result); + resObj.putInt(SystemController.REQUEST_GID, gid); + if (params != null) { + resObj.putTObject(SystemController.REQUEST_PARM, params); + } + Packet packet = new Packet(); + packet.setId(SystemController.ACTION_REQUST_CMD); + packet.setData(resObj); + packet.setRecipient(recipient); + BitSwarmEngine.getInstance().write(packet, weightId); + } + + public final Logger getLogger() { + return logger; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public boolean isActive() { + return active; + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/core/TPEvents.java b/taurus-permanent/src/main/java/com/taurus/permanent/core/TPEvents.java new file mode 100644 index 0000000..0f0eb50 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/core/TPEvents.java @@ -0,0 +1,28 @@ +package com.taurus.permanent.core; + +/** + * TPEvents + * + * + */ +public class TPEvents { + /** + * session丢失或被清理时间 + */ + public static final String SESSION_LOST = "sessionLost"; + /** + * session空闲事件 + */ + public static final String SESSION_IDLE = "sessionIdle"; + /** + * 完成检测需要清理的session事件 + */ + public static final String SESSION_IDLE_CHECK_COMPLETE = "sessionIdleCheckComplete"; + /** + * session断开连接事件 + */ + public static final String EVENT_SESSION_DISCONNECT = "session_disconnect"; + + public static final String PARAM_SESSION = "session"; + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/BindableSocket.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/BindableSocket.java new file mode 100644 index 0000000..a4bd191 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/BindableSocket.java @@ -0,0 +1,37 @@ +package com.taurus.permanent.data; + +import java.nio.channels.SelectableChannel; + +/** + * BindableSocket + * + */ +public class BindableSocket { + protected SelectableChannel channel; + private String address; + private int port; + + public BindableSocket(SelectableChannel channel, String address, int port) { + this.address = address; + this.port = port; + + this.channel = channel; + } + + public SelectableChannel getChannel() { + return channel; + } + + public String getAddress() { + return address; + } + + public int getPort() { + return port; + } + + + public String toString() { + return String.format("%s[%d]", address, port); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/IPacketQueue.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/IPacketQueue.java new file mode 100644 index 0000000..b7bd82d --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/IPacketQueue.java @@ -0,0 +1,66 @@ +package com.taurus.permanent.data; + +/** + * 网络包队列接口 + * + */ +public interface IPacketQueue { + /** + * 返回队列头部的元素 + * @return + */ + public Packet peek(); + + /** + * 移除并返回队列头部的元素 + * @return + */ + public Packet take(); + + /** + * 队列是否为空 + * @return + */ + public boolean isEmpty(); + + /** + * 队列是否已满 + * @return + */ + public boolean isFull(); + + /** + * 获取队列当前大小 + * @return + */ + public int getSize(); + + /** + * 获取队列最大大小 + * @return + */ + public int getMaxSize(); + + /** + * 设置队列最大大小 + * @param size + */ + public void setMaxSize(int size); + + /** + * 队列当前使用百分比 + * @return + */ + public float getPercentageUsed(); + + /** + * 清理队列 + */ + public void clear(); + + /** + * 添加一个元素 + * @param packet + */ + public void put(Packet packet); +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/ISocketChannel.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/ISocketChannel.java new file mode 100644 index 0000000..4b1709e --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/ISocketChannel.java @@ -0,0 +1,21 @@ +package com.taurus.permanent.data; + +import java.io.IOException; +import java.net.SocketAddress; +import java.nio.ByteBuffer; + +public interface ISocketChannel{ + long write(ByteBuffer buffer); + + void write(final String p0); + + boolean checkConnection(); + + Object getChannel(); + + SocketAddress getRemoteAddress(); + + SocketAddress getLocalAddress(); + + void close() throws IOException; +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/NonBlockingPacketQueue.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/NonBlockingPacketQueue.java new file mode 100644 index 0000000..83fc0e1 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/NonBlockingPacketQueue.java @@ -0,0 +1,82 @@ +package com.taurus.permanent.data; + +import java.util.LinkedList; + +/** + * 非阻塞网络包队列 + * + */ +public final class NonBlockingPacketQueue implements IPacketQueue { + private final LinkedList queue; + private int maxSize; + + public NonBlockingPacketQueue(int maxSize) { + this.queue = new LinkedList(); + this.maxSize = maxSize; + } + + public void clear() { + synchronized (this.queue) { + queue.clear(); + } + } + + public int getSize() { + return queue.size(); + } + + public int getMaxSize() { + return maxSize; + } + + public boolean isEmpty() { + return queue.size() == 0; + } + + public boolean isFull() { + return queue.size() >= maxSize; + } + + public float getPercentageUsed() { + if (this.maxSize == 0) { + return 0.0F; + } + return queue.size() * 100 / maxSize; + } + + public Packet peek() { + Packet packet = null; + + synchronized (this.queue) { + if (!isEmpty()) { + packet = queue.get(0); + } + } + return packet; + } + + public void put(Packet packet){ + if (isFull()) { + throw new RuntimeException("packet is full!"); + } + + synchronized (queue) { + queue.addLast(packet); + } + } + + public void setMaxSize(int size) { + maxSize = size; + } + + public Packet take() { + Packet packet = null; + + synchronized (queue) { + packet = queue.removeFirst(); + } + + return packet; + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/PackDataType.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/PackDataType.java new file mode 100644 index 0000000..884a912 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/PackDataType.java @@ -0,0 +1,6 @@ +package com.taurus.permanent.data; + +public enum PackDataType { + BINARY, + TEXT +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/Packet.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/Packet.java new file mode 100644 index 0000000..efd4d27 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/Packet.java @@ -0,0 +1,94 @@ +package com.taurus.permanent.data; + +import java.util.ArrayList; +import java.util.List; + +/** + * Packet data object + * + */ +public class Packet { + protected int id; + protected Object data; + protected Session sender; + protected List recipients; + protected byte[] fragmentBuffer; + protected PackDataType dataType = PackDataType.BINARY; + + + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Object getData() { + return this.data; + } + + public void setData(Object data) { + this.data = data; + } + + public Session getSender() { + return this.sender; + } + + public void setSender(Session sender) { + this.sender = sender; + } + + public List getRecipients() { + return this.recipients; + } + + public void setRecipients(List recipients) { + this.recipients = recipients; + } + + public void setRecipient(Session session) { + List recipients = new ArrayList(); + recipients.add(session); + setRecipients(recipients); + } + + public boolean isFragmented() { + return this.fragmentBuffer != null; + } + + public byte[] getFragmentBuffer() { + return this.fragmentBuffer; + } + + public void setFragmentBuffer(byte[] bb) { + this.fragmentBuffer = bb; + } + + public PackDataType getDataType() { + return dataType; + } + + public void setDataType(PackDataType dataType) { + this.dataType = dataType; + } + + public String toString() { + return String.format("{ data: %s }", data.getClass().getName()); + } + + public Packet clone() { + Packet newPacket = new Packet(); + newPacket.id = this.id; + newPacket.data = data; + List recipients = new ArrayList(); + recipients.addAll(this.recipients); + newPacket.recipients = recipients; + newPacket.sender = this.sender; + newPacket.dataType = this.dataType; + newPacket.fragmentBuffer = this.fragmentBuffer; + return newPacket; + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/Session.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/Session.java new file mode 100644 index 0000000..95ba371 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/Session.java @@ -0,0 +1,467 @@ +package com.taurus.permanent.data; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import com.taurus.permanent.core.SessionManager; + +/** + * 核心用户session对象 + * + */ +public final class Session { + public static final String DATA_BUFFER = "session_data_buffer"; + public static final String PACKET_READ_STATE = "read_state"; + private static final String NO_IP = "NO_IP"; + + + private static AtomicInteger idCounter = new AtomicInteger(0); + + private volatile long readBytes = 0L; + private volatile long writtenBytes = 0L; + private volatile int droppedMessages = 0; + private ISocketChannel connection; + private volatile long creationTime; + private volatile long lastReadTime; + private volatile long lastWriteTime; + private volatile long lastActivityTime; + private int id; + private volatile String hashId; + private SessionType type; + private volatile String clientIpAddress = NO_IP; + private volatile int clientPort; + private int serverPort; + private String serverAddress; + private int timeout; + private volatile boolean frozen = false; + private boolean markedForEviction = false; + private volatile boolean connected = false; + private IPacketQueue packetQueue; + private Map systemProperties; + + public Session() { + creationTime = lastReadTime = lastWriteTime = lastActivityTime = System.currentTimeMillis(); + + setId(getUniqueId()); + + systemProperties = new ConcurrentHashMap(); + } + + private static int getUniqueId() { + return idCounter.incrementAndGet(); + } + + /** + * 统计当前session接收字节流大小 + * @param amount + */ + public void addReadBytes(long amount) { + this.readBytes += amount; + } + + /** + * 统计当前session发送字节流大小 + * @param amount + */ + public void addWrittenBytes(long amount) { + this.writtenBytes += amount; + } + + /** + * 获取channe连接对象 + * @return + */ + public ISocketChannel getConnection() { + return this.connection; + } + + /** + * 获取session创建时间 + * @return + */ + public long getCreationTime() { + return this.creationTime; + } + + /** + * 获取hashid + * @return + */ + public String getHashId() { + return this.hashId; + } + + /** + * 获取session id + * @return + */ + public int getId() { + return this.id; + } + + /** + * 获取客户端详细地址 + * @return + */ + public String getFullIpAddress() { + return clientPort > 0 ? getAddress() + ":" + clientPort : getAddress(); + } + + /** + * 获取客户端地址 + * @return + */ + public String getAddress() { + return this.clientIpAddress; + } + + /** + * 获取客户端端口 + * @return + */ + public int getClientPort() { + return this.clientPort; + } + + /** + * 获取服务器监听端口 + * @return + */ + public int getServerPort() { + return this.serverPort; + } + + /** + * 获取服务器详细地址 + * @return + */ + public String getFullServerIpAddress() { + return this.serverAddress + ":" + this.serverPort; + } + + /** + * 获取服务器地址 + * @return + */ + public String getServerAddress() { + return this.serverAddress; + } + + /** + * 获取最后激活时间 + * @return + */ + public long getLastActivityTime() { + return this.lastActivityTime; + } + + /** + * 获取最后读时间 + * @return + */ + public long getLastReadTime() { + return this.lastReadTime; + } + + /** + * 获取最后写时间 + * @return + */ + public long getLastWriteTime() { + return this.lastWriteTime; + } + + /** + * 获取超时时间 + * @return + */ + public int getTimeout() { + return this.timeout; + } + + /** + * 获取网络包队列 + * @return + */ + public IPacketQueue getPacketQueue() { + return this.packetQueue; + } + + /** + * 获取服务器内部属性 + * @param key + * @return + */ + public Object getSystemProperty(String key) { + return this.systemProperties.get(key); + } + + /** + * 获取属性 + * @param key + */ + public void removeSystemProperty(String key) { + this.systemProperties.remove(key); + } + + /** + * 获取session类型 + * @return + */ + public SessionType getType() { + return this.type; + } + + /** + * 获取当前session接收字节流大小 + * @return + */ + public long getReadBytes() { + return this.readBytes; + } + + /** + * 获取当前session发送字节流大小 + * @return + */ + public long getWrittenBytes() { + return this.writtenBytes; + } + + /** + * 当前连接状态 + * @return + */ + public boolean isConnected() { + return this.connected; + } + + /** + * 设置连接状态 + * @param value + */ + public void setConnected(boolean value) { + this.connected = value; + } + + + /** + * session 是否空闲,做超时踢出处理 + * @return + */ + public boolean isIdle() { + return isSocketIdle(); + } + + private boolean isSocketIdle() { + boolean isIdle = false; + + if (this.timeout > 0) { + long elapsedSinceLastActivity = System.currentTimeMillis() - this.lastActivityTime; + isIdle = elapsedSinceLastActivity / 1000L > this.timeout; + } + + return isIdle; + } + + public boolean isMarkedForEviction() { + return this.markedForEviction; + } + + /** + * 设置channel连接对象 + * @param connection + */ + public void setConnection(ISocketChannel connection) { + if (connection == null) { + return; + } + + if (this.connection != null) { + throw new IllegalArgumentException("You cannot overwrite the connection linked to a Session!"); + } + if(connection.checkConnection()) { + setSocketConnection(connection); + this.connected = true; + } + } + + private void setSocketConnection(ISocketChannel connection) { + this.connection = connection; + String svr_host = connection.getLocalAddress().toString().substring(1); + String[] svr_adr =svr_host.split("\\:"); + this.serverAddress = svr_adr[0]; + try { + this.serverPort = Integer.parseInt(svr_adr[1]); + } catch (NumberFormatException localNumberFormatException) { + } + + + String client_host = connection.getRemoteAddress().toString().substring(1); + String[] client_adr = client_host.split("\\:"); + this.clientIpAddress = client_adr[0]; + try { + this.clientPort = Integer.parseInt(client_adr[1]); + } catch (NumberFormatException localNumberFormatException) { + } + + } + + /** + * 设置网络包队列 + * @param queue + */ + public void setPacketQueue(IPacketQueue queue) { + if (this.packetQueue != null) { + throw new IllegalStateException("Cannot reassing the packet queue. Queue already exists!"); + } + this.packetQueue = queue; + } + + /** + * 设置创建时间 + * @param timestamp + */ + public void setCreationTime(long timestamp) { + this.creationTime = timestamp; + } + + /** + * 设置hashID + * @param hash + */ + public void setHashId(String hash) { + this.hashId = hash; + } + + /** + * 设置session id + * @param id + */ + public void setId(int id) { + this.id = id; + } + + /** + * 设置最后读取网络字节时间 + * @param timestamp + */ + public void setLastReadTime(long timestamp) { + this.lastReadTime = timestamp; + if(this.hashId!=null) { + this.lastActivityTime = timestamp; + } + } + + /** + * 设置最后写网络字节时间 + * @param timestamp + */ + public void setLastWriteTime(long timestamp) { + this.lastWriteTime = timestamp; + if(this.hashId!=null) { + this.lastActivityTime = timestamp; + } + } + + public void updateLastActivityTime() { + this.lastActivityTime = System.currentTimeMillis(); + } + + /** + * session 标记为驱逐 + */ + public void setMarkedForEviction() { + this.markedForEviction = true; + this.frozen = true; + } + + /** + * 设置超时时间 + * @param idleTime + */ + public void setTimeout(int idleTime) { + this.timeout = idleTime; + } + + /** + * 设置服务器内部属性 + * @param key + * @param property + */ + public void setSystemProperty(String key, Object property) { + this.systemProperties.put(key, property); + } + + /** + * 设置session 类型 + * @param type + */ + public void setType(SessionType type) { + this.type = type; + + if (type == SessionType.VOID) { + this.clientIpAddress = NO_IP; + this.clientPort = 0; + } + } + + /** + * 获取丢包数量 + * @return + */ + public int getDroppedMessages() { + return this.droppedMessages; + } + + /** + * 统计丢包数量 + */ + public void addDroppedMessages(int amount) { + this.droppedMessages += amount; + } + + /** + * session 是否被冻结 + * @return + */ + public boolean isFrozen() { + return this.frozen; + } + + /** + * 关闭session + * @throws IOException + */ + public void close() throws IOException { + this.packetQueue = null; + this.frozen = true; + try { + if(connection!=null) { + connection.close(); + } + } finally { + connected = false; + SessionManager.getInstance().removeSession(this); + } + } + + public String toString() { + return String.format("{ Id: %s, Type: %s, IP: %s }", id + (hashId!=null ? ("[" + this.hashId + "]") : ""), type, getFullIpAddress()); + } + + public boolean equals(Object obj) { + if (!(obj instanceof Session)) { + return false; + } + boolean isEqual = false; + Session session = (Session) obj; + + if (session.getId() == this.id) { + isEqual = true; + } + return isEqual; + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/data/SessionType.java b/taurus-permanent/src/main/java/com/taurus/permanent/data/SessionType.java new file mode 100644 index 0000000..3e0b480 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/data/SessionType.java @@ -0,0 +1,17 @@ +package com.taurus.permanent.data; + +/** + * session 类型 + * + */ +public enum SessionType{ + /** + * 普通 tcp udp 长链接 + */ + NORMAL, + /** + * websocket 长链接 + */ + WEBSOCKET, + VOID +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/BinaryIoHandler.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/BinaryIoHandler.java new file mode 100644 index 0000000..9309052 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/BinaryIoHandler.java @@ -0,0 +1,242 @@ +package com.taurus.permanent.io; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; + +/** + * 协议包字节流解析 + * + */ +public class BinaryIoHandler { + + private static final int INT_SIZE = 4; + private final Logger log; + private final BitSwarmEngine engine; + private volatile long packetsRead = 0L; + private volatile long droppedIncomingPackets = 0L; + private final int maxPacketSize; + + public BinaryIoHandler(IOHandler parentHandler) { + this.log = Logger.getLogger(getClass()); + this.engine = BitSwarmEngine.getInstance(); + this.maxPacketSize = engine.getConfig().maxPacketSize; + } + + public long getReadPackets() { + return this.packetsRead; + } + + public long getIncomingDroppedPackets() { + return this.droppedIncomingPackets; + } + + public void handleWrite(Packet packet) throws Exception { + engine.getProtocolHandler().onPacketWrite(packet); + int protocolCompressionThreshold = TPServer.me().getConfig().protocolCompression; + byte[] binData = null; + try { + binData = ((TObject)packet.getData()).toBinary(); + } catch (Exception e) { + log.error(e); + log.error(((TObject)packet.getData()).toString()); + log.error(((TObject)packet.getData()).toJson()); + return; + } + boolean compression = binData.length > protocolCompressionThreshold; + if(compression) { + binData = Utils.compress(binData); + } + ByteBuffer packetBuffer = ByteBuffer.allocate(INT_SIZE + 1 + binData.length); + packetBuffer.put(compression?(byte)1:(byte)0); + packetBuffer.putInt(binData.length); + packetBuffer.put(binData); + packet.setData(packetBuffer.array()); + engine.getSocketWriter().enqueuePacket(packet); + } + + public void handleRead(Session session, byte[] data) { + + PacketReadState readState = (PacketReadState) session.getSystemProperty(Session.PACKET_READ_STATE); + try { + while (data.length > 0) { + if (readState == PacketReadState.WAIT_NEW_PACKET) { + ProcessedPacket process = handleNewPacket(session, data); + readState = process.getState(); + data = process.getData(); + } + + if (readState == PacketReadState.WAIT_DATA_SIZE) { + ProcessedPacket process = handleDataSize(session, data); + readState = process.getState(); + data = process.getData(); + } + + if (readState == PacketReadState.WAIT_DATA_SIZE_FRAGMENT) { + ProcessedPacket process = handleDataSizeFragment(session, data); + readState = process.getState(); + data = process.getData(); + } + + if (readState != PacketReadState.WAIT_DATA) + continue; + ProcessedPacket process = handlePacketData(session, data); + readState = process.getState(); + data = process.getData(); + } + + } catch (Exception err) { + this.log.error(err); + readState = PacketReadState.WAIT_NEW_PACKET; + } + + session.setSystemProperty(Session.PACKET_READ_STATE, readState); + } + + private ProcessedPacket handleNewPacket(Session session, byte[] data) { + PendingPacket pp = new PendingPacket(); + pp.compressed = data[0] > 0; + session.setSystemProperty(Session.DATA_BUFFER, pp); + data = Utils.resizeByteArray(data, 1, data.length - 1); + return new ProcessedPacket(PacketReadState.WAIT_DATA_SIZE, data); + } + + private ProcessedPacket handleDataSize(Session session, byte[] data) { + PacketReadState state = PacketReadState.WAIT_DATA; + PendingPacket pending = (PendingPacket) session.getSystemProperty(Session.DATA_BUFFER); + int dataSize = -1; + int sizeBytes = INT_SIZE; + + if (data.length >= INT_SIZE) { + dataSize = 0; + for (int i = 0; i < INT_SIZE; i++) { + int pow256 = (int) Math.pow(256.0D, 3 - i); + int intByte = data[i] & 0xFF; + dataSize += pow256 * intByte; + } + } + + if (dataSize != -1) { + validateIncomingDataSize(session, dataSize); + pending.setExpectedLen(dataSize); + pending.setBuffer(ByteBuffer.allocate(dataSize)); + data = Utils.resizeByteArray(data, sizeBytes, data.length - sizeBytes); + } else { + state = PacketReadState.WAIT_DATA_SIZE_FRAGMENT; + ByteBuffer sizeBuffer = ByteBuffer.allocate(INT_SIZE); + sizeBuffer.put(data); + pending.setBuffer(sizeBuffer); + data = new byte[0]; + } + return new ProcessedPacket(state, data); + } + + private ProcessedPacket handleDataSizeFragment(Session session, byte[] data) { + PacketReadState state = PacketReadState.WAIT_DATA_SIZE_FRAGMENT; + PendingPacket pending = (PendingPacket) session.getSystemProperty(Session.DATA_BUFFER); + ByteBuffer sizeBuffer = (ByteBuffer) pending.getBuffer(); + + int remaining = INT_SIZE - sizeBuffer.position(); + + if (data.length >= remaining) { + sizeBuffer.put(data, 0, remaining); + sizeBuffer.flip(); + int dataSize = sizeBuffer.getInt(); + + validateIncomingDataSize(session, dataSize); + pending.setExpectedLen(dataSize); + pending.setBuffer(ByteBuffer.allocate(dataSize)); + state = PacketReadState.WAIT_DATA; + + if (data.length > remaining) + data = Utils.resizeByteArray(data, remaining, data.length - remaining); + else { + data = new byte[0]; + } + + } else { + sizeBuffer.put(data); + data = new byte[0]; + } + + return new ProcessedPacket(state, data); + } + + private ProcessedPacket handlePacketData(Session session, byte[] data) throws Exception { + PacketReadState state = PacketReadState.WAIT_DATA; + PendingPacket pending = (PendingPacket) session.getSystemProperty(Session.DATA_BUFFER); + ByteBuffer dataBuffer = (ByteBuffer) pending.getBuffer(); + int readLen = dataBuffer.remaining(); + boolean isThereMore = data.length > readLen; + + if (data.length >= readLen) { + dataBuffer.put(data, 0, readLen); + + if (pending.getExpectedLen() != dataBuffer.capacity()) { + throw new IllegalStateException("Expected: " + pending.getExpectedLen() + ", Buffer size: " + dataBuffer.capacity()); + } + final byte[] tembytes = dataBuffer.array(); + final boolean compressed = pending.compressed; + dispatchRequest(session,tembytes,compressed); + this.packetsRead += 1L; + state = PacketReadState.WAIT_NEW_PACKET; + + } else { + dataBuffer.put(data); + } + + if (isThereMore) + data = Utils.resizeByteArray(data, readLen, data.length - readLen); + else { + data = new byte[0]; + } + return new ProcessedPacket(state, data); + } + + + private void dispatchRequest(Session session, byte[] data,boolean compressed) { + if(compressed) { + try { + data = Utils.uncompress(data); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + ITObject requestObject = TObject.newFromBinaryData(data); + Packet newPacket = new Packet(); + newPacket.setSender(session); + newPacket.setData(requestObject); + engine.getProtocolHandler().onPacketRead(newPacket); + } + + /** + * 验证字节流数据大小 + * @param session + * @param dataSize + */ + private void validateIncomingDataSize(Session session, int dataSize) { + String who = session.toString(); + + if (dataSize < 1) { + this.droppedIncomingPackets += 1L; + throw new IllegalArgumentException("Illegal request size: " + dataSize + " bytes, from: " + who); + } + + if (dataSize > this.maxPacketSize) { + TPServer.me().getController().disconnect(session); + this.droppedIncomingPackets += 1L; + + throw new IllegalArgumentException(String.format("Incoming request size too large: %s, Current limit: %s, From: %s", dataSize, this.maxPacketSize, who)); + } + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/IOHandler.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/IOHandler.java new file mode 100644 index 0000000..6ad430c --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/IOHandler.java @@ -0,0 +1,73 @@ +package com.taurus.permanent.io; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; + +/** + * 读写网络字节流 + * + */ +public class IOHandler { + private final BinaryIoHandler binHandler; + private final Logger logger; + + public IOHandler() { + logger = Logger.getLogger(getClass()); + binHandler = new BinaryIoHandler(this); + + } + + /** + * 读取网络包字节流 + * @param session + * @param data + */ + public void onDataRead(Session session, byte[] data) { + if ((data == null) || (data.length < 1)) { + throw new IllegalArgumentException("Unexpected null or empty byte array!"); + } + + PacketReadState readState = (PacketReadState) session.getSystemProperty(Session.PACKET_READ_STATE); + if(readState==null){ + if (data[0] == 60) { + return; + } + session.setSystemProperty(Session.PACKET_READ_STATE, PacketReadState.WAIT_NEW_PACKET); + } + + binHandler.handleRead(session, data); + } + + /** + * 数据写入网络字节流,发送给指定客户端 + * @param packet + */ + public void onDataWrite(Packet packet) { + if (packet.getRecipients().size() > 0) { + try { + this.binHandler.handleWrite(packet); + } catch (Exception e) { + logger.error(e); + } + } + } + + /** + * 统计丢包数量 + * @return + */ + public long getReadPackets() { + return binHandler.getReadPackets(); + } + + /** + * 统计丢包数量 + * @return + */ + public long getIncomingDroppedPackets() { + return binHandler.getIncomingDroppedPackets(); + } + + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/PacketReadState.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/PacketReadState.java new file mode 100644 index 0000000..6bcdbad --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/PacketReadState.java @@ -0,0 +1,21 @@ +package com.taurus.permanent.io; + +/** + * PacketReadState + * + */ +public enum PacketReadState { + /** + * 等待新包读取 + */ + WAIT_NEW_PACKET, + /** + * 等待读取包大小 + */ + WAIT_DATA_SIZE, + /** + * 等待读取碎片包 + */ + WAIT_DATA_SIZE_FRAGMENT, + WAIT_DATA; +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/PendingPacket.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/PendingPacket.java new file mode 100644 index 0000000..6b6a059 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/PendingPacket.java @@ -0,0 +1,37 @@ +package com.taurus.permanent.io; + +/** + * PendingPacket + * + */ +public class PendingPacket { + private Object buffer; + private int expectedLen = -1; + public boolean compressed; + + public PendingPacket() { + + } + + + + public Object getBuffer() { + return buffer; + } + + public void setBuffer(Object buffer) { + this.buffer = buffer; + } + + public int getExpectedLen() { + return this.expectedLen; + } + + public void setExpectedLen(int len) { + this.expectedLen = len; + } + + public String toString() { + return buffer.toString(); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/ProcessedPacket.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/ProcessedPacket.java new file mode 100644 index 0000000..741e0e3 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/ProcessedPacket.java @@ -0,0 +1,23 @@ +package com.taurus.permanent.io; + +/** + * ProcessedPacket + * + */ +public class ProcessedPacket { + private byte[] data; + private PacketReadState state; + + public ProcessedPacket(PacketReadState state, byte[] data) { + this.state = state; + this.data = data; + } + + public byte[] getData() { + return data; + } + + public PacketReadState getState() { + return state; + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/io/ProtocolHandler.java b/taurus-permanent/src/main/java/com/taurus/permanent/io/ProtocolHandler.java new file mode 100644 index 0000000..2a3e4f9 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/io/ProtocolHandler.java @@ -0,0 +1,42 @@ +package com.taurus.permanent.io; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Packet; + +/** + * ProtocolHandler + * + * + */ +public class ProtocolHandler { + private static final String ACTION_ID = "a"; + private static final String PARAM_ID = "p"; + + public void onPacketWrite(Packet packet) { + ITObject params = TObject.newInstance(); + params.putByte(ACTION_ID, (byte) packet.getId()); + params.putTObject(PARAM_ID, (ITObject) packet.getData()); + packet.setData(params); + } + + public void onPacketRead(Packet packet) { + ITObject requestObject = (ITObject)packet.getData(); + if (requestObject.isNull(ACTION_ID)) { + throw new IllegalStateException("Request rejected: No Action ID in request!"); + } + if (requestObject.isNull(PARAM_ID)) { + throw new IllegalStateException("Request rejected: Missing parameters field!"); + } + + packet.setId(requestObject.getByte(ACTION_ID)); + if(requestObject.containsKey(PARAM_ID)) { + packet.setData(requestObject.getTObject(PARAM_ID)); + }else { + packet.setData(null); + } + + TPServer.me().getController().enqueueRequest(packet); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/normal/NormalSocketChannel.java b/taurus-permanent/src/main/java/com/taurus/permanent/normal/NormalSocketChannel.java new file mode 100644 index 0000000..1d3d67f --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/normal/NormalSocketChannel.java @@ -0,0 +1,71 @@ +package com.taurus.permanent.normal; + +import java.io.IOException; +import java.net.Socket; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +import com.taurus.permanent.data.ISocketChannel; + +public class NormalSocketChannel implements ISocketChannel{ + private final SocketChannel channel; + + public NormalSocketChannel(SocketChannel channel) { + this.channel = channel; + } + @Override + public long write(ByteBuffer buffer) { + try { + return channel.write(buffer); + } catch (IOException e) { + return 0; + } + } + + @Override + public void write(String p0) { + // TODO Auto-generated method stub + + } + + @Override + public SocketAddress getRemoteAddress() { + if(checkConnection()) { + return channel.socket().getRemoteSocketAddress(); + } + return null; + } + + @Override + public SocketAddress getLocalAddress() { + if(checkConnection()) { + return channel.socket().getLocalSocketAddress(); + } + return null; + } + + @Override + public void close() throws IOException{ + Socket socket = channel.socket(); + if ((socket != null) && (!socket.isClosed())) { + socket.shutdownInput(); + socket.shutdownOutput(); + socket.close(); + channel.close(); + } + } + @Override + public Object getChannel() { + return channel; + } + + @Override + public boolean checkConnection() { + if((channel != null) && (channel.socket() != null) && (!channel.socket().isClosed())) { + return true; + } + return false; + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketAcceptor.java b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketAcceptor.java new file mode 100644 index 0000000..e7ecc9d --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketAcceptor.java @@ -0,0 +1,259 @@ +package com.taurus.permanent.normal; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.core.BaseCoreService; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.core.ConnectionFilter; +import com.taurus.permanent.core.DefaultConstants; +import com.taurus.permanent.core.ServerConfig.SocketAddress; +import com.taurus.permanent.core.SessionManager; +import com.taurus.permanent.data.BindableSocket; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.data.SessionType; + +/** + * SocketAcceptor + * + * + */ +public class SocketAcceptor extends BaseCoreService implements Runnable { + private final BitSwarmEngine engine; + private final Logger logger; + private volatile int threadId = 1; + private int threadPoolSize = 1; + private final ExecutorService threadPool; + private LinkedList acceptableConnections; + private List boundSockets; + + private SessionManager sessionManager; + private SocketReader socketReader; + private Selector acceptSelector; + private volatile boolean isActive = false; + + public SocketAcceptor(int threadPoolSize) { + this.threadPoolSize = threadPoolSize; + + engine = BitSwarmEngine.getInstance(); + logger = Logger.getLogger(SocketAcceptor.class); + + threadPool = Executors.newFixedThreadPool(threadPoolSize); + + acceptableConnections = new LinkedList(); + boundSockets = new ArrayList(); + socketReader = engine.getSocketReader(); + + try { + acceptSelector = Selector.open(); + logger.info("AcceptSelector opened"); + } catch (IOException e) { + logger.warn("Problems during SocketAcceptor init: " + e); + logger.error(e); + } + } + + public void init(Object o) { + super.init(o); + if (isActive) { + throw new IllegalArgumentException("Object is already initialized. Destroy it first!"); + } + if (threadPoolSize < 1) { + throw new IllegalArgumentException("Illegal value for a thread pool size: " + threadPoolSize); + } + sessionManager = engine.getSessionManager(); + + isActive = true; + initThreadPool(); + + logger.info("SocketAcceptor initialized (pool size:"+threadPoolSize+")"); + checkBoundSockets(); + } + + public void destroy(Object o) { + super.destroy(o); + + isActive = false; + shutDownBoundSockets(); + + List leftOvers = threadPool.shutdownNow(); + try { + Thread.sleep(500L); + + acceptSelector.close(); + } catch (Exception e) { + logger.warn("Error when shutting down Accept selector: " + e.getMessage()); + } + + logger.info("SocketAcceptor stopped. Unprocessed tasks: " + leftOvers.size()); + } + + private void initThreadPool() { + for (int j = 0; j < threadPoolSize; j++) + threadPool.execute(this); + } + + public void run() { + Thread.currentThread().setName("SocketAcceptor-" + threadId++); + + while (isActive) { + try { + acceptLoop(); + } catch (IOException e) { + logger.info("I/O Error with Accept Selector: " + e.getMessage()); + logger.error(e); + } + } + + logger.info("SocketAcceptor threadpool shutting down."); + } + + private void acceptLoop() throws IOException { + acceptSelector.select(); + List _list = null; + synchronized (acceptSelector) { + Set readyKeys = acceptSelector.selectedKeys(); + _list = new ArrayList(readyKeys); + readyKeys.clear(); + } + + for (SelectionKey key : _list) { + try { + ServerSocketChannel ssChannel = (ServerSocketChannel) key.channel(); + SocketChannel clientChannel = ssChannel.accept(); + synchronized (acceptableConnections) { + acceptableConnections.addLast(clientChannel); + } + } catch (IOException error) { + logger.info("I/O Error during accept loop: " + error.getMessage()); + } + } + + if (isActive) + socketReader.getSelector().wakeup(); + } + + public void handleAcceptableConnections() { + if (acceptableConnections.size() == 0) { + return; + } + SocketChannel connection = null; + synchronized (acceptableConnections) { + connection = acceptableConnections.removeFirst(); + } + if (connection == null) + return; + ConnectionFilter connectionFilter = engine.getConnectionFilter(); + + try { + Socket socket = connection.socket(); + InetAddress iAddr = null; + if (socket != null && !socket.isClosed()) { + iAddr = socket.getInetAddress(); + } + if (iAddr == null) { + handleAcceptableConnections(); + return; + } + if (!connectionFilter.validateAndAddAddress(iAddr.getHostAddress())) { + try { + connection.socket().shutdownInput(); + connection.socket().shutdownOutput(); + connection.close(); + } catch (IOException e1) { + logger.warn("Additional problem with refused connection. Was not able to shut down the channel: " + e1.getMessage()); + } + handleAcceptableConnections(); + return; + } + connection.configureBlocking(false); + connection.socket().setTcpNoDelay(engine.getConfig().tcpNoDelay); + + SelectionKey selectionKey = connection.register(socketReader.getSelector(), SelectionKey.OP_READ); + Session session = sessionManager.createSession(new NormalSocketChannel(connection), SessionType.NORMAL); + session.setSystemProperty(DefaultConstants.SESSION_SELECTION_KEY, selectionKey); + sessionManager.addSession(session); + } catch (IOException e) { + StringBuilder sb = new StringBuilder("Failed accepting connection: "); + + if ((connection != null) && (connection.socket() != null)) { + sb.append(connection.socket().getInetAddress().getHostAddress()); + } + logger.info(sb.toString()); + } + handleAcceptableConnections(); + } + + public void bindSocket(SocketAddress socketConfig) throws IOException { + if (socketConfig.type.equalsIgnoreCase(SocketAddress.TYPE_TCP)) { + bindTcpSocket(socketConfig.address, socketConfig.port); + } else + throw new UnsupportedOperationException("Invalid transport type!"); + } + + public List getBoundSockets() { + ArrayList list = null; + + synchronized (boundSockets) { + list = new ArrayList(boundSockets); + } + + return list; + } + + private void bindTcpSocket(String address, int port) throws IOException { + ServerSocketChannel socketChannel = ServerSocketChannel.open(); + socketChannel.configureBlocking(false); + socketChannel.socket().bind(new InetSocketAddress(address, port)); + socketChannel.socket().setReuseAddress(true); + socketChannel.register(acceptSelector, SelectionKey.OP_ACCEPT); + + synchronized (boundSockets) { + boundSockets.add(new BindableSocket(socketChannel, address, port)); + } + + logger.info("Added bound tcp socket --> " + address + ":" + port); + } + + private void checkBoundSockets() { + if (boundSockets.size() < 1) + logger.error("No bound sockets! Check the boot logs for possible problems!"); + } + + private void shutDownBoundSockets() { + List problematicSockets = null; + + for (BindableSocket bindableSocket : boundSockets) { + try { + bindableSocket.getChannel().close(); + } catch (IOException e) { + if (problematicSockets == null) { + problematicSockets = new ArrayList(); + } + problematicSockets.add(bindableSocket); + } + } + + if (problematicSockets != null) { + StringBuilder sb = new StringBuilder("Problems closing bound socket(s). The following socket(s) raised exceptions: "); + + for (BindableSocket socket : problematicSockets) { + sb.append(socket.toString()).append(" "); + } + throw new RuntimeException(sb.toString()); + } + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketReader.java b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketReader.java new file mode 100644 index 0000000..70e9de9 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketReader.java @@ -0,0 +1,231 @@ +package com.taurus.permanent.normal; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.CancelledKeyException; +import java.nio.channels.ClosedSelectorException; +import java.nio.channels.SelectableChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import com.taurus.core.util.FixedIndexThreadPool; +import com.taurus.core.util.FixedIndexThreadPool.Work; +import com.taurus.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.core.BaseCoreService; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.core.DefaultConstants; +import com.taurus.permanent.core.SessionManager; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.io.IOHandler; + +/** + * SocketReader + * + * + */ +public class SocketReader extends BaseCoreService implements Runnable { + private final BitSwarmEngine engine; + private final Logger logger; + private int threadPoolSize = 1; + private ExecutorService threadPool; + private FixedIndexThreadPool packetReaderPool; + private SessionManager sessionManager; + private SocketAcceptor socketAcceptor; + private SocketWriter socketWriter; + private Selector readSelector; + private IOHandler ioHandler; + private volatile boolean isActive = false; + private volatile long readBytes = 0L; + + public SocketReader(int nThreads) { + threadPoolSize = nThreads; + + engine = BitSwarmEngine.getInstance(); + logger = Logger.getLogger(getClass()); + try { + readSelector = Selector.open(); + logger.info("TCP Selector opened"); + } catch (IOException e) { + logger.error("Failed opening UDP Selector: " + e.toString()); + e.printStackTrace(); + } + } + + public void init(Object o) { + super.init(o); + if (isActive) { + throw new IllegalArgumentException("Object is already initialized. Destroy it first!"); + } + sessionManager = engine.getSessionManager(); + socketAcceptor = engine.getSocketAcceptor(); + socketWriter = engine.getSocketWriter(); + isActive = true; + initThreadPool(); + + logger.info("SocketReader started (pool size:"+threadPoolSize+")"); + } + + public void destroy(Object o) { + super.destroy(o); + + isActive = false; + List leftOvers = threadPool.shutdownNow(); + int pr_count = packetReaderPool.shutdown(); + try { + Thread.sleep(500L); + readSelector.close(); + } catch (Exception e) { + logger.warn("Error when shutting down TCP Selector: " + e.getMessage()); + logger.error(e); + } + + logger.info("SocketReader stopped. Unprocessed tasks: " + leftOvers.size()); + logger.info("PacketReader stopped. Unprocessed tasks: " + pr_count); + } + + public void initThreadPool() { + threadPool = Executors.newSingleThreadExecutor(); + threadPool.execute(this); + packetReaderPool = new FixedIndexThreadPool(threadPoolSize, "PacketReader", PacketReaderWork.class); + } + + public void run() { + Thread.currentThread().setName("SocketReader"); + + while (isActive) { + try { + socketAcceptor.handleAcceptableConnections(); + readIncomingSocketData(); + + Thread.sleep(5L); + } catch (Throwable t) { + logger.warn("Problems in SocketReader main loop: " + t + ", Thread: " + Thread.currentThread()); + logger.error(t); + } + } + + logger.info("SocketReader threadpool shutting down."); + } + + private void readIncomingSocketData() { + SocketChannel channel = null; + SelectionKey key = null; + try { + int readyKeyCount = readSelector.selectNow(); + + if (readyKeyCount > 0) { + Set readyKeys = readSelector.selectedKeys(); + + for (Iterator it = readyKeys.iterator(); it.hasNext();) { + key = (SelectionKey) it.next(); + it.remove(); + + if (!key.isValid()) { + continue; + } + channel = (SocketChannel) key.channel(); + Session session = sessionManager.getSessionByConnection(channel); + packetReaderPool.execute(session.getId(), session); + } + } + + } catch (ClosedSelectorException e) { + logger.debug("Selector is closed!"); + } catch (CancelledKeyException localCancelledKeyException) { + } catch (IOException ioe) { + logger.warn("I/O reading/selection error: " + ioe); + logger.error(ioe); + } catch (Exception err) { + logger.warn("Generic reading/selection error: " + err); + logger.error(err); + } + } + + private void readTcpData(Session session,SocketChannel channel, ByteBuffer readBuffer) throws IOException { + SelectionKey key = (SelectionKey) session.getSystemProperty(DefaultConstants.SESSION_SELECTION_KEY); + if (!key.isValid()) { + return; + } + if (key.isWritable()) { + key.interestOps(SelectionKey.OP_READ); + socketWriter.continueWriteOp(session); + } + if (!key.isReadable()) { + return; + } + readBuffer.clear(); + long byteCount = channel.read(readBuffer); + + if (byteCount == -1L) { + closeConnection(channel); + } else if (byteCount > 0L) { + session.setLastReadTime(System.currentTimeMillis()); + readBytes += byteCount; + session.addReadBytes(byteCount); + readBuffer.flip(); + byte[] binaryData = new byte[readBuffer.limit()]; + readBuffer.get(binaryData); + ioHandler.onDataRead(session, binaryData); + } + } + + private void closeConnection(SelectableChannel channel) throws IOException { + channel.close(); + if (channel instanceof SocketChannel) + sessionManager.onSocketDisconnected(channel); + } + + public IOHandler getIOHandler() { + return ioHandler; + } + + public Selector getSelector() { + return readSelector; + } + + public void setIoHandler(IOHandler handler) { + if (handler == null) { + throw new IllegalStateException("IOHandler si already set!"); + } + ioHandler = handler; + } + + public long getReadBytes() { + return readBytes; + } + + public long getReadPackets() { + return ioHandler.getReadPackets(); + } + + public static final class PacketReaderWork extends Work { + private ByteBuffer readBuffer; + private BitSwarmEngine engine; + private SocketReader reader; + + public PacketReaderWork() { + engine = BitSwarmEngine.getInstance(); + reader = (SocketReader) engine.getSocketReader(); + readBuffer = Utils.allocateBuffer(engine.getConfig().maxReadBufferSize, engine.getConfig().readBufferType); + } + + @Override + protected void handlerTask(Object task) throws Exception { + Session session = (Session) task; + SocketChannel channel = (SocketChannel) session.getConnection().getChannel(); + readBuffer.clear(); + try { + reader.readTcpData(session,channel, readBuffer); + } catch (IOException e) { + reader.closeConnection(channel); + } + } + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketWriter.java b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketWriter.java new file mode 100644 index 0000000..3bf0312 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/normal/SocketWriter.java @@ -0,0 +1,276 @@ +package com.taurus.permanent.normal; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectionKey; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; + +import com.taurus.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.BaseCoreService; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.core.DefaultConstants; +import com.taurus.permanent.core.ServerConfig; +import com.taurus.permanent.data.IPacketQueue; +import com.taurus.permanent.data.ISocketChannel; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.data.SessionType; +import com.taurus.permanent.io.IOHandler; + +/** + * SocketWriter + * + * + */ +public final class SocketWriter extends BaseCoreService implements Runnable { + private BitSwarmEngine engine; + private IOHandler ioHandler; + private final Logger logger; + private final ExecutorService threadPool; + private final BlockingQueue sessionTicketsQueue; + private volatile int threadId = 1; + private volatile boolean isActive = false; + private volatile long droppedPacketsCount = 0L; + private volatile long writtenBytes = 0L; + private volatile long writtenPackets = 0L; + private int threadPoolSize; + + public SocketWriter(int threadPoolSize) { + this.threadPoolSize = threadPoolSize; + + threadPool = Executors.newFixedThreadPool(threadPoolSize); + logger = Logger.getLogger(SocketWriter.class); + + sessionTicketsQueue = new LinkedBlockingQueue(); + } + + public void init(Object o) { + super.init(o); + + if (isActive) { + throw new IllegalArgumentException("Object is already initialized. Destroy it first!"); + } + if (threadPoolSize < 1) { + throw new IllegalArgumentException("Illegal value for a thread pool size: " + threadPoolSize); + } + engine = BitSwarmEngine.getInstance(); + isActive = true; + + initThreadPool(); + + logger.info("Socket Writer started (pool size:" + threadPoolSize + ")"); + } + + public void destroy(Object o) { + super.destroy(o); + + isActive = false; + List leftOvers = threadPool.shutdownNow(); + logger.info("SocketWriter stopped. Unprocessed tasks: " + leftOvers.size()); + } + + public int getQueueSize() { + return sessionTicketsQueue.size(); + } + + public int getThreadPoolSize() { + return threadPoolSize; + } + + public IOHandler getIOHandler() { + return ioHandler; + } + + public void setIOHandler(IOHandler ioHandler) { + if (this.ioHandler != null) { + throw new IllegalStateException("You cannot reassign the IOHandler class!"); + } + this.ioHandler = ioHandler; + } + + public void continueWriteOp(Session session) { + if (session != null) + sessionTicketsQueue.add(session); + } + + private void initThreadPool() { + for (int j = 0; j < threadPoolSize; j++) + threadPool.execute(this); + } + + public void run() { + Thread.currentThread().setName("SocketWriter-" + threadId++); + + ServerConfig setting = TPServer.me().getConfig(); + ByteBuffer writeBuffer = Utils.allocateBuffer(setting.maxWriteBufferSize, setting.writeBufferType); + + while (isActive) { + try { + Session session = sessionTicketsQueue.take(); + processSessionQueue(writeBuffer, session); + } catch (InterruptedException e) { + logger.warn("SocketWriter thread interrupted: " + Thread.currentThread()); + isActive = false; + } catch (Throwable t) { + logger.warn("Problems in SocketWriter main loop, Thread: " + Thread.currentThread()); + logger.error(t); + } + } + + logger.info("SocketWriter threadpool shutting down."); + } + + private void processSessionQueue(ByteBuffer writeBuffer, Session session) { + if (session != null) { + SessionType type = session.getType(); + + if (type == SessionType.NORMAL) { + processRegularSession(writeBuffer, session); + }else if (type == SessionType.VOID) + return; + } + } + + private void processRegularSession(ByteBuffer writeBuffer, Session session) { + if (session.isFrozen()) { + return; + } + Packet packet = null; + try { + IPacketQueue sessionQ = session.getPacketQueue(); + + synchronized (sessionQ) { + if (!sessionQ.isEmpty()) { + packet = sessionQ.peek(); + + if (packet == null) { + return; + } + tcpSend(writeBuffer, sessionQ, session, packet); + } + } + + } catch (ClosedChannelException cce) { + logger.debug("Socket closed during write operation for session: " + session); + } catch (IOException localIOException) {} catch (Exception e) { + logger.warn("Error during write. Session: " + session); + logger.error(e); + } + } + + private void tcpSend(ByteBuffer writeBuffer, IPacketQueue sessionQ, Session session, Packet packet) throws Exception { + ISocketChannel channel = session.getConnection(); + if (channel == null) { + logger.debug("Skipping packet, found null socket for Session: " + session); + return; + } + writeBuffer.clear(); + + byte[] buffer = packet.isFragmented() ? packet.getFragmentBuffer() : (byte[]) packet.getData(); + if (writeBuffer.capacity() < buffer.length) { + writeBuffer = Utils.allocateBuffer(buffer.length, engine.getConfig().writeBufferType); + } + writeBuffer.put(buffer); + writeBuffer.flip(); + + long toWrite = writeBuffer.remaining(); + + long bytesWritten = channel.write(writeBuffer); + if(bytesWritten == 0)throw new IOException("Written Bytes excetion!"); + + writtenBytes += bytesWritten; + session.addWrittenBytes(bytesWritten); + if (bytesWritten < toWrite) { + byte[] bb = new byte[writeBuffer.remaining()]; + writeBuffer.get(bb); + packet.setFragmentBuffer(bb); + + SelectionKey sk = (SelectionKey) session.getSystemProperty(DefaultConstants.SESSION_SELECTION_KEY); + if ((sk != null) && (sk.isValid())) { + sk.interestOps(SelectionKey.OP_READ|SelectionKey.OP_WRITE); + } else { + logger.warn("Could not OP_WRITE for Session: " + session + ", written bytes: " + bytesWritten); + } + } else { + writtenPackets += 1L; + + sessionQ.take(); + if (!sessionQ.isEmpty()) { + sessionTicketsQueue.add(session); + } + } + } + + public void enqueuePacket(Packet packet) { + enqueueLocal(packet); + } + + private void enqueueLocal(Packet packet) { + Collection recipients = packet.getRecipients(); + int size = recipients.size(); + + if ((recipients != null) && (size > 0)) { + if (packet.getSender() != null) { + packet.getSender().setLastWriteTime(System.currentTimeMillis()); + } + if (size == 1) { + enqueueLocalPacket((Session) packet.getRecipients().iterator().next(), packet); + } else + for (Session session : recipients) { + enqueueLocalPacket(session, packet.clone()); + } + } + } + + private void enqueueLocalPacket(Session session, Packet packet) { + IPacketQueue sessionQ = session.getPacketQueue(); + + if (sessionQ != null) { + synchronized (sessionQ) { + try { + boolean wasEmpty = sessionQ.isEmpty(); + + sessionQ.put(packet); + + if ((wasEmpty)) { + sessionTicketsQueue.add(session); + } + + packet.setRecipients(null); + } catch (Exception error) { + dropOneMessage(session); + } + } + } + } + + /** + * 丢包处理 + * @param session + */ + private void dropOneMessage(Session session) { + session.addDroppedMessages(1); + droppedPacketsCount += 1L; + } + + public long getDroppedPacketsCount() { + return droppedPacketsCount; + } + + + public long getWrittenBytes() { + return writtenBytes; + } + + public long getWrittenPackets() { + return writtenPackets; + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/util/GhostUserHunter.java b/taurus-permanent/src/main/java/com/taurus/permanent/util/GhostUserHunter.java new file mode 100644 index 0000000..07cdf74 --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/util/GhostUserHunter.java @@ -0,0 +1,82 @@ +package com.taurus.permanent.util; + +import com.taurus.core.util.Logger; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.SessionManager; +import com.taurus.permanent.core.SystemController; +import com.taurus.permanent.data.Session; + +import java.util.ArrayList; +import java.util.List; + +/** + * GhostUserHunter + * + * + * + */ +public class GhostUserHunter { + private static final String EOL = System.getProperty("line.separator"); + private final TPServer taurus; + private SessionManager sm; + private SystemController controller; + private final Logger log; + private static final int TOT_CYCLES = 2; + private int cycleCounter = 0; + + public GhostUserHunter() { + taurus = TPServer.me(); + this.controller = TPServer.me().getController(); + log = Logger.getLogger(getClass()); + } + + public void hunt() { + if (sm == null) { + sm = taurus.getSessionManager(); + } + + if (++cycleCounter < TOT_CYCLES) { + return; + } + cycleCounter = 0; + + List ghosts = searchGhosts(); + if (ghosts.size() > 0) { + log.info(buildReport(ghosts)); + } + + for (Session ghost : ghosts) + controller.disconnect(ghost); + } + + private List searchGhosts() { + List allUsers = taurus.getSessionManager().getAllSessions(); + List ghosts = new ArrayList(); + + for (Session u : allUsers) { + Session sess = u; + + if ((!sm.containsSession(sess)) || (sess.isIdle()) || (sess.isMarkedForEviction())) { + ghosts.add(u); + } + } + return ghosts; + } + + private String buildReport(List ghosts) { + StringBuilder sb = new StringBuilder("GHOST REPORT"); + sb.append(EOL).append("Total ghosts: ").append(ghosts.size()).append(EOL); + + for (Session ghost : ghosts) { + Session ss = ghost; + + if (ss == null) { + sb.append(ghost.getId()).append(", ").append(" -> Null session").append(", SessionById: ").append(this.sm.getSessionById(ghost.getId())); + } else { + sb.append(ghost.getId()).append(", ").append(", Connected: ").append(ss.isConnected()).append(", Idle: ").append(ss.isIdle()).append(", Marked: ") + .append(ss.isMarkedForEviction()).append(", Frozen: ").append(ss.isFrozen()).append(", SessionById: ").append(this.sm.getSessionById(ghost.getId())); + } + } + return sb.toString(); + } +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/websocket/UndertowWebSocketChannel.java b/taurus-permanent/src/main/java/com/taurus/permanent/websocket/UndertowWebSocketChannel.java new file mode 100644 index 0000000..13e363a --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/websocket/UndertowWebSocketChannel.java @@ -0,0 +1,56 @@ +package com.taurus.permanent.websocket; + +import java.io.IOException; +import java.net.SocketAddress; +import java.nio.ByteBuffer; + +import com.taurus.permanent.data.ISocketChannel; + +import io.undertow.websockets.core.WebSocketChannel; +import io.undertow.websockets.core.WebSockets; + +public class UndertowWebSocketChannel implements ISocketChannel{ + + private WebSocketChannel channel; + + public UndertowWebSocketChannel (WebSocketChannel channel) { + this.channel = channel; + } + + @Override + public long write(ByteBuffer buffer) { + return 0; + } + + @Override + public void write(String message) { + WebSockets.sendText(message, channel, null); + } + + @Override + public SocketAddress getRemoteAddress() { + return channel.getPeerAddress(); + } + + @Override + public SocketAddress getLocalAddress() { + return channel.getLocalAddress(); + } + + @Override + public void close() throws IOException{ + channel.close(); + } + + @Override + public Object getChannel() { + return channel; + } + + @Override + public boolean checkConnection() { + if(channel!=null&&channel.isOpen())return true; + return false; + } + +} diff --git a/taurus-permanent/src/main/java/com/taurus/permanent/websocket/WebSocketService.java b/taurus-permanent/src/main/java/com/taurus/permanent/websocket/WebSocketService.java new file mode 100644 index 0000000..b932a4b --- /dev/null +++ b/taurus-permanent/src/main/java/com/taurus/permanent/websocket/WebSocketService.java @@ -0,0 +1,195 @@ +package com.taurus.permanent.websocket; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.core.util.Utils; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.core.BaseCoreService; +import com.taurus.permanent.core.BitSwarmEngine; +import com.taurus.permanent.core.ServerConfig; +import com.taurus.permanent.core.SessionManager; +import com.taurus.permanent.data.ISocketChannel; +import com.taurus.permanent.data.PackDataType; +import com.taurus.permanent.data.Packet; +import com.taurus.permanent.data.Session; +import com.taurus.permanent.data.SessionType; + +import io.undertow.Handlers; +import io.undertow.Undertow; +import io.undertow.websockets.WebSocketConnectionCallback; +import io.undertow.websockets.core.AbstractReceiveListener; +import io.undertow.websockets.core.BufferedBinaryMessage; +import io.undertow.websockets.core.BufferedTextMessage; +import io.undertow.websockets.core.CloseMessage; +import io.undertow.websockets.core.WebSocketChannel; +import io.undertow.websockets.core.WebSockets; +import io.undertow.websockets.spi.WebSocketHttpExchange; + +/** + * WebSocket service + * + * + */ +public class WebSocketService extends BaseCoreService{ + private Undertow server; + private final BitSwarmEngine engine; + private SessionManager sessionManager; + private Logger logger; + + public WebSocketService() { + engine = BitSwarmEngine.getInstance(); + sessionManager = engine.getSessionManager(); + logger = Logger.getLogger(WebSocketService.class); + } + + public void init(Object o) { + super.init(o); + WSConnectionListener listener = new WSConnectionListener(this); + ServerConfig config = TPServer.me().getConfig(); + server = Undertow.builder().addHttpListener(config.webSocketConfig.port, config.webSocketConfig.address) + .setHandler(Handlers.path().addPrefixPath("/websocket", Handlers.websocket(listener))) + .build(); + server.start(); + logger.info("Websocket listen --> "+config.webSocketConfig.address+":"+config.webSocketConfig.port); + logger.info("Websocket service start!"); + } + + public void destroy(Object o) { + super.destroy(o); + server.stop(); + server = null; + logger.info("Websocket service shutdown!"); + } + + private void openAction(WebSocketChannel channel) { + Session session = sessionManager.createSession(new UndertowWebSocketChannel(channel), SessionType.WEBSOCKET); + sessionManager.addSession(session); + } + + private void readTextAction(WebSocketChannel channel,String data) { + Session session = sessionManager.getSessionByConnection(channel); + Packet newPacket = new Packet(); + newPacket.setDataType(PackDataType.TEXT); + newPacket.setSender(session); + ITObject requestObject = TObject.newFromJsonData(data); + newPacket.setData(requestObject); + session.setLastReadTime(System.currentTimeMillis()); + engine.getProtocolHandler().onPacketRead(newPacket); + } + + private void readBinaryAction(WebSocketChannel channel,ByteBuffer data) { + Session session = sessionManager.getSessionByConnection(channel); + Packet newPacket = new Packet(); + newPacket.setDataType(PackDataType.BINARY); + boolean compressed = data.get() >0; + byte[] bytes = new byte[data.remaining()]; + data.get(bytes); + if(compressed) { + try { + bytes = Utils.uncompress(bytes); + } catch (IOException e) { + logger.error(e); + return; + } + } + newPacket.setSender(session); + ITObject requestObject = TObject.newFromBinaryData(bytes); + newPacket.setData(requestObject); + session.setLastReadTime(System.currentTimeMillis()); + engine.getProtocolHandler().onPacketRead(newPacket); + } + + + /** + * send packet + */ + public void onDataWrite(Packet packet){ + if (packet.getRecipients().size() > 0) { + packet.setDataType(PackDataType.BINARY); + engine.getProtocolHandler().onPacketWrite(packet); + int protocolCompressionThreshold = TPServer.me().getConfig().protocolCompression; + byte[] binData = ((TObject)packet.getData()).toBinary(); + boolean compression = binData.length > protocolCompressionThreshold; + if(compression) { + try { + binData = Utils.compress(binData); + } catch (IOException e) { + logger.error(e); + return; + } + } + ByteBuffer writeBuffer = ByteBuffer.allocate(1 + binData.length); + writeBuffer.put(compression?(byte)1:(byte)0); + writeBuffer.put(binData); + writeBuffer.flip(); + for (final Session session : packet.getRecipients()) { + session.setLastWriteTime(System.currentTimeMillis()); + final ISocketChannel channel = session.getConnection(); + WebSockets.sendBinary(writeBuffer, (WebSocketChannel)channel.getChannel(), null); + } + } + } + + private void closeAction(WebSocketChannel channel) { + try { + sessionManager.onSocketDisconnected(channel); + } catch (IOException e) { + throw new RuntimeException("WebSocket Disconnected exception!",e); + } + } + + private static final class WSConnectionListener implements WebSocketConnectionCallback{ + private WSListener listener; + private WebSocketService wsService; + + public WSConnectionListener(WebSocketService wsService) { + this.wsService = wsService; + this.listener = new WSListener(wsService); + } + + @Override + public void onConnect(WebSocketHttpExchange exchange, WebSocketChannel channel) { + channel.getReceiveSetter().set(this.listener); + channel.resumeReceives(); + wsService.openAction(channel); + } + + } + + private static final class WSListener extends AbstractReceiveListener{ + private WebSocketService wsService; + + public WSListener(WebSocketService wsService) { + this.wsService = wsService; + } + + @Override + protected void onFullTextMessage(WebSocketChannel channel, BufferedTextMessage message) { + wsService.readTextAction(channel, message.getData()); + } + + + protected void onCloseMessage(CloseMessage cm, WebSocketChannel channel) { + wsService.closeAction(channel); + } + + protected void onFullPingMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { + super.onFullBinaryMessage(channel, message); + } + + protected void onFullBinaryMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { + ByteBuffer[] bufferList= message.getData().getResource(); + for (ByteBuffer tem : bufferList) { + wsService.readBinaryAction(channel, tem); + } + message.getData().free(); + } + + } + + +} diff --git a/taurus-permanent/src/test/java/com/taurus/T1Controller.java b/taurus-permanent/src/test/java/com/taurus/T1Controller.java new file mode 100644 index 0000000..1e9cba6 --- /dev/null +++ b/taurus-permanent/src/test/java/com/taurus/T1Controller.java @@ -0,0 +1,16 @@ +package com.taurus; + +import com.taurus.core.entity.TObject; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.routes.IController; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Session; + +public class T1Controller implements IController{ + + @ActionKey("test") + public void test(Session sender,TObject params,int gid) { + System.out.println("t1 test"); + TPServer.me().getController().sendResponse(gid, 0, params, sender); + } +} diff --git a/taurus-permanent/src/test/java/com/taurus/T2Controller.java b/taurus-permanent/src/test/java/com/taurus/T2Controller.java new file mode 100644 index 0000000..82b8e99 --- /dev/null +++ b/taurus-permanent/src/test/java/com/taurus/T2Controller.java @@ -0,0 +1,22 @@ +package com.taurus; + +import com.taurus.core.entity.TObject; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.routes.IController; +import com.taurus.permanent.TPServer; +import com.taurus.permanent.data.Session; + +public class T2Controller implements IController{ + + @ActionKey("test") + public void test(Session sender,TObject params,int gid) { + System.out.println("t1 test"); + TPServer.me().getController().sendResponse(gid, 0, params, sender); + } + + @ActionKey("test1") + public void test1(Session sender,TObject params,int gid) { + System.out.println("t2 test"); + TPServer.me().getController().sendResponse(gid, 1, params, sender); + } +} diff --git a/taurus-permanent/src/test/java/com/taurus/TestExtension.java b/taurus-permanent/src/test/java/com/taurus/TestExtension.java new file mode 100644 index 0000000..7057140 --- /dev/null +++ b/taurus-permanent/src/test/java/com/taurus/TestExtension.java @@ -0,0 +1,44 @@ +package com.taurus; + +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; + +/** + * + * @date 2016年12月21日 下午12:42:33 + * @version V2.9 + */ +public class TestExtension extends Extension{ + + public TestExtension() { + super(); +// login_cmd_map.put("req_test", true); + } + + @Override + public void configRoute(Routes me) { + me.add("t1", new T1Controller()); + me.add("t2", new T2Controller()); + } + +// @Override +// public void handleEvent(Event event) { +// if( event.getName() == TPEvents.EVENT_SESSION_DISCONNECT){ +// Session session = (Session) event.getParameter(TPEvents.PARAM_SESSION); +// logger.info("session:" + session.isIdle()); +// } +// +// } +// +// @Override +// protected void handlerRequest(Session sender, String cmdName, ITObject params, int gid) { +// // TODO Auto-generated method stub +// params.putInt("ttt", 1); +// sendResponse(gid, 0, params, sender); +// +// //api.disconnect(sender); +// } + + + +} diff --git a/taurus-server/pom.xml b/taurus-server/pom.xml new file mode 100644 index 0000000..50f6dca --- /dev/null +++ b/taurus-server/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + com.taurus + taurus-server + pom + 1.0.1 + taurus-server + + + UTF-8 + 1.8 + 1.8 + + + + taurus-permanent + taurus-web + taurus-core + + + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-permanent + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + + mysql + mysql-connector-java + 8.0.16 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + junit + junit + 3.8.1 + test + + + + + + + + jdom + jdom + + + + + log4j + log4j + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + + 1.8 + 1.8 + UTF-8 + + + + + + + + \ No newline at end of file diff --git a/taurus-server/taurus-core/config/log4j.properties b/taurus-server/taurus-core/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/taurus-server/taurus-core/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/taurus-server/taurus-core/config/taurus-core.xml b/taurus-server/taurus-core/config/taurus-core.xml new file mode 100644 index 0000000..e92604b --- /dev/null +++ b/taurus-server/taurus-core/config/taurus-core.xml @@ -0,0 +1,93 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.134.123.86:8060/test + root + cssq@2020 + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + \ No newline at end of file diff --git a/taurus-server/taurus-core/pom.xml b/taurus-server/taurus-core/pom.xml new file mode 100644 index 0000000..570dfed --- /dev/null +++ b/taurus-server/taurus-core/pom.xml @@ -0,0 +1,117 @@ + + + 4.0.0 + + com.taurus + taurus-server + 1.0.1 + + jar + taurus-core + 1.0.1 + + + + + redis.clients + jedis + + + + + com.zaxxer + HikariCP + + + + + jdom + jdom + + + + + log4j + log4j + + + + + mysql + mysql-connector-java + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + **/*.properties + + + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + true + + + + compile + + jar + + + + + + + + + releases + Nexus Release Repository + http://192.168.1.236:8081/nexus/content/repositories/releases/ + + + snapshots + Nexus Snapshot Repository + http://192.168.1.236:8081/nexus/content/repositories/snapshots/ + + + + diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITArray.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITArray.java new file mode 100644 index 0000000..4426747 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITArray.java @@ -0,0 +1,83 @@ +package com.taurus.core.entity; + +import java.util.Iterator; + +/** + * object array interface + * + * + */ +public interface ITArray { + + public Iterator iterator(); + + public TDataWrapper get(int index); + + public void del(int index); + + public int size(); + + public void clear(); + + public byte[] toBinary(); + + public String toJson(); + + public void addNull(); + + public void addBool(boolean value); + + public void addByte(byte value); + + public void addShort(short value); + + public void addInt(int value); + + public void addLong(long value); + + public void addFloat(float value); + + public void addDouble(double value); + + public void addString(String value); + + public void addUtfString(String value); + + public void addByteArray(byte[] data); + + public void addTArray(ITArray array); + + public void addTObject(ITObject object); + + public void add(TDataWrapper wrapper); + + public boolean isNull(int index); + + public Boolean getBool(int index); + + public Byte getByte(int index); + + public Integer getUByte(int index); + + public Short getShort(int index); + + public Integer getInt(int index); + + public Long getLong(int index); + + public Float getFloat(int index); + + public Double getDouble(int index); + + public String getString(int index); + + public String getUtfString(int index); + + public byte[] getByteArray(int index); + + public ITArray getTArray(int index); + + public ITObject getTObject(int index); + + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITObject.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITObject.java new file mode 100644 index 0000000..d80bf4c --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/ITObject.java @@ -0,0 +1,87 @@ +package com.taurus.core.entity; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * object map interface + * + * + */ +public interface ITObject { + public boolean isNull(String key); + + public boolean containsKey(String key); + + public boolean remove(String key); + + public Set getKeys(); + + public int size(); + + public Iterator> iterator(); + + public byte[] toBinary(); + + public String toJson(); + + public TDataWrapper get(String key); + + public Boolean getBoolean(String key); + + public Byte getByte(String key); + + public Integer getUByte(String key); + + public Short getShort(String key); + + public Integer getInt(String key); + + public Long getLong(String key); + + public Float getFloat(String key); + + public Double getDouble(String key); + + public String getString(String key); + + public String getUtfString(String key); + + public byte[] getByteArray(String key); + + public ITArray getTArray(String key); + + public ITObject getTObject(String key); + + public void putNull(String key); + + public void putBoolean(String key, boolean value); + + public void putByte(String key, byte value); + + public void putShort(String key, short value); + + public void putInt(String key, int value); + + public void putLong(String key, long value); + + public void putFloat(String key, float value); + + public void putDouble(String key, double value); + + public void putString(String key, String value); + + public void putUtfString(String key, String value); + + public void putByteArray(String key, byte[] data); + + public void putTArray(String key, ITArray array); + + public void putTObject(String key, ITObject object); + + public void put(String key, TDataWrapper wrapper); + + public void del(String key); + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArray.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArray.java new file mode 100644 index 0000000..f0125c2 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArray.java @@ -0,0 +1,226 @@ +package com.taurus.core.entity; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * object array entity + * + * + */ +public class TArray implements ITArray { + private List dataHolder; + private boolean isChange = false; + + public TArray() { + dataHolder = new ArrayList(); + } + + public static ITArray newFromBinaryData(byte[] bytes) { + return TDataSerializer.me().binary2array(bytes); + } + + public static ITArray newFromJsonData(String jsonStr) { + return TDataSerializer.me().json2array(jsonStr); + } + + public static ITArray newFromResultSet(ResultSet rs) throws SQLException { + return TDataSerializer.me().resultSet2array(rs); + } + + public static TArray newInstance() { + return new TArray(); + } + + public byte[] toBinary() { + return TDataSerializer.me().array2binary(this); + } + + public String toJson() { + return TDataSerializer.me().array2json(flatten()); + } + + public boolean isNull(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + + if (wrapper == null) { + return false; + } + return wrapper.getTypeId() == TDataType.NULL; + } + + public TDataWrapper get(int index) { + return (TDataWrapper) this.dataHolder.get(index); + } + + public Boolean getBool(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Boolean) wrapper.getObject() : null; + } + + public Byte getByte(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Byte) wrapper.getObject() : null; + } + + public Integer getUByte(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? Integer.valueOf(TDataSerializer.me().getUByte(((Byte) wrapper.getObject()).byteValue())) : null; + } + + public Short getShort(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Short) wrapper.getObject() : null; + } + + public Integer getInt(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Integer) wrapper.getObject() : null; + } + + public Long getLong(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Long) wrapper.getObject() : null; + } + + public Float getFloat(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Float) wrapper.getObject() : null; + } + + public Double getDouble(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (Double) wrapper.getObject() : null; + } + + public String getString(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (String) wrapper.getObject() : null; + } + + public byte[] getByteArray(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (byte[]) wrapper.getObject() : null; + } + + public ITArray getTArray(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (ITArray) wrapper.getObject() : null; + } + + public ITObject getTObject(int index) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(index); + return wrapper != null ? (ITObject) wrapper.getObject() : null; + } + + public void addBool(boolean value) { + addObject(Boolean.valueOf(value), TDataType.BOOL); + } + + public void addByte(byte value) { + addObject(Byte.valueOf(value), TDataType.BYTE); + } + + public void addByteArray(byte[] value) { + addObject(value, TDataType.BYTE_ARRAY); + } + + public void addDouble(double value) { + addObject(Double.valueOf(value), TDataType.DOUBLE); + } + + public void addFloat(float value) { + addObject(Float.valueOf(value), TDataType.FLOAT); + } + + public void addInt(int value) { + addObject(Integer.valueOf(value), TDataType.INT); + } + + public void addLong(long value) { + addObject(Long.valueOf(value), TDataType.LONG); + } + + public void addNull() { + addObject(null, TDataType.NULL); + } + + public void addTArray(ITArray value) { + addObject(value, TDataType.TARRAY); + } + + public void addTObject(ITObject value) { + addObject(value, TDataType.TOBJECT); + } + + public void addShort(short value) { + addObject(Short.valueOf(value), TDataType.SHORT); + } + + public void addString(String value) { + addObject(value, TDataType.STRING); + } + + public void add(TDataWrapper wrappedObject) { + this.dataHolder.add(wrappedObject); + } + + public Object getAt(int index) { + Object item = null; + TDataWrapper wrapper = (TDataWrapper) dataHolder.get(index); + + if (wrapper != null) + item = wrapper.getObject(); + return item; + } + + public Iterator iterator() { + return this.dataHolder.iterator(); + } + + public void del(int index) { + this.dataHolder.remove(index); + } + + public int size() { + return this.dataHolder.size(); + } + + public void clear() { + this.dataHolder.clear(); + } + + public String toString() { + return dataHolder.toString(); + } + + private void addObject(Object value, TDataType typeId) { + dataHolder.add(new TDataWrapper(typeId, value)); + isChange = true; + } + + public boolean equals(Object obj) { + boolean isEquals = isChange; + isChange = false; + return isEquals; + } + + private List flatten() { + List list = new ArrayList(); + TDataSerializer.me().flattenArray(list, this); + return list; + } + + @Override + public void addUtfString(String value) { + this.addString(value); + } + + @Override + public String getUtfString(int index) { + return getString(index); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArrayLite.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArrayLite.java new file mode 100644 index 0000000..c34f723 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TArrayLite.java @@ -0,0 +1,28 @@ +package com.taurus.core.entity; + +/** + * TArrayLite + * + * + */ +public class TArrayLite extends TArray { + public static TArrayLite newInstance() { + return new TArrayLite(); + } + + public Byte getByte(int index) { + Integer i = super.getInt(index); + + return i != null ? Byte.valueOf(i.byteValue()) : null; + } + + public Short getShort(int index) { + Integer i = super.getInt(index); + return i != null ? Short.valueOf(i.shortValue()) : null; + } + + public Float getFloat(int index) { + Double d = super.getDouble(index); + return d != null ? Float.valueOf(d.floatValue()) : null; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataSerializer.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataSerializer.java new file mode 100644 index 0000000..30920e8 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataSerializer.java @@ -0,0 +1,645 @@ +package com.taurus.core.entity; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.sql.Blob; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.json.JSONUtils; + +/** + * TDataSerializer + * + * + */ +public class TDataSerializer { + private static TDataSerializer instance = new TDataSerializer(); + private static int BUFFER_CHUNK_SIZE = 512; + + private static Logger logger = Logger.getLogger(TDataSerializer.class); + + public static TDataSerializer me() { + return instance; + } + + private TDataSerializer() { + } + + public int getUByte(byte b) { + return 0xFF & b; + } + + public ITArray binary2array(byte[] data) { + if (data.length < 3) { + throw new IllegalStateException("Can't decode an Array. Size: " + data.length + " bytes"); + } + ByteBuffer buffer = ByteBuffer.allocate(data.length); + buffer.put(data); + buffer.flip(); + return decodeTArray(buffer); + } + + private ITArray decodeTArray(ByteBuffer buffer) { + ITArray array = TArray.newInstance(); + byte headerBuffer = buffer.get(); + if (headerBuffer != TDataType.TARRAY.getTypeID()) { + throw new IllegalStateException("Invalid DataType. Expected: " + TDataType.TARRAY.getTypeID() + ", found: " + headerBuffer); + } + short size = buffer.getShort(); + if (size < 0) { + throw new IllegalStateException("Can't decode Array. Size is negative = " + size); + } + + try { + for (int i = 0; i < size; i++) { + TDataWrapper decodedObject = decodeObject(buffer); + + if (decodedObject != null) + array.add(decodedObject); + else { + throw new IllegalStateException("Array item is null! index: " + i); + } + } + } catch (RuntimeException codecError) { + throw new IllegalArgumentException(codecError.getMessage()); + } + return array; + } + + public ITObject binary2object(byte[] data) { + if (data.length < 3) { + throw new IllegalStateException("Can't decode an Object. Size: " + data.length + " bytes"); + } + ByteBuffer buffer = ByteBuffer.allocate(data.length); + buffer.put(data); + buffer.flip(); + return decodeTObject(buffer); + } + + private ITObject decodeTObject(ByteBuffer buffer) { + ITObject tobj = TObject.newInstance(); + byte headerBuffer = buffer.get(); + if (headerBuffer != TDataType.TOBJECT.getTypeID()) { + throw new IllegalStateException("Invalid DataType. Expected: " + TDataType.TOBJECT.getTypeID() + ", found: " + headerBuffer); + } + short size = buffer.getShort(); + if (size < 0) { + throw new IllegalStateException("Can't decode Object. Size is negative = " + size); + } + + for (int i = 0; i < size; i++) { + short keySize = buffer.getShort(); + if ((keySize < 0) || (keySize > 255)) { + throw new IllegalStateException("Invalid Object key length. Found = " + keySize); + } + byte[] keyData = new byte[keySize]; + buffer.get(keyData, 0, keyData.length); + String key = new String(keyData); + TDataWrapper decodedObject = decodeObject(buffer); + if (decodedObject != null) + tobj.put(key, decodedObject); + else { + throw new IllegalStateException("Could not decode value for key: " + keyData); + } + } + return tobj; + } + + /** + * + * @param jsonStr + * @return + */ + @SuppressWarnings("unchecked") + public ITObject json2object(String jsonStr) { + if (jsonStr.length() < 2) { + throw new IllegalStateException("Can't decode Object. JSON String is too short. Len: " + jsonStr.length()); + } + + Object o = JSONUtils.parse(jsonStr); + return decodeTObject((HashMap) o); + } + + /** + * + * @param jsonStr + * @return + */ + @SuppressWarnings("unchecked") + public ITArray json2array(String jsonStr) { + if (jsonStr.length() < 2) { + throw new IllegalStateException("Can't decode Object. JSON String is too short. Len: " + jsonStr.length()); + } + Object jsa = JSONUtils.parse(jsonStr); + return decodeTArray((List) jsa); + } + + private ITArray decodeTArray(List jsa) { + ITArray array = TArrayLite.newInstance(); + + for (Object value : jsa) { + TDataWrapper decodedObject = decodeJsonObject(value); + if (decodedObject != null) + array.add(decodedObject); + else { + throw new IllegalStateException("(json2sfarray) Could not decode value for object: " + value); + } + } + return array; + } + + private ITObject decodeTObject(HashMap jso) { + + ITObject object = TObjectLite.newInstance(); + for (Entry entry : jso.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + TDataWrapper decodedObject = decodeJsonObject(value); + if (decodedObject != null) + object.put(key, decodedObject); + else { + throw new IllegalStateException("(json2tobj) Could not decode value for key: " + key); + } + } + return object; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private TDataWrapper decodeJsonObject(Object o) { + + if ((o instanceof Integer)) { + return new TDataWrapper(TDataType.INT, o); + } + if ((o instanceof Long)) { + return new TDataWrapper(TDataType.LONG, o); + } + if ((o instanceof Double)) { + return new TDataWrapper(TDataType.DOUBLE, o); + } + if ((o instanceof Boolean)) { + return new TDataWrapper(TDataType.BOOL, o); + } + if ((o instanceof String)) { + return new TDataWrapper(TDataType.STRING, o); + } + if ((o instanceof HashMap)) { + HashMap jso = (HashMap) o; + return new TDataWrapper(TDataType.TOBJECT, decodeTObject(jso)); + } + if ((o instanceof List)) { + return new TDataWrapper(TDataType.TARRAY, decodeTArray((List) o)); + } + + throw new IllegalArgumentException(String.format("Unknown DataType! %s", o == null ? "null" : o.getClass())); + } + + public TObject resultSet2object(ResultSet rset) throws SQLException { + ResultSetMetaData metaData = rset.getMetaData(); + TObject sfso = new TObject(); + + if (rset.isBeforeFirst()) { + rset.next(); + } + for (int col = 1; col <= metaData.getColumnCount(); col++) { + String colName = metaData.getColumnLabel(col); + int type = metaData.getColumnType(col); + + Object rawDataObj = rset.getObject(col); + if (rawDataObj == null) { + continue; + } + + if (type == Types.NULL) { + sfso.putNull(colName); + } else if (type == Types.BOOLEAN) { + sfso.putBoolean(colName, rset.getBoolean(col)); + } else if (type == Types.DATE) { + sfso.putLong(colName, rset.getDate(col).getTime()); + } else if ((type == Types.FLOAT) || (type == Types.DOUBLE) || (type == Types.DECIMAL) || (type == Types.REAL)) { + sfso.putDouble(colName, rset.getDouble(col)); + } else if ((type == Types.INTEGER) || (type == Types.TINYINT) || (type == Types.SMALLINT)) { + sfso.putInt(colName, rset.getInt(col)); + } else if ((type == Types.CHAR) || (type == Types.VARCHAR) || (type == Types.LONGVARCHAR)) { + sfso.putString(colName, rset.getString(col)); + } else if ((type == Types.NCHAR) || (type == Types.NVARCHAR) || (type == Types.LONGNVARCHAR)) { + sfso.putString(colName, rset.getNString(col)); + } else if (type == Types.TIMESTAMP) { + sfso.putLong(colName, rset.getTimestamp(col).getTime()); + } else if (type == Types.BIGINT) { + sfso.putLong(colName, rset.getLong(col)); + } else if (type == Types.LONGVARBINARY) { + byte[] binData = getBlobData(colName, rset.getBinaryStream(col)); + + if (binData != null) { + sfso.putByteArray(colName, binData); + } + } else if (type == Types.BLOB) { + Blob blob = rset.getBlob(col); + sfso.putByteArray(colName, blob.getBytes(0L, (int) blob.length())); + } else { + logger.info("Skipping Unsupported SQL TYPE: " + type + ", Column:" + colName); + } + } + + return sfso; + } + + private byte[] getBlobData(String colName, InputStream stream) { + BufferedInputStream bis = new BufferedInputStream(stream); + byte[] bytes = (byte[]) null; + try { + bytes = new byte[bis.available()]; + bis.read(bytes); + } catch (IOException ex) { + logger.warn("Object serialize error. Failed reading BLOB data for column: " + colName); + } finally { + try { + bis.close(); + } catch (IOException e) { + logger.error(e); + } + } + + return bytes; + } + + public TArray resultSet2array(ResultSet rset) throws SQLException { + TArray array = new TArray(); + + while (rset.next()) { + array.addTObject(resultSet2object(rset)); + } + + return array; + } + + public byte[] object2binary(ITObject object) { + ByteBuffer buffer = ByteBuffer.allocate(BUFFER_CHUNK_SIZE); + buffer.put((byte) TDataType.TOBJECT.getTypeID()); + buffer.putShort((short) object.size()); + return obj2bin(object, buffer); + } + + private byte[] obj2bin(ITObject object, ByteBuffer buffer) { + Set keys = object.getKeys(); + for (String key : keys) { + TDataWrapper wrapper = object.get(key); + buffer = encodeTObjectKey(buffer, key); + buffer = encodeObject(buffer, wrapper); + } + + int pos = buffer.position(); + byte[] result = new byte[pos]; + buffer.flip(); + buffer.get(result, 0, pos); + return result; + } + + public byte[] array2binary(ITArray array) { + ByteBuffer buffer = ByteBuffer.allocate(BUFFER_CHUNK_SIZE); + buffer.put((byte) TDataType.TARRAY.getTypeID()); + buffer.putShort((short) array.size()); + return arr2bin(array, buffer); + } + + private byte[] arr2bin(ITArray array, ByteBuffer buffer) { + Iterator iter = array.iterator(); + while (iter.hasNext()) { + TDataWrapper wrapper = (TDataWrapper) iter.next(); + buffer = encodeObject(buffer, wrapper); + } + + int pos = buffer.position(); + byte[] result = new byte[pos]; + buffer.flip(); + buffer.get(result, 0, pos); + return result; + } + + public String object2json(Map map) { + return JSONUtils.toJSONString(map); + } + + public String array2json(List array) { + return JSONUtils.toJSONString(array); + } + + public void flattenObject(Map map, ITObject obj) { + for (Iterator> it = obj.iterator(); it.hasNext();) { + Entry entry = it.next(); + String key = (String) entry.getKey(); + TDataWrapper value = (TDataWrapper) entry.getValue(); + if (value.getTypeId() == TDataType.TOBJECT) { + Map newMap = new HashMap(); + map.put(key, newMap); + flattenObject(newMap, (ITObject) value.getObject()); + } else if (value.getTypeId() == TDataType.TARRAY) { + List newList = new ArrayList(); + map.put(key, newList); + flattenArray(newList, (ITArray) value.getObject()); + } else { + map.put(key, value.getObject()); + } + } + } + + public void flattenArray(List array, ITArray tarray) { + for (Iterator it = tarray.iterator(); it.hasNext();) { + TDataWrapper value = (TDataWrapper) it.next(); + if (value.getTypeId() == TDataType.TOBJECT) { + Map newMap = new HashMap(); + array.add(newMap); + flattenObject(newMap, (TObject) value.getObject()); + } else if (value.getTypeId() == TDataType.TARRAY) { + List newList = new ArrayList(); + array.add(newList); + flattenArray(newList, (ITArray) value.getObject()); + } else { + array.add(value.getObject()); + } + } + } + + private TDataWrapper decodeObject(ByteBuffer buffer) throws RuntimeException { + TDataWrapper decodedObject = null; + byte headerByte = buffer.get(); + + if (headerByte == TDataType.NULL.getTypeID()) { + decodedObject = binDecode_NULL(buffer); + } else if (headerByte == TDataType.BOOL.getTypeID()) { + decodedObject = binDecode_BOOL(buffer); + } else if (headerByte == TDataType.BYTE.getTypeID()) { + decodedObject = binDecode_BYTE(buffer); + } else if (headerByte == TDataType.BYTE_ARRAY.getTypeID()) { + decodedObject = binDecode_BYTE_ARRAY(buffer); + } else if (headerByte == TDataType.SHORT.getTypeID()) { + decodedObject = binDecode_SHORT(buffer); + } else if (headerByte == TDataType.INT.getTypeID()) { + decodedObject = binDecode_INT(buffer); + } else if (headerByte == TDataType.LONG.getTypeID()) { + decodedObject = binDecode_LONG(buffer); + } else if (headerByte == TDataType.FLOAT.getTypeID()) { + decodedObject = binDecode_FLOAT(buffer); + } else if (headerByte == TDataType.DOUBLE.getTypeID()) { + decodedObject = binDecode_DOUBLE(buffer); + } else if (headerByte == TDataType.STRING.getTypeID()) { + decodedObject = binDecode_STRING(buffer); + } else if (headerByte == TDataType.TARRAY.getTypeID()) { + buffer.position(buffer.position() - 1); + decodedObject = new TDataWrapper(TDataType.TARRAY, decodeTArray(buffer)); + } else if (headerByte == TDataType.TOBJECT.getTypeID()) { + buffer.position(buffer.position() - 1); + ITObject tobj = decodeTObject(buffer); + TDataType type = TDataType.TOBJECT; + Object finalTObj = tobj; + decodedObject = new TDataWrapper(type, finalTObj); + } else { + throw new RuntimeException("Unknow DataType ID: " + headerByte); + } + return decodedObject; + } + + private ByteBuffer encodeObject(ByteBuffer buffer, TDataWrapper wrapper) { + TDataType typeId = wrapper.getTypeId(); + Object object = wrapper.getObject(); + + switch (typeId) { + case NULL: + buffer = binEncode_NULL(buffer); + break; + case BOOL: + buffer = binEncode_BOOL(buffer, (Boolean) object); + break; + case BYTE: + buffer = binEncode_BYTE(buffer, (Byte) object); + break; + case SHORT: + buffer = binEncode_SHORT(buffer, (Short) object); + break; + case INT: + buffer = binEncode_INT(buffer, (Integer) object); + break; + case LONG: + buffer = binEncode_LONG(buffer, (Long) object); + break; + case FLOAT: + buffer = binEncode_FLOAT(buffer, (Float) object); + break; + case DOUBLE: + buffer = binEncode_DOUBLE(buffer, (Double) object); + break; + case STRING: + buffer = binEncode_STRING(buffer, (String) object); + break; + case BYTE_ARRAY: + buffer = binEncode_BYTE_ARRAY(buffer, (byte[]) object); + break; + case TARRAY: + buffer = addData(buffer, array2binary((TArray) object)); + break; + case TOBJECT: + buffer = addData(buffer, object2binary((TObject) object)); + break; + default: + throw new IllegalArgumentException("Unrecognized type in TObject serialization: " + typeId); + } + + return buffer; + } + + private TDataWrapper binDecode_NULL(ByteBuffer buffer) { + return new TDataWrapper(TDataType.NULL, null); + } + + private TDataWrapper binDecode_BOOL(ByteBuffer buffer) throws RuntimeException { + byte boolByte = buffer.get(); + Boolean bool = null; + if (boolByte == 0) + bool = new Boolean(false); + else if (boolByte == 1) + bool = new Boolean(true); + else { + throw new RuntimeException("Error decoding Bool type. Illegal value: " + bool); + } + return new TDataWrapper(TDataType.BOOL, bool); + } + + private TDataWrapper binDecode_BYTE(ByteBuffer buffer) { + byte boolByte = buffer.get(); + return new TDataWrapper(TDataType.BYTE, Byte.valueOf(boolByte)); + } + + private TDataWrapper binDecode_SHORT(ByteBuffer buffer) { + short shortValue = buffer.getShort(); + return new TDataWrapper(TDataType.SHORT, Short.valueOf(shortValue)); + } + + private TDataWrapper binDecode_INT(ByteBuffer buffer) { + int intValue = buffer.getInt(); + return new TDataWrapper(TDataType.INT, Integer.valueOf(intValue)); + } + + private TDataWrapper binDecode_LONG(ByteBuffer buffer) { + long longValue = buffer.getLong(); + return new TDataWrapper(TDataType.LONG, Long.valueOf(longValue)); + } + + private TDataWrapper binDecode_FLOAT(ByteBuffer buffer) { + float floatValue = buffer.getFloat(); + return new TDataWrapper(TDataType.FLOAT, Float.valueOf(floatValue)); + } + + private TDataWrapper binDecode_DOUBLE(ByteBuffer buffer) { + double doubleValue = buffer.getDouble(); + return new TDataWrapper(TDataType.DOUBLE, Double.valueOf(doubleValue)); + } + + private TDataWrapper binDecode_STRING(ByteBuffer buffer) throws RuntimeException { + int strLen = buffer.getShort(); + if (strLen < 0) { + throw new RuntimeException("Error decoding String. Negative size: " + strLen); + } + if(strLen == 0) { + return new TDataWrapper(TDataType.STRING, StringUtil.Empty); + } + byte[] strData = new byte[strLen]; + buffer.get(strData, 0, strLen); + String decodedString = StringUtil.Empty; + try { + decodedString = StringUtil.getString(strData); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + return new TDataWrapper(TDataType.STRING, decodedString); + } + + private TDataWrapper binDecode_BYTE_ARRAY(ByteBuffer buffer) throws RuntimeException { + int arraySize = buffer.getInt(); + if (arraySize < 0) { + throw new RuntimeException("Error decoding typed array size. Negative size: " + arraySize); + } + + byte[] byteData = new byte[arraySize]; + buffer.get(byteData, 0, arraySize); + return new TDataWrapper(TDataType.BYTE_ARRAY, byteData); + } + + private ByteBuffer binEncode_NULL(ByteBuffer buffer) { + return addData(buffer, new byte[1]); + } + + private ByteBuffer binEncode_BOOL(ByteBuffer buffer, Boolean value) { + byte[] data = new byte[2]; + data[0] = (byte) TDataType.BOOL.getTypeID(); + data[1] = (byte) (value.booleanValue() ? 1 : 0); + return addData(buffer, data); + } + + private ByteBuffer binEncode_BYTE(ByteBuffer buffer, Byte value) { + byte[] data = new byte[2]; + data[0] = (byte) TDataType.BYTE.getTypeID(); + data[1] = value.byteValue(); + return addData(buffer, data); + } + + private ByteBuffer binEncode_SHORT(ByteBuffer buffer, Short value) { + ByteBuffer buf = ByteBuffer.allocate(3); + buf.put((byte) TDataType.SHORT.getTypeID()); + buf.putShort(value.shortValue()); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_INT(ByteBuffer buffer, Integer value) { + ByteBuffer buf = ByteBuffer.allocate(5); + buf.put((byte) TDataType.INT.getTypeID()); + buf.putInt(value.intValue()); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_LONG(ByteBuffer buffer, Long value) { + ByteBuffer buf = ByteBuffer.allocate(9); + buf.put((byte) TDataType.LONG.getTypeID()); + buf.putLong(value.longValue()); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_FLOAT(ByteBuffer buffer, Float value) { + ByteBuffer buf = ByteBuffer.allocate(5); + buf.put((byte) TDataType.FLOAT.getTypeID()); + buf.putFloat(value.floatValue()); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_DOUBLE(ByteBuffer buffer, Double value) { + ByteBuffer buf = ByteBuffer.allocate(9); + buf.put((byte) TDataType.DOUBLE.getTypeID()); + buf.putDouble(value.doubleValue()); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_STRING(ByteBuffer buffer, String value) { + if (StringUtil.isEmpty(value)) { + ByteBuffer buf = ByteBuffer.allocate(3); + buf.put((byte) TDataType.STRING.getTypeID()); + buf.putShort((short)0); + return addData(buffer, buf.array()); + } + byte[] stringBytes = null; + try { + stringBytes = StringUtil.getBytes(value); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + ByteBuffer buf = ByteBuffer.allocate(3 + stringBytes.length); + buf.put((byte) TDataType.STRING.getTypeID()); + buf.putShort((short)stringBytes.length); + buf.put(stringBytes); + return addData(buffer, buf.array()); + } + + private ByteBuffer binEncode_BYTE_ARRAY(ByteBuffer buffer, byte[] value) { + ByteBuffer buf = ByteBuffer.allocate(5 + value.length); + buf.put((byte) TDataType.BYTE_ARRAY.getTypeID()); + buf.putInt(value.length); + buf.put(value); + return addData(buffer, buf.array()); + } + + private ByteBuffer encodeTObjectKey(ByteBuffer buffer, String value) { + ByteBuffer buf = ByteBuffer.allocate(2 + value.length()); + buf.putShort((short) value.length()); + buf.put(value.getBytes()); + return addData(buffer, buf.array()); + } + + private ByteBuffer addData(ByteBuffer buffer, byte[] newData) { + if (buffer.remaining() < newData.length) { + int newSize = BUFFER_CHUNK_SIZE; + if (newSize < newData.length) { + newSize = newData.length; + } + ByteBuffer newBuffer = ByteBuffer.allocate(buffer.capacity() + newSize); + buffer.flip(); + newBuffer.put(buffer); + buffer = newBuffer; + } + buffer.put(newData); + return buffer; + } + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataType.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataType.java new file mode 100644 index 0000000..b21cfec --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataType.java @@ -0,0 +1,41 @@ +package com.taurus.core.entity; + +/** + * TDataType + * + * + */ +public enum TDataType{ + NULL(0), + BOOL(1), + BYTE(2), + SHORT(3), + INT(4), + LONG(5), + FLOAT(6), + DOUBLE(7), + STRING(8), + BYTE_ARRAY(9), + TARRAY(10), + TOBJECT(11); + + private int typeID; + + private TDataType(int typeID) { + this.typeID = typeID; + } + + public static TDataType fromTypeId(int typeId) { + for (TDataType item : values()) { + if (item.getTypeID() == typeId) { + return item; + } + } + + throw new IllegalArgumentException("Unknown typeId for MPDataType"); + } + + public int getTypeID() { + return this.typeID; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataWrapper.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataWrapper.java new file mode 100644 index 0000000..d2f25a8 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TDataWrapper.java @@ -0,0 +1,28 @@ +package com.taurus.core.entity; + +/** + * TDataWrapper + * + * + */ +public class TDataWrapper { + private TDataType typeId; + private Object object; + + public TDataWrapper(TDataType typeId, Object object) { + this.typeId = typeId; + this.object = object; + } + + public TDataType getTypeId() { + return typeId; + } + + public Object getObject() { + return object; + } + + public String toString() { + return object.toString(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObject.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObject.java new file mode 100644 index 0000000..8017226 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObject.java @@ -0,0 +1,291 @@ +package com.taurus.core.entity; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import com.taurus.core.util.StringUtil; + +/** + * object map entity + * + * + */ +public class TObject implements ITObject { + private Map dataHolder; + private boolean isChange; + + public static ITObject newFromBinaryData(byte[] bytes) { + return TDataSerializer.me().binary2object(bytes); + } + + public static ITObject newFromJsonData(String jsonStr) { + return TDataSerializer.me().json2object(jsonStr); + } + + public static ITObject newFromResultSet(ResultSet rs) throws SQLException{ + return TDataSerializer.me().resultSet2object(rs); + } + + public static TObject newInstance() { + return new TObject(); + } + + public TObject() { + dataHolder = new ConcurrentHashMap(); + } + + public Iterator> iterator() { + return this.dataHolder.entrySet().iterator(); + } + + public boolean containsKey(String key) { + return this.dataHolder.containsKey(key); + } + + public boolean remove(String key) { + return this.dataHolder.remove(key) != null; + } + + public int size() { + return this.dataHolder.size(); + } + + public byte[] toBinary() { + return TDataSerializer.me().object2binary(this); + } + + public String toJson() { + return TDataSerializer.me().object2json(flatten()); + } + + public boolean isNull(String key) { + TDataWrapper wrapper = (TDataWrapper) this.dataHolder.get(key); + + if (wrapper == null) { + return false; + } + return wrapper.getTypeId() == TDataType.NULL; + } + + public TDataWrapper get(String key) { + return (TDataWrapper) this.dataHolder.get(key); + } + + public Boolean getBoolean(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return (Boolean) o.getObject(); + } + + public Byte getByte(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return (Byte) o.getObject(); + } + + public byte[] getByteArray(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (byte[]) o.getObject(); + } + + public Double getDouble(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (Double) o.getObject(); + } + + public Float getFloat(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (Float) o.getObject(); + } + + public Integer getInt(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (Integer) o.getObject(); + } + + public Set getKeys() { + return dataHolder.keySet(); + } + + public Long getLong(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return (Long) o.getObject(); + } + + public ITArray getTArray(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return (ITArray) o.getObject(); + } + + public ITObject getTObject(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (ITObject) o.getObject(); + } + + public Short getShort(String key) { + TDataWrapper o = (TDataWrapper) dataHolder.get(key); + + if (o == null) { + return null; + } + return (Short) o.getObject(); + } + + public Integer getUByte(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return Integer.valueOf(TDataSerializer.me().getUByte(((Byte) o.getObject()).byteValue())); + } + + public String getString(String key) { + TDataWrapper o = (TDataWrapper) this.dataHolder.get(key); + + if (o == null) { + return null; + } + return (String) o.getObject(); + } + + public void putBoolean(String key, boolean value) { + putObj(key, Boolean.valueOf(value), TDataType.BOOL); + } + + public void putByte(String key, byte value) { + putObj(key, Byte.valueOf(value), TDataType.BYTE); + } + + public void putByteArray(String key, byte[] value) { + putObj(key, value, TDataType.BYTE_ARRAY); + } + + public void putDouble(String key, double value) { + putObj(key, Double.valueOf(value), TDataType.DOUBLE); + } + + public void putFloat(String key, float value) { + putObj(key, Float.valueOf(value), TDataType.FLOAT); + } + + public void putInt(String key, int value) { + putObj(key, Integer.valueOf(value), TDataType.INT); + } + + public void putLong(String key, long value) { + putObj(key, Long.valueOf(value), TDataType.LONG); + } + + public void putNull(String key) { + this.dataHolder.put(key, new TDataWrapper(TDataType.NULL, null)); + } + + public void putTArray(String key, ITArray value) { + putObj(key, value, TDataType.TARRAY); + } + + public void putTObject(String key, ITObject value) { + putObj(key, value, TDataType.TOBJECT); + } + + public void putShort(String key, short value) { + putObj(key, Short.valueOf(value), TDataType.SHORT); + } + + public void putString(String key, String value) { + if(value==null)value = StringUtil.Empty; + putObj(key, value, TDataType.STRING); + } + + public void put(String key, TDataWrapper wrappedObject) { + putObj(key, wrappedObject, null); + } + + public String toString() { + return dataHolder.toString(); + } + + private void putObj(String key, Object value, TDataType typeId) { + if (key == null) { + throw new IllegalArgumentException("TObject requires a non-null key for a 'put' operation!"); + } + if (key.length() > 255) { + throw new IllegalArgumentException("TObject keys must be less than 255 characters!"); + } + if (value == null) { + throw new IllegalArgumentException("TObject requires a non-null value! If you need to add a null use the putNull() method."); + } + if ((value instanceof TDataWrapper)) + dataHolder.put(key, (TDataWrapper) value); + else + dataHolder.put(key, new TDataWrapper(typeId, value)); + isChange = true; + } + + public boolean equals(Object obj) { + boolean isEquals = isChange; + isChange = false; + return isEquals; + } + + private Map flatten() { + Map map = new HashMap(); + TDataSerializer.me().flattenObject(map, this); + return map; + } + + @Override + public void del(String key) { + dataHolder.remove(key); + } + + @Override + public String getUtfString(String key) { + return this.getString(key); + } + + @Override + public void putUtfString(String key, String value) { + this.putString(key, value); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObjectLite.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObjectLite.java new file mode 100644 index 0000000..2ad448c --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/entity/TObjectLite.java @@ -0,0 +1,33 @@ +package com.taurus.core.entity; + +/** + * TObjectLite + * + * + */ +public final class TObjectLite extends TObject { + public static TObject newInstance() { + return new TObjectLite(); + } + + @Override + public Byte getByte(String key) { + Integer i = super.getInt(key); + + return i != null ? Byte.valueOf(i.byteValue()) : null; + } + + @Override + public Short getShort(String key) { + Integer i = super.getInt(key); + + return i != null ? Short.valueOf(i.shortValue()) : null; + } + + @Override + public Float getFloat(String key) { + Double d = super.getDouble(key); + + return d != null ? Float.valueOf(d.floatValue()) : null; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/events/Event.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/Event.java new file mode 100644 index 0000000..76a91c6 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/Event.java @@ -0,0 +1,60 @@ +package com.taurus.core.events; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Event. + * + */ +public class Event { + + protected Object target; + protected String name; + protected Map paramMap; + + public Event(String name) { + this.name = name; + } + + public Event(String name, Object source) { + this.target = source; + this.name = name; + } + + public Object getTarget() { + return this.target; + } + + public String getName() { + return this.name; + } + + public void setTarget(Object target) { + this.target = target; + } + + public void setName(String name) { + this.name = name; + } + + public Object getParameter(String key) { + Object tem = null; + + if (paramMap != null) { + tem = paramMap.get(key); + } + return tem; + } + + public void setParameter(String key, Object value) { + if (paramMap == null) { + paramMap = new ConcurrentHashMap(); + } + paramMap.put(key, value); + } + + public String toString() { + return "Event { Name:" + name + ", Source: " + target + ", Params: " + paramMap + " }"; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventDispatcher.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventDispatcher.java new file mode 100644 index 0000000..c4c98b3 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventDispatcher.java @@ -0,0 +1,93 @@ +package com.taurus.core.events; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.ThreadPoolExecutor; + +import com.taurus.core.util.Logger; + +/** + * EventDispatcher 事件派发器类,负责进行事件的发送和侦听。 +*/ +public class EventDispatcher implements IEventDispatcher { + + private final Map> listenersByEvent; + private ThreadPoolExecutor threadPool; + + public EventDispatcher(){ + listenersByEvent = new ConcurrentHashMap>(); + } + + public EventDispatcher(ThreadPoolExecutor threadPool){ + this(); + this.threadPool = threadPool; + } + + @Override + public synchronized void addEventListener(String eventName, IEventListener listener) { + Set listeners = listenersByEvent.get(eventName); + if (listeners == null) { + listeners = new CopyOnWriteArraySet(); + listenersByEvent.put(eventName, listeners); + } + + listeners.add(listener); + } + + @Override + public boolean hasEventListener(String eventName) { + boolean found = false; + Set listeners = listenersByEvent.get(eventName); + if ((listeners != null) && (listeners.size() > 0)) { + found = true; + } + return found; + } + + @Override + public synchronized void removeEventListener(String eventName, IEventListener listener) { + Set listeners = listenersByEvent.get(eventName); + if (listeners != null) + listeners.remove(listener); + } + + @Override + public void dispatchEvent(Event event) { + Set listeners = (Set) listenersByEvent.get(event.getName()); + if ((listeners != null) && (listeners.size() > 0)) { + for (IEventListener listenerObj : listeners) { + if(threadPool!=null){ + threadPool.execute(new EventRunner(listenerObj,event)); + }else{ + listenerObj.handleEvent(event); + } + + } + } + } + + @Override + public void removeAllListener() { + listenersByEvent.clear(); + } + + private static final class EventRunner implements Runnable { + private final IEventListener listener; + private final Event event; + + public EventRunner(IEventListener listener, Event event) { + this.listener = listener; + this.event = event; + } + + public void run() { + try { + listener.handleEvent(event); + } catch (Exception e) { + Logger.getLogger(getClass()).warn("Error in event handler: " + e + ", Event: " + event + " Listener: " + listener); + } + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventManager.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventManager.java new file mode 100644 index 0000000..0d99d8b --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/EventManager.java @@ -0,0 +1,63 @@ +package com.taurus.core.events; + +import java.util.concurrent.ThreadPoolExecutor; + +import com.taurus.core.service.AbstractService; +import com.taurus.core.util.Logger; + +/** + * 事件管理,处理框架内部事件 + * + * + * + */ +public final class EventManager extends AbstractService implements IEventDispatcher { + private final ThreadPoolExecutor threadPool; + private final EventDispatcher dispatcher; + private final Logger logger; + + public EventManager(ThreadPoolExecutor threadPool) { + setName("EventManager"); + logger = Logger.getLogger(EventManager.class); + + this.threadPool = threadPool; + dispatcher = new EventDispatcher(threadPool); + } + + public void init(Object o) { + super.init(o); + logger.info(this.name + " init."); + } + + public void destroy(Object o) { + super.init(o); + dispatcher.removeAllListener(); + logger.info(this.name + " shut down."); + } + + public ThreadPoolExecutor getThreadPool() { + return this.threadPool; + } + + public void addEventListener(String eventName, IEventListener listener) { + dispatcher.addEventListener(eventName, listener); + } + + public boolean hasEventListener(String eventName) { + return dispatcher.hasEventListener(eventName); + } + + public void removeEventListener(String eventName, IEventListener listener) { + dispatcher.removeEventListener(eventName, listener); + } + + public void dispatchEvent(Event event) { + dispatcher.dispatchEvent(event); + } + + @Override + public void removeAllListener() { + dispatcher.removeAllListener(); + } + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventDispatcher.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventDispatcher.java new file mode 100644 index 0000000..b7128c2 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventDispatcher.java @@ -0,0 +1,40 @@ +package com.taurus.core.events; + +/** + * 事件派发器通用接口 + * + */ +public interface IEventDispatcher { + + /** + * 添加指定类型的事件监听 + * @param eventName + * @param listener + */ + public void addEventListener(String eventName, IEventListener listener); + + /** + * 检查指定类型事件监听器是否存在 + * @param eventName + * @return + */ + public boolean hasEventListener(String eventName); + + /** + * 删除指定的事件监听 + * @param eventName + * @param listener + */ + public void removeEventListener(String eventName, IEventListener listener); + + /** + * 删除所有的事件监听 + */ + public void removeAllListener(); + + /** + * + * @param event + */ + public void dispatchEvent(Event event); +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventListener.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventListener.java new file mode 100644 index 0000000..2281095 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/events/IEventListener.java @@ -0,0 +1,14 @@ +package com.taurus.core.events; + +/** + * 事件监听接口 + * + */ +public interface IEventListener { + + /** + * + * @param event + */ + public void handleEvent(Event event); +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/IPlugin.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/IPlugin.java new file mode 100644 index 0000000..6406aec --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/IPlugin.java @@ -0,0 +1,23 @@ + +package com.taurus.core.plugin; + +import org.jdom.Element; + +/** + * IPlugin + */ +public interface IPlugin { + String getId(); + + void setId(String id); + + /** + * 加载配置 + * @param element + * @return + */ + boolean loadConfig(Element element); + + boolean start(); + boolean stop(); +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/PluginService.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/PluginService.java new file mode 100644 index 0000000..dd33c7f --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/PluginService.java @@ -0,0 +1,149 @@ +package com.taurus.core.plugin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; + +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; + +public class PluginService { + private static final String CONFIG_PATH = "config/taurus-core.xml"; + private final Logger logger; + + /** + * 插件列表 + */ + final ConcurrentMap pluginMap; + + private static PluginService _instance; + + /** + * get main instance + */ + public static PluginService me() { + if (_instance == null) { + _instance = new PluginService(); + } + return _instance; + } + + private PluginService() { + logger = Logger.getLogger(PluginService.class); + pluginMap = new ConcurrentHashMap(); + } + + /** + * 加载配置 + * @throws Exception + */ + public void loadConfig() throws Exception{ + loadConfig(System.getProperty("user.dir")); + } + + private IPlugin createPlugin(String pclass) throws RuntimeException { + if (StringUtil.isEmpty(pclass)) { + logger.info("Plugin class not find!"); + return null; + } + IPlugin plugin = null; + try { + Class extensionClass = Class.forName(pclass); + if (!IPlugin.class.isAssignableFrom(extensionClass)) { + throw new RuntimeException("Controller does not implement IPlugin! "+pclass); + } + plugin = (IPlugin) extensionClass.newInstance(); + } catch (IllegalAccessException e) { + throw new RuntimeException("Illegal access while instantiating class: " + pclass); + } catch (InstantiationException e) { + throw new RuntimeException("Cannot instantiate class: " + pclass); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Class not found: " + pclass); + } + return plugin; + } + + /** + * 加载配置 + * @param path + * @throws Exception + */ + public void loadConfig(String path) throws Exception{ + File file = new File(path+"/"+CONFIG_PATH); + if(!file.exists())return; + InputStream is = new FileInputStream(file); + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(is); + Element root = document.getRootElement(); + + String log4jPath = root.getChildTextTrim("log4jPath"); + if(StringUtil.isNotEmpty(log4jPath)) { + try { + Class.forName("org.apache.log4j.PropertyConfigurator"); + log4jPath = path+"/config/" + log4jPath; + org.apache.log4j.PropertyConfigurator.configure(log4jPath); + }catch (ClassNotFoundException e) { + } + } + + Iterator itr = (root.getChildren("plugin")).iterator(); + while(itr.hasNext()) { + Element pluginEm = (Element)itr.next(); + String pid = pluginEm.getChildTextTrim("id"); + if(StringUtil.isEmpty(pid)) { + throw new RuntimeException("Plugin id is null!"); + } + String pclass = pluginEm.getChildTextTrim("class"); + if(StringUtil.isEmpty(pclass)) { + throw new RuntimeException("Plugin class is null!"); + } + IPlugin plugin = createPlugin(pclass); + plugin.setId(pid); + plugin.loadConfig(pluginEm); + putPlugin(plugin); + logger.info("plugin["+plugin.getId()+"] load success!"); + } + } + + /** + * put plugin instance + * @param plugin + */ + public final void putPlugin(IPlugin plugin) { + if(pluginMap.containsKey(plugin.getId()))return; + plugin.start(); + pluginMap.put(plugin.getId(),plugin); + } + + /** + * remove plugin + * @param pluginId plugin key id + */ + public final void removePlugin(String pluginId) { + IPlugin plugin =pluginMap.remove(pluginId); + if(plugin!=null) { + plugin.stop(); + } + } + + /** + * stop all plugin + */ + public final void stop() { + Collection list = pluginMap.values(); + for(IPlugin plugin : list) { + plugin.stop(); + } + pluginMap.clear(); + } + + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBase.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBase.java new file mode 100644 index 0000000..c693f6a --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBase.java @@ -0,0 +1,62 @@ +package com.taurus.core.plugin.database; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import com.taurus.core.util.StringUtil; +import com.zaxxer.hikari.HikariDataSource; + +/** + * DataBase 数据库工具 + *
+ * DataBase.use().executeQueryByTArray("SELECT * FROM table");
+ * 
+ * + * + */ +public class DataBase { + static Db mainDb = null; + + static final ConcurrentMap dbMap = new ConcurrentHashMap(); + + static void addDb(Db db) { + if (db == null) + throw new IllegalArgumentException("cache can not be null"); + if (dbMap.containsKey(db.getName())) + throw new IllegalArgumentException("The cache name already exists"); + + dbMap.put(db.getName(), db); + if (mainDb == null) + mainDb = db; + } + + static void removeDb(String dbName) { + Db db = dbMap.remove(dbName); + if(db == mainDb) { + ((HikariDataSource)db.ds).close(); + mainDb = null; + } + } + + /** + * set mainDb + */ + public static void setMainDb(String dbName) { + if (StringUtil.isEmpty(dbName)) + throw new IllegalArgumentException("dbName can not be blank"); + dbName = dbName.trim(); + Db db = dbMap.get(dbName); + if (db == null) + throw new IllegalArgumentException("the db not exists: " + dbName); + + DataBase.mainDb = db; + } + + public static Db use() { + return mainDb; + } + + public static Db use(String dbName) { + return dbMap.get(dbName); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBasePlugin.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBasePlugin.java new file mode 100644 index 0000000..48599ac --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/DataBasePlugin.java @@ -0,0 +1,132 @@ +package com.taurus.core.plugin.database; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.jdom.Element; + +import com.taurus.core.plugin.IPlugin; +import com.taurus.core.plugin.database.DataBasePlugin.DatabaseConfig.DbConfig; +import com.taurus.core.plugin.database.DataBasePlugin.DatabaseConfig.PoolConfig; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +/** + * DataBasePlugin 支持多个数据库连接组件 + * + * + * + */ +public class DataBasePlugin implements IPlugin { + private String id; + + private DatabaseConfig config; + + public DataBasePlugin() { + this.config = new DatabaseConfig(); + } + + @Override + public boolean start() { + + for (DbConfig dbconfig : this.config.dbList) { + PoolConfig config = this.config.poolConfig; + + HikariConfig hk_config = new HikariConfig(); + hk_config.setPoolName(dbconfig.name); + hk_config.setJdbcUrl(dbconfig.jdbcUrl); + hk_config.setUsername(dbconfig.userName); + hk_config.setPassword(dbconfig.password); + hk_config.setDriverClassName(dbconfig.driverName); + hk_config.setMaximumPoolSize(config.maxPool); + hk_config.setMinimumIdle(config.minIdle); + hk_config.setConnectionTimeout(config.connectionTimeout); + hk_config.setIdleTimeout(config.idleTimeout); + hk_config.setMaxLifetime(config.maxLifetime); + hk_config.setConnectionTestQuery(config.validationQuery); + hk_config.setDataSourceProperties(config.props); + + HikariDataSource dbPool = new HikariDataSource(hk_config); + Db db = new Db(dbconfig.name, dbPool); + DataBase.addDb(db); + } + + return true; + } + + @Override + public boolean stop() { + Set keys = DataBase.dbMap.keySet(); + for (String key : keys) { + DataBase.removeDb(key); + } + return true; + } + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + @Override + public boolean loadConfig(Element element) { + Element pcEm = element.getChild("poolConfig"); + this.config.poolConfig.maxPool = Integer.parseInt(pcEm.getChild("maxPool").getTextTrim()); + this.config.poolConfig.minIdle = Integer.parseInt(pcEm.getChild("minIdle").getTextTrim()); + this.config.poolConfig.maxLifetime = Integer.parseInt(pcEm.getChild("maxLifetime").getTextTrim()); + this.config.poolConfig.validationQuery = pcEm.getChild("validationQuery").getTextTrim(); + this.config.poolConfig.connectionTimeout = Integer.parseInt(pcEm.getChild("connectionTimeout").getTextTrim()); + this.config.poolConfig.idleTimeout = Integer.parseInt(pcEm.getChild("idleTimeout").getTextTrim()); + Element propsEm = pcEm.getChild("props"); + List props = propsEm.getChildren(); + for (Object obj : props) { + Element pEm = (Element) obj; + this.config.poolConfig.props.put(pEm.getName(), pEm.getTextTrim()); + } + + Element dblistEm = element.getChild("databases"); + Iterator itr = (dblistEm.getChildren()).iterator(); + while (itr.hasNext()) { + Element dbEm = (Element) itr.next(); + DbConfig dbconfig = new DbConfig(); + dbconfig.name = dbEm.getChildTextTrim("name"); + dbconfig.driverName = dbEm.getChildTextTrim("driverName"); + dbconfig.jdbcUrl = dbEm.getChildTextTrim("jdbcUrl"); + dbconfig.userName = dbEm.getChildTextTrim("userName"); + dbconfig.password = dbEm.getChildTextTrim("password"); + this.config.dbList.add(dbconfig); + } + return true; + } + + public static final class DatabaseConfig { + public volatile PoolConfig poolConfig = new PoolConfig(); + public volatile List dbList = new ArrayList(); + + public static final class PoolConfig { + public int maxPool = 8; + public int minIdle = 8; + public int maxLifetime = 6000; + public int connectionTimeout = 3000; + public int idleTimeout = 60000; + public String validationQuery = "select 1"; + public Properties props = new Properties(); + } + + public static final class DbConfig { + public String name = ""; + public String driverName = ""; + public String jdbcUrl = ""; + public String userName = ""; + public String password = ""; + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/Db.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/Db.java new file mode 100644 index 0000000..5a9cb4c --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/database/Db.java @@ -0,0 +1,807 @@ +package com.taurus.core.plugin.database; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.sql.DataSource; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TDataWrapper; +import com.taurus.core.util.StringUtil; + +/** + * Db 数据库工具 + * + * + */ +public class Db { + protected String name; + protected DataSource ds; + + private static final String STR_NULL = ""; + private static final char CHAR_COMMA = ','; + private static final char CHAR_QUOTES = '\''; + private static final char CHAR_UNKNOWN = '?'; + private static final String TYPE_BOOLEAN = "boolean"; + + public Db(String name, DataSource ds) { + this.name = name; + this.ds = ds; + } + + /** + * 数据库 exec select + * + * @param sql select 数据 + * @return + * @throws SQLException + */ + public List> executeQuery(String sql) throws SQLException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rset = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + rset = stmt.executeQuery(); + + ResultSetMetaData rsmd = rset.getMetaData(); + int dataSize = rsmd.getColumnCount(); + + List> list = new ArrayList>(); + + while (rset.next()) { + if (rset.isBeforeFirst()) { + rset.next(); + } + Map map = new HashMap(); + for (int i = 1; i <= dataSize; i++) { + String columnName = rsmd.getColumnName(i); + if (StringUtil.isEmpty(columnName)) + continue; + Object column = rset.getObject(columnName); + String columnStr = null; + if (column == null || StringUtil.isEmpty(column.toString())) { + columnStr = STR_NULL; + } else { + columnStr = column.toString(); + } + map.put(columnName, columnStr); + } + list.add(map); + } + return list; + } finally { + try { + if (rset != null) + rset.close(); + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + + } + + private static void writeValueFromSetter(Field field, Object pojo, Object fieldValue) throws Exception { + String setterName = "set" + StringUtil.capitalize(field.getName()); + Method setterMethod = pojo.getClass().getMethod(setterName, new Class[] { field.getType() }); + setterMethod.invoke(pojo, new Object[] { fieldValue }); + } + + private static final void setFieldValue(Object pojo, Field field, Object fieldValue) throws Exception { + int modifiers = field.getModifiers(); + if ((Modifier.isTransient(modifiers)) || (Modifier.isStatic(modifiers))) { + return; + } + if (Modifier.isPublic(modifiers)) + field.set(pojo, fieldValue); + else + writeValueFromSetter(field, pojo, fieldValue); + } + + private static Object readValueFromGetter(String fieldName, String type, Object pojo) throws Exception { + Object value = null; + boolean isBool = type.equalsIgnoreCase(TYPE_BOOLEAN); + String getterName = isBool ? "is" : "get" + StringUtil.capitalize(fieldName); + Method getterMethod = pojo.getClass().getMethod(getterName, new Class[0]); + value = getterMethod.invoke(pojo, new Object[0]); + + return value; + } + + private static final Object getFieldValue(Field field, Object pojo) throws Exception { + int modifiers = field.getModifiers(); + if ((Modifier.isTransient(modifiers)) || (Modifier.isStatic(modifiers))) { + return null; + } + Object fieldValue = null; + + if (Modifier.isPublic(modifiers)) { + fieldValue = field.get(pojo); + } else { + fieldValue = readValueFromGetter(field.getName(), field.getType().getSimpleName(), pojo); + } + + return fieldValue; + } + + /** + * 数据库 exec select + * + * @param sql select 数据 + * @param pojoClazz + * @return + * @throws Exception + */ + @SuppressWarnings("unchecked") + public List executeQuery(String sql, Class clazz) throws Exception { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rset = null; + + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + rset = stmt.executeQuery(); + + List list = new ArrayList(); + + while (rset.next()) { + if (rset.isBeforeFirst()) { + rset.next(); + } + Object pojo = clazz.newInstance(); + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + int modifiers = field.getModifiers(); + if ((Modifier.isTransient(modifiers)) || (Modifier.isStatic(modifiers))) { + continue; + } + Object column = null; + try { + column = rset.getObject(field.getName()); + if (column == null) { + continue; + } + } catch (Exception e) { + continue; + } + setFieldValue(pojo, field, column); + } + list.add((T) pojo); + } + return list; + } finally { + try { + if (rset != null) + rset.close(); + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + } + + /** + * 数据库 exec select + * + * @param sql select 数据 + * @return + * @throws SQLException + */ + public ITArray executeQueryByTArray(String sql) throws SQLException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rset = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + + rset = stmt.executeQuery(); + ITArray list = TArray.newFromResultSet(rset); + return list; + } finally { + try { + if (rset != null) + rset.close(); + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + } + + /** + * 数据库 exec select + * + * @param sql select 数据 + * @return + * @throws SQLException + */ + public ITArray executeQueryByTArrayLogin(String sql, String[] params) throws SQLException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rset = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + + if (stmt == null) + throw new SQLException(sql + "sql error!"); + if (params.length != 0) { + for (int i = 0; i < params.length; i++) { + stmt.setString(i + 1, params[i]); + + } + } + rset = stmt.executeQuery(); + ITArray list = TArray.newFromResultSet(rset); + return list; + } finally { + try { + if (rset != null) + rset.close(); + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + } + + /** + * 数据库 exec sql + * + * @param sql sql数据 + * @return + * @throws SQLException + */ + public int executeUpdate(String sql) throws SQLException { + return __executeUpdate(sql); + } + + /** + * 数据库 exec sql + * + * @param sql sql数据 + * @return + * @throws SQLException + */ + public int executeUpdateLogin(String sql, String params[]) throws SQLException { + return __executeUpdateLogin(sql, params); + } + + private int __executeUpdateLogin(String sql, String params[]) throws SQLException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + if (params.length != 0) { + for (int i = 0; i < params.length; i++) { + stmt.setString(i + 1, params[i]); + } + } + int result = stmt.executeUpdate(); + return result; + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + + private int __executeUpdate(String sql) throws SQLException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + int result = stmt.executeUpdate(); + return result; + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + + /** + * 数据库 insert into tableName values() + * + * @param table 表名 + * @param data insert数据 + * @return + * @throws SQLException + */ + public int insert(String table, ITObject data) throws SQLException { + if (StringUtil.isEmpty(table)) { + throw new SQLException("table is null!"); + } + if (data == null) { + throw new SQLException("data is null!"); + } + StringBuilder valuesql = new StringBuilder(); + StringBuilder keysql = new StringBuilder(); + Set keys = data.getKeys(); + int count = 0; + for (String key : keys) { + TDataWrapper wrapper = data.get(key); + if (count > 0) { + keysql.append(CHAR_COMMA); + valuesql.append(CHAR_COMMA); + } + count++; + keysql.append(key); + switch (wrapper.getTypeId()) { + case SHORT: + case INT: + case DOUBLE: + case FLOAT: + case BYTE: + case BOOL: + case LONG: + valuesql.append(wrapper.getObject()); + break; + case STRING: + valuesql.append(CHAR_QUOTES); + valuesql.append(wrapper.getObject()); + valuesql.append(CHAR_QUOTES); + break; + case TOBJECT: + ITObject mo = (ITObject) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(mo.toJson()); + valuesql.append(CHAR_QUOTES); + break; + case TARRAY: + ITArray ao = (ITArray) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(ao.toJson()); + valuesql.append(CHAR_QUOTES); + break; + default: + break; + } + } + + String sql = String.format("INSERT INTO %s (%s) VALUES(%s)", table, keysql, valuesql); + return __executeUpdate(sql); + } + + /** + * 数据库 insert into tableName values() + * + * @param table 表名 + * @param data insert数据 + * @return + * @throws SQLException + */ + public int insert(String table, T data) throws Exception { + if (StringUtil.isEmpty(table)) { + throw new SQLException("table is null!"); + } + if (data == null) { + throw new SQLException("data is null!"); + } + StringBuilder valuesql = new StringBuilder(); + StringBuilder keysql = new StringBuilder(); + // 获取类中的全部定义字段 + Field[] fields = data.getClass().getDeclaredFields(); + int count = 0; + for (Field field : fields) { + Object value = getFieldValue(field, data); + if (value == null) + continue; + if (count > 0) { + keysql.append(CHAR_COMMA); + valuesql.append(CHAR_COMMA); + } + count++; + keysql.append(field.getName()); + if ((value instanceof Boolean) || (value instanceof Byte) || (value instanceof Short) + || (value instanceof Integer) || (value instanceof Long) || (value instanceof Float) + || (value instanceof Double)) { + valuesql.append(value); + } else if ((value instanceof String)) { + valuesql.append(CHAR_QUOTES); + valuesql.append(value); + valuesql.append(CHAR_QUOTES); + } + } + String sql = String.format("INSERT INTO %s (%s) VALUES(%s)", table, keysql, valuesql); + return __executeUpdate(sql); + } + + /** + * 数据库 insert into tableName values() + * + * @param table 表名 + * @param list insert数据 + * @return + * @throws SQLException + */ + public int insertBatch(String table, List list) throws Exception { + if (StringUtil.isEmpty(table)) { + throw new SQLException("table is null!"); + } + if (list == null) { + throw new SQLException("list is null!"); + } + if (list.size() == 0) + return 0; + + StringBuilder valuesql = new StringBuilder(); + StringBuilder keysql = new StringBuilder(); + // 获取类中的全部定义字段 + T data = list.get(0); + Class classz = data.getClass(); + Field[] fields = classz.getDeclaredFields(); + + int count = 0; + List methodList = new ArrayList<>(); + for (Field field : fields) { + int modifiers = field.getModifiers(); + if ((Modifier.isTransient(modifiers)) || (Modifier.isStatic(modifiers))) { + continue; + } + String fieldName = field.getName(); + boolean isBool = field.getType().getSimpleName().equalsIgnoreCase(TYPE_BOOLEAN); + String getterName = isBool ? "is" : "get" + StringUtil.capitalize(fieldName); + Method getterMethod = classz.getMethod(getterName, new Class[0]); + methodList.add(getterMethod); + if (count > 0) { + keysql.append(CHAR_COMMA); + valuesql.append(CHAR_COMMA); + } + count++; + keysql.append(field.getName()); + valuesql.append(CHAR_UNKNOWN); + } + String sql = String.format("INSERT INTO %s (%s) VALUES(%s)", table, keysql, valuesql); + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareStatement(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + conn.setAutoCommit(false); + for (int i = 0; i < list.size(); ++i) { + T obj = list.get(i); + for (int k = 1; k <= count; ++k) { + Method method = methodList.get(k - 1); + Object value = method.invoke(obj, new Object[0]); + stmt.setObject(k, value); + } + stmt.addBatch(); + } + stmt.executeBatch(); + conn.commit(); + return 0; + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + + /** + * 数据库 update tableName set + * + * @param table 表名 + * @param data 更新的字段 + * @param where sql条件 + * @return + * @throws SQLException + */ + public int update(String table, ITObject data, String where) throws SQLException { + if (StringUtil.isEmpty(table)) { + throw new SQLException("table is null!"); + } + if (data == null || data.size() == 0) { + throw new SQLException("data is null!"); + } + StringBuilder valuesql = new StringBuilder(); + Set keys = data.getKeys(); + int count = 0; + for (String key : keys) { + TDataWrapper wrapper = data.get(key); + if (count > 0) { + valuesql.append(CHAR_COMMA); + } + count++; + valuesql.append(key); + valuesql.append("="); + switch (wrapper.getTypeId()) { + case SHORT: + case INT: + case DOUBLE: + case FLOAT: + case BYTE: + case BOOL: + case LONG: + valuesql.append(wrapper.getObject()); + break; + case STRING: + valuesql.append(CHAR_QUOTES); + valuesql.append(wrapper.getObject()); + valuesql.append(CHAR_QUOTES); + break; + case TOBJECT: + ITObject mo = (ITObject) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(mo.toJson()); + valuesql.append(CHAR_QUOTES); + break; + case TARRAY: + ITArray ao = (ITArray) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(ao.toJson()); + valuesql.append(CHAR_QUOTES); + break; + default: + break; + } + } + + String sql = String.format("UPDATE %s SET %s ", table, valuesql); + if (where != null && where.length() > 0) + sql = sql + "where " + where; + return __executeUpdate(sql); + } + + /** + * 数据库 update tableName set + * + * @param table 表名 + * @param data 更新的字段 + * @param where sql条件 + * @return + * @throws Exception + */ + public int update(String table, T data, String where) throws Exception { + if (StringUtil.isEmpty(table)) { + throw new SQLException("table is null!"); + } + if (data == null) { + throw new SQLException("data is null!"); + } + StringBuilder valuesql = new StringBuilder(); + + // 获取类中的全部定义字段 + Field[] fields = data.getClass().getDeclaredFields(); + int count = 0; + for (Field field : fields) { + Object value = getFieldValue(field, data); + if (value == null) + continue; + if (count > 0) { + valuesql.append(CHAR_COMMA); + } + count++; + valuesql.append(field.getName()); + valuesql.append("="); + if ((value instanceof Boolean) || (value instanceof Byte) || (value instanceof Short) + || (value instanceof Integer) || (value instanceof Long) || (value instanceof Float) + || (value instanceof Double)) { + valuesql.append(value); + } else if ((value instanceof String)) { + valuesql.append(CHAR_QUOTES); + valuesql.append(value); + valuesql.append(CHAR_QUOTES); + } + } + + String sql = String.format("UPDATE %s SET %s ", table, valuesql); + if (where != null && where.length() > 0) + sql = sql + "where " + where; + return __executeUpdate(sql); + } + + /** + * 存储过程调用 call prepareName() + * + * @param prepareName 存储过程名 + * @param data 数据 + * @return + * @throws SQLException + */ + public ITArray prepareCall(String prepareName, ITArray data) throws SQLException { + return prepareCall(prepareName, data, true); + } + + /** + * 存储过程调用 call prepareName() + * + * @param prepareName 存储过程名 + * @param data 数据 + * @return + * @throws SQLException + */ + public void prepareCallNonResult(String prepareName, ITArray data) throws SQLException { + prepareCall(prepareName, data, false); + } + + /** + * 存储过程调用 call prepareName() + * + * @param prepareName 存储过程名 + * @param data 数据 + * @return + * @throws SQLException + */ + private ITArray prepareCall(String prepareName, ITArray data, boolean resultSet) throws SQLException { + if (StringUtil.isEmpty(prepareName)) { + throw new SQLException("prepare name is null!"); + } + if (data == null) { + throw new SQLException("data is null!"); + } + StringBuilder valuesql = new StringBuilder(); + + int count = 0; + for (int i = 0; i < data.size(); ++i) { + + TDataWrapper wrapper = data.get(i); + if (count > 0) { + valuesql.append(CHAR_COMMA); + } + count++; + switch (wrapper.getTypeId()) { + case SHORT: + case INT: + case DOUBLE: + case FLOAT: + case BYTE: + case BOOL: + case LONG: + valuesql.append(wrapper.getObject()); + break; + case STRING: + valuesql.append(CHAR_QUOTES); + valuesql.append(wrapper.getObject()); + valuesql.append(CHAR_QUOTES); + break; + case TOBJECT: + ITObject mo = (ITObject) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(mo.toJson()); + valuesql.append(CHAR_QUOTES); + break; + case TARRAY: + ITArray ao = (ITArray) wrapper.getObject(); + valuesql.append(CHAR_QUOTES); + valuesql.append(ao.toJson()); + valuesql.append(CHAR_QUOTES); + break; + default: + break; + } + } + String sql = String.format("{call %s(%s)}", prepareName, valuesql); + return executeCall(sql, resultSet); + } + + /** + * 存储过程调用 + * + * @param sql + * @param resultSet + * @return + * @throws SQLException + */ + public ITArray executeCall(String sql, boolean resultSet) throws SQLException { + Connection conn = null; + CallableStatement stmt = null; + ResultSet rset = null; + try { + conn = ds.getConnection(); + if (conn == null) + throw new SQLException("db connection is null!"); + stmt = conn.prepareCall(sql); + if (stmt == null) + throw new SQLException(sql + "sql error!"); + if (resultSet) { + rset = stmt.executeQuery(); + ITArray list = TArray.newFromResultSet(rset); + return list; + } else { + stmt.executeUpdate(); + return null; + } + } finally { + try { + if (rset != null) + rset.close(); + } finally { + try { + if (stmt != null) + stmt.close(); + } finally { + if (conn != null) + conn.close(); + } + } + } + } + + /** + * 获取当前DB名称 + * + * @return + */ + public String getName() { + return name; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Cache.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Cache.java new file mode 100644 index 0000000..be88699 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Cache.java @@ -0,0 +1,1212 @@ +package com.taurus.core.plugin.redis; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.taurus.core.util.StringUtil; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.Pipeline; + +/** + * Cache. + * Cache api 添加了中文注释,便于工程师更方便使用,另外还原样保持了 + * Jedis api 的方法名称及使用方法,以便于仅仅通过查看 Redis 文档 + * 即可快速掌握使用方法 + * Redis 命令参考: http://redisdoc.com/ + */ +public class Cache { + + protected String name; + protected JedisPool jedisPool; + + + protected Cache() { + + } + + public Cache(String name, JedisPool jedisPool) { + this.name = name; + this.jedisPool = jedisPool; + } + + /** + * 存放 key value 对到 redis + * 如果 key 已经持有其他值, SET 就覆写旧值,无视类型。 + * 对于某个原本带有生存时间(TTL)的键来说, 当 SET 命令成功在这个键上执行时, 这个键原有的 TTL 将被清除。 + */ + public String set(String key, String value) { + Jedis jedis = getJedis(); + try { + return jedis.set(key, value); + } + finally {close(jedis);} + } + + /** + * 存放 key value 对到 redis,并将 key 的生存时间设为 seconds (以秒为单位)。 + * 如果 key 已经存在, SETEX 命令将覆写旧值。 + */ + public String setex(String key, int seconds, String value) { + Jedis jedis = getJedis(); + try { + return jedis.setex(key, seconds, value); + } + finally {close(jedis);} + } + + /** + * 将 key 的值设为 value ,当且仅当 key 不存在。 若给定的 key 已经存在,则 SETNX 不做任何动作。 SETNX 是『SET if Not eXists』(如果不存在,则 SET)的简写。
+ *1 设置成功
+ *0 设置失败 + */ + public Long setnx(String key, String value) { + Jedis jedis = getJedis(); + try { + return jedis.setnx(key, value); + } + finally {close(jedis);} + } + + /** + * 返回 key 所关联的 value 值 + * 如果 key 不存在那么返回特殊值 nil 。 + */ + public String get(String key) { + Jedis jedis = getJedis(); + try { + return jedis.get(key); + } + finally {close(jedis);} + } + + /** + * 删除给定的一个 key + * 不存在的 key 会被忽略。 + */ + public Long del(String key) { + Jedis jedis = getJedis(); + try { + return jedis.del(key); + } + finally {close(jedis);} + } + + /** + * 删除给定的多个 key + * 不存在的 key 会被忽略。 + */ + public Long del(String... keys) { + Jedis jedis = getJedis(); + try { + return jedis.del(keys); + } + finally {close(jedis);} + } + + /** + * 查找所有符合给定模式 pattern 的 key 。 + * KEYS * 匹配数据库中所有 key 。 + * KEYS h?llo 匹配 hello , hallo 和 hxllo 等。 + * KEYS h*llo 匹配 hllo 和 heeeeello 等。 + * KEYS h[ae]llo 匹配 hello 和 hallo ,但不匹配 hillo 。 + * 特殊符号用 \ 隔开 + */ + public Set keys(String pattern) { + Jedis jedis = getJedis(); + try { + return jedis.keys(pattern); + } + finally {close(jedis);} + } + + /** + * 同时设置一个或多个 key-value 对。 + * 如果某个给定 key 已经存在,那么 MSET 会用新值覆盖原来的旧值,如果这不是你所希望的效果,请考虑使用 MSETNX 命令:它只会在所有给定 key 都不存在的情况下进行设置操作。 + * MSET 是一个原子性(atomic)操作,所有给定 key 都会在同一时间内被设置,某些给定 key 被更新而另一些给定 key 没有改变的情况,不可能发生。 + *
+	 * 例子:
+	 * Cache cache = RedisKit.use();			// 使用 Redis 的 cache
+	 * cache.mset("k1", "v1", "k2", "v2");		// 放入多个 key value 键值对
+	 * List list = cache.mget("k1", "k2");		// 利用多个键值得到上面代码放入的值
+	 * 
+ */ + public String mset(String... keysValues) { + if (keysValues.length % 2 != 0) + throw new IllegalArgumentException("wrong number of arguments for met, keysValues length can not be odd"); + Jedis jedis = getJedis(); + try { + String[] kv = new String[keysValues.length]; + for (int i=0; i mget(String... keys) { + Jedis jedis = getJedis(); + try { + List data = jedis.mget(keys); + return data; + } + finally {close(jedis);} + } + + /** + * 将 key 中储存的数字值减一。 + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECR 操作。 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 + * 本操作的值限制在 64 位(bit)有符号数字表示之内。 + * 关于递增(increment) / 递减(decrement)操作的更多信息,请参见 INCR 命令。 + */ + public Long decr(String key) { + Jedis jedis = getJedis(); + try { + return jedis.decr(key); + } + finally {close(jedis);} + } + + /** + * 将 key 所储存的值减去减量 decrement 。 + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 DECRBY 操作。 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 + * 本操作的值限制在 64 位(bit)有符号数字表示之内。 + * 关于更多递增(increment) / 递减(decrement)操作的更多信息,请参见 INCR 命令。 + */ + public Long decrBy(String key, long longValue) { + Jedis jedis = getJedis(); + try { + return jedis.decrBy(key, longValue); + } + finally {close(jedis);} + } + + /** + * 将 key 中储存的数字值增一。 + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作。 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 + * 本操作的值限制在 64 位(bit)有符号数字表示之内。 + */ + public Long incr(String key) { + Jedis jedis = getJedis(); + try { + return jedis.incr(key); + } + finally {close(jedis);} + } + + /** + * 将 key 所储存的值加上增量 increment 。 + * 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCRBY 命令。 + * 如果值包含错误的类型,或字符串类型的值不能表示为数字,那么返回一个错误。 + * 本操作的值限制在 64 位(bit)有符号数字表示之内。 + * 关于递增(increment) / 递减(decrement)操作的更多信息,参见 INCR 命令。 + */ + public Long incrBy(String key, long longValue) { + Jedis jedis = getJedis(); + try { + return jedis.incrBy(key, longValue); + } + finally {close(jedis);} + } + + /** + * 检查给定 key 是否存在。 + */ + public boolean exists(String key) { + Jedis jedis = getJedis(); + try { + return jedis.exists(key); + } + finally {close(jedis);} + } + + /** + * 从当前数据库中随机返回(不删除)一个 key 。 + */ + public String randomKey() { + Jedis jedis = getJedis(); + try { + return jedis.randomKey(); + } + finally {close(jedis);} + } + + /** + * 将 key 改名为 newkey 。 + * 当 key 和 newkey 相同,或者 key 不存在时,返回一个错误。 + * 当 newkey 已经存在时, RENAME 命令将覆盖旧值。 + */ + public String rename(String oldkey, String newkey) { + Jedis jedis = getJedis(); + try { + return jedis.rename(oldkey, newkey); + } + finally {close(jedis);} + } + + /** + * 将当前数据库的 key 移动到给定的数据库 db 当中。 + * 如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key ,或者 key 不存在于当前数据库,那么 MOVE 没有任何效果。 + * 因此,也可以利用这一特性,将 MOVE 当作锁(locking)原语(primitive)。 + */ + public Long move(String key, int dbIndex) { + Jedis jedis = getJedis(); + try { + return jedis.move(key, dbIndex); + } + finally {close(jedis);} + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上,一旦传送成功, key 保证会出现在目标实例上,而当前实例上的 key 会被删除。 + */ + public String migrate(String host, int port, String key, int destinationDb, int timeout) { + Jedis jedis = getJedis(); + try { + return jedis.migrate(host, port, key, destinationDb, timeout); + } + finally {close(jedis);} + } + + /** + * 切换到指定的数据库,数据库索引号 index 用数字值指定,以 0 作为起始索引值。 + * 默认使用 0 号数据库。 + * 注意:在 Jedis 对象被关闭时,数据库又会重新被设置为初始值,所以本方法 select(...) + * 正常工作需要使用如下方式之一: + * 1:使用 RedisInterceptor,在本线程内共享同一个 Jedis 对象 + * 2:使用 Redis.call(ICallback) 进行操作 + * 3:自行获取 Jedis 对象进行操作 + */ + public String select(int databaseIndex) { + Jedis jedis = getJedis(); + try { + return jedis.select(databaseIndex); + } + finally {close(jedis);} + } + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。 + * 在 Redis 中,带有生存时间的 key 被称为『易失的』(volatile)。 + */ + public Long expire(String key, int seconds) { + Jedis jedis = getJedis(); + try { + return jedis.expire(key, seconds); + } + finally {close(jedis);} + } + + /** + * EXPIREAT 的作用和 EXPIRE 类似,都用于为 key 设置生存时间。不同在于 EXPIREAT 命令接受的时间参数是 UNIX 时间戳(unix timestamp)。 + */ + public Long expireAt(String key, long unixTime) { + Jedis jedis = getJedis(); + try { + return jedis.expireAt(key, unixTime); + } + finally {close(jedis);} + } + + /** + * 这个命令和 EXPIRE 命令的作用类似,但是它以毫秒为单位设置 key 的生存时间,而不像 EXPIRE 命令那样,以秒为单位。 + */ + public Long pexpire(String key, long milliseconds) { + Jedis jedis = getJedis(); + try { + return jedis.pexpire(key, milliseconds); + } + finally {close(jedis);} + } + + /** + * 这个命令和 EXPIREAT 命令类似,但它以毫秒为单位设置 key 的过期 unix 时间戳,而不是像 EXPIREAT 那样,以秒为单位。 + */ + public Long pexpireAt(String key, long millisecondsTimestamp) { + Jedis jedis = getJedis(); + try { + return jedis.pexpireAt(key, millisecondsTimestamp); + } + finally {close(jedis);} + } + + /** + * 将给定 key 的值设为 value ,并返回 key 的旧值(old value)。 + * 当 key 存在但不是字符串类型时,返回一个错误。 + */ + public String getSet(String key, String value) { + Jedis jedis = getJedis(); + try { + return jedis.getSet(key, value); + } + finally {close(jedis);} + } + + /** + * 移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。 + */ + public Long persist(String key) { + Jedis jedis = getJedis(); + try { + return jedis.persist(key); + } + finally {close(jedis);} + } + + /** + * 返回 key 所储存的值的类型。 + */ + public String type(String key) { + Jedis jedis = getJedis(); + try { + return jedis.type(key); + } + finally {close(jedis);} + } + + /** + * 以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。 + */ + public Long ttl(String key) { + Jedis jedis = getJedis(); + try { + return jedis.ttl(key); + } + finally {close(jedis);} + } + + /** + * 这个命令类似于 TTL 命令,但它以毫秒为单位返回 key 的剩余生存时间,而不是像 TTL 命令那样,以秒为单位。 + */ + public Long pttl(String key) { + Jedis jedis = getJedis(); + try { + return jedis.pttl(key); + } + finally {close(jedis);} + } + + /** + * 对象被引用的数量 + */ + public Long objectRefcount(String key) { + Jedis jedis = getJedis(); + try { + return jedis.objectRefcount(key); + } + finally {close(jedis);} + } + + /** + * 对象没有被访问的空闲时间 + */ + public Long objectIdletime(String key) { + Jedis jedis = getJedis(); + try { + return jedis.objectIdletime(key); + } + finally {close(jedis);} + } + + /** + * 将哈希表 key 中的域 field 的值设为 value 。 + * 如果 key 不存在,一个新的哈希表被创建并进行 HSET 操作。 + * 如果域 field 已经存在于哈希表中,旧值将被覆盖。 + */ + public Long hset(String key, String field, String value) { + Jedis jedis = getJedis(); + try { + return jedis.hset(key, field, value); + } + finally {close(jedis);} + } + + /** + * 只在 key 指定的哈希集中不存在指定的字段时,设置字段的值。如果 key 指定的哈希集不存在,会创建一个新的哈希集并与 key 关联。如果字段已存在,该操作无效果。
+ * 1:如果字段是个新的字段,并成功赋值
+ * 0:如果哈希集中已存在该字段,没有操作被执行 + */ + public Long hsetnx(String key, String field, String value) { + Jedis jedis = getJedis(); + try { + return jedis.hsetnx(key, field, value); + } + finally {close(jedis);} + } + + + /** + * 同时将多个 field-value (域-值)对设置到哈希表 key 中。 + * 此命令会覆盖哈希表中已存在的域。 + * 如果 key 不存在,一个空哈希表被创建并执行 HMSET 操作。 + */ + public String hmset(String key, Map hash) { + Jedis jedis = getJedis(); + try { + return jedis.hmset(key, hash); + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中给定域 field 的值。 + */ + public String hget(String key, String field) { + Jedis jedis = getJedis(); + try { + return jedis.hget(key, field); + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中,一个或多个给定域的值。 + * 如果给定的域不存在于哈希表,那么返回一个 nil 值。 + * 因为不存在的 key 被当作一个空哈希表来处理,所以对一个不存在的 key 进行 HMGET 操作将返回一个只带有 nil 值的表。 + */ + public List hmget(String key, String... fields) { + Jedis jedis = getJedis(); + try { + return jedis.hmget(key, fields); + } + finally {close(jedis);} + } + + /** + * 删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。 + */ + public Long hdel(String key, String... fields) { + Jedis jedis = getJedis(); + try { + return jedis.hdel(key, fields); + } + finally {close(jedis);} + } + + /** + * 查看哈希表 key 中,给定域 field 是否存在。 + */ + public boolean hexists(String key, String field) { + Jedis jedis = getJedis(); + try { + return jedis.hexists(key, field); + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中,所有的域和值。 + * 在返回值里,紧跟每个域名(field name)之后是域的值(value),所以返回值的长度是哈希表大小的两倍。 + */ + public Map hgetAll(String key) { + Jedis jedis = getJedis(); + try { + Map data = jedis.hgetAll(key); + return data; + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中所有域的值。 + */ + public List hvals(String key) { + Jedis jedis = getJedis(); + try { + List data = jedis.hvals(key); + return data; + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中的所有域。 + * 底层实现此方法取名为 hfields 更为合适,在此仅为与底层保持一致 + */ + public Set hkeys(String key) { + Jedis jedis = getJedis(); + try { + Set fieldSet = jedis.hkeys(key); + return fieldSet; + } + finally {close(jedis);} + } + + /** + * 返回哈希表 key 中域的数量。 + */ + public Long hlen(String key) { + Jedis jedis = getJedis(); + try { + return jedis.hlen(key); + } + finally {close(jedis);} + } + + /** + * 为哈希表 key 中的域 field 的值加上增量 increment 。 + * 增量也可以为负数,相当于对给定域进行减法操作。 + * 如果 key 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。 + * 如果域 field 不存在,那么在执行命令前,域的值被初始化为 0 。 + * 对一个储存字符串值的域 field 执行 HINCRBY 命令将造成一个错误。 + * 本操作的值被限制在 64 位(bit)有符号数字表示之内。 + */ + public Long hincrBy(String key, String field, long value) { + Jedis jedis = getJedis(); + try { + return jedis.hincrBy(key, field, value); + } + finally {close(jedis);} + } + + /** + * 为哈希表 key 中的域 field 加上浮点数增量 increment 。 + * 如果哈希表中没有域 field ,那么 HINCRBYFLOAT 会先将域 field 的值设为 0 ,然后再执行加法操作。 + * 如果键 key 不存在,那么 HINCRBYFLOAT 会先创建一个哈希表,再创建域 field ,最后再执行加法操作。 + * 当以下任意一个条件发生时,返回一个错误: + * 1:域 field 的值不是字符串类型(因为 redis 中的数字和浮点数都以字符串的形式保存,所以它们都属于字符串类型) + * 2:域 field 当前的值或给定的增量 increment 不能解释(parse)为双精度浮点数(double precision floating point number) + * HINCRBYFLOAT 命令的详细功能和 INCRBYFLOAT 命令类似,请查看 INCRBYFLOAT 命令获取更多相关信息。 + */ + public Double hincrByFloat(String key, String field, double value) { + Jedis jedis = getJedis(); + try { + return jedis.hincrByFloat(key, field, value); + } + finally {close(jedis);} + } + + /** + * 返回列表 key 中,下标为 index 的元素。 + * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 + * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + * 如果 key 不是列表类型,返回一个错误。 + */ + + /** + * 返回列表 key 中,下标为 index 的元素。 + * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素, + * 以 1 表示列表的第二个元素,以此类推。 + * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + * 如果 key 不是列表类型,返回一个错误。 + */ + public String lindex(String key, long index) { + Jedis jedis = getJedis(); + try { + return jedis.lindex(key, index); + } + finally {close(jedis);} + } + + /** + * 获取记数器的值 + */ + public Long getCounter(String key) { + Jedis jedis = getJedis(); + try { + String ret = jedis.get(key); + return ret != null ? Long.parseLong(ret) : null; + } + finally {close(jedis);} + } + + /** + * 返回列表 key 的长度。 + * 如果 key 不存在,则 key 被解释为一个空列表,返回 0 . + * 如果 key 不是列表类型,返回一个错误。 + */ + public Long llen(String key) { + Jedis jedis = getJedis(); + try { + return jedis.llen(key); + } + finally {close(jedis);} + } + + /** + * 移除并返回列表 key 的头元素。 + */ + public String lpop(String key) { + Jedis jedis = getJedis(); + try { + return jedis.lpop(key); + } + finally {close(jedis);} + } + + /** + * 将一个或多个值 value 插入到列表 key 的表头 + * 如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表头: 比如说, + * 对空列表 mylist 执行命令 LPUSH mylist a b c ,列表的值将是 c b a , + * 这等同于原子性地执行 LPUSH mylist a 、 LPUSH mylist b 和 LPUSH mylist c 三个命令。 + * 如果 key 不存在,一个空列表会被创建并执行 LPUSH 操作。 + * 当 key 存在但不是列表类型时,返回一个错误。 + */ + public Long lpush(String key, String... values) { + Jedis jedis = getJedis(); + try { + return jedis.lpush(key, values); + } + finally {close(jedis);} + } + + /** + * 将列表 key 下标为 index 的元素的值设置为 value 。 + * 当 index 参数超出范围,或对一个空列表( key 不存在)进行 LSET 时,返回一个错误。 + * 关于列表下标的更多信息,请参考 LINDEX 命令。 + */ + public String lset(String key, long index, String value) { + Jedis jedis = getJedis(); + try { + return jedis.lset(key, index, value); + } + finally {close(jedis);} + } + + /** + * 根据参数 count 的值,移除列表中与参数 value 相等的元素。 + * count 的值可以是以下几种: + * count > 0 : 从表头开始向表尾搜索,移除与 value 相等的元素,数量为 count 。 + * count < 0 : 从表尾开始向表头搜索,移除与 value 相等的元素,数量为 count 的绝对值。 + * count = 0 : 移除表中所有与 value 相等的值。 + */ + public Long lrem(String key, long count, String value) { + Jedis jedis = getJedis(); + try { + return jedis.lrem(key, count, value); + } + finally {close(jedis);} + } + + /** + * 返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定。 + * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 + * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + *
+	 * 例子:
+	 * 获取 list 中所有数据:cache.lrange(listKey, 0, -1);
+	 * 获取 list 中下标 1 到 3 的数据: cache.lrange(listKey, 1, 3);
+	 * 
+ */ + public List lrange(String key, long start, long end) { + Jedis jedis = getJedis(); + try { + List data = jedis.lrange(key, start, end); + return data; + } + finally {close(jedis);} + } + + /** + * 对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。 + * 举个例子,执行命令 LTRIM list 0 2 ,表示只保留列表 list 的前三个元素,其余元素全部删除。 + * 下标(index)参数 start 和 stop 都以 0 为底,也就是说,以 0 表示列表的第一个元素,以 1 表示列表的第二个元素,以此类推。 + * 你也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推。 + * 当 key 不是列表类型时,返回一个错误。 + */ + public String ltrim(String key, long start, long end) { + Jedis jedis = getJedis(); + try { + return jedis.ltrim(key, start, end); + } + finally {close(jedis);} + } + + /** + * 移除并返回列表 key 的尾元素。 + */ + public String rpop(String key) { + Jedis jedis = getJedis(); + try { + return jedis.rpop(key); + } + finally {close(jedis);} + } + + /** + * 命令 RPOPLPUSH 在一个原子时间内,执行以下两个动作: + * 将列表 source 中的最后一个元素(尾元素)弹出,并返回给客户端。 + * 将 source 弹出的元素插入到列表 destination ,作为 destination 列表的的头元素。 + */ + public String rpoplpush(String srcKey, String dstKey) { + Jedis jedis = getJedis(); + try { + return jedis.rpoplpush(srcKey, dstKey); + } + finally {close(jedis);} + } + + /** + * 将一个或多个值 value 插入到列表 key 的表尾(最右边)。 + * 如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表尾:比如 + * 对一个空列表 mylist 执行 RPUSH mylist a b c ,得出的结果列表为 a b c , + * 等同于执行命令 RPUSH mylist a 、 RPUSH mylist b 、 RPUSH mylist c 。 + * 如果 key 不存在,一个空列表会被创建并执行 RPUSH 操作。 + * 当 key 存在但不是列表类型时,返回一个错误。 + */ + public Long rpush(String key, String... values) { + Jedis jedis = getJedis(); + try { + return jedis.rpush(key, values); + } + finally {close(jedis);} + } + + /** + * BLPOP 是列表的阻塞式(blocking)弹出原语。 + * 它是 LPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BLPOP 命令阻塞,直到等待超时或发现可弹出元素为止。 + * 当给定多个 key 参数时,按参数 key 的先后顺序依次检查各个列表,弹出第一个非空列表的头元素。 + * + * 参考:http://redisdoc.com/list/blpop.html + * 命令行:BLPOP key [key ...] timeout + */ + public List blpop(int timeout, String... keys) { + Jedis jedis = getJedis(); + try { + List data = jedis.blpop(timeout, keys); + return data; + } + finally {close(jedis);} + } + + /** + * BRPOP 是列表的阻塞式(blocking)弹出原语。 + * 它是 RPOP 命令的阻塞版本,当给定列表内没有任何元素可供弹出的时候,连接将被 BRPOP 命令阻塞,直到等待超时或发现可弹出元素为止。 + * 当给定多个 key 参数时,按参数 key 的先后顺序依次检查各个列表,弹出第一个非空列表的尾部元素。 + * 关于阻塞操作的更多信息,请查看 BLPOP 命令, BRPOP 除了弹出元素的位置和 BLPOP 不同之外,其他表现一致。 + * + * 参考:http://redisdoc.com/list/brpop.html + * 命令行:BRPOP key [key ...] timeout + */ + public List brpop(int timeout, String... keys) { + Jedis jedis = getJedis(); + try { + List data = jedis.brpop(timeout, keys); + return data; + } + finally {close(jedis);} + } + + /** + * 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG 。 + * 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值。 + */ + public String ping() { + Jedis jedis = getJedis(); + try { + return jedis.ping(); + } + finally {close(jedis);} + } + + /** + * 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 + * 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 + * 当 key 不是集合类型时,返回一个错误。 + */ + public Long sadd(String key, String... members) { + Jedis jedis = getJedis(); + try { + return jedis.sadd(key, members); + } + finally {close(jedis);} + } + + /** + * 返回集合 key 的基数(集合中元素的数量)。 + */ + public Long scard(String key) { + Jedis jedis = getJedis(); + try { + return jedis.scard(key); + } + finally {close(jedis);} + } + + /** + * 移除并返回集合中的一个随机元素。 + * 如果只想获取一个随机元素,但不想该元素从集合中被移除的话,可以使用 SRANDMEMBER 命令。 + */ + public String spop(String key) { + Jedis jedis = getJedis(); + try { + return jedis.spop(key); + } + finally {close(jedis);} + } + + /** + * 返回集合 key 中的所有成员。 + * 不存在的 key 被视为空集合。 + */ + public Set smembers(String key) { + Jedis jedis = getJedis(); + try { + Set data = jedis.smembers(key); + return data; + } + finally {close(jedis);} + } + + /** + * 判断 member 元素是否集合 key 的成员。 + */ + public boolean sismember(String key, String member) { + Jedis jedis = getJedis(); + try { + return jedis.sismember(key, member); + } + finally {close(jedis);} + } + + /** + * 返回多个集合的交集,多个集合由 keys 指定 + */ + public Set sinter(String... keys) { + Jedis jedis = getJedis(); + try { + Set data = jedis.sinter(keys); + return data; + } + finally {close(jedis);} + } + + /** + * 返回集合中的一个随机元素。 + */ + public String srandmember(String key) { + Jedis jedis = getJedis(); + try { + return jedis.srandmember(key); + } + finally {close(jedis);} + } + + /** + * 返回集合中的 count 个随机元素。 + * 从 Redis 2.6 版本开始, SRANDMEMBER 命令接受可选的 count 参数: + * 如果 count 为正数,且小于集合基数,那么命令返回一个包含 count 个元素的数组,数组中的元素各不相同。 + * 如果 count 大于等于集合基数,那么返回整个集合。 + * 如果 count 为负数,那么命令返回一个数组,数组中的元素可能会重复出现多次,而数组的长度为 count 的绝对值。 + * 该操作和 SPOP 相似,但 SPOP 将随机元素从集合中移除并返回,而 SRANDMEMBER 则仅仅返回随机元素,而不对集合进行任何改动。 + */ + public List srandmember(String key, int count) { + Jedis jedis = getJedis(); + try { + List data = jedis.srandmember(key, count); + return data; + } + finally {close(jedis);} + } + + /** + * 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。 + */ + public Long srem(String key, String... members) { + Jedis jedis = getJedis(); + try { + return jedis.srem(key, members); + } + finally {close(jedis);} + } + + /** + * 返回多个集合的并集,多个集合由 keys 指定 + * 不存在的 key 被视为空集。 + */ + public Set sunion(String... keys) { + Jedis jedis = getJedis(); + try { + Set data = jedis.sunion(keys); + return data; + } + finally {close(jedis);} + } + + /** + * 返回一个集合的全部成员,该集合是所有给定集合之间的差集。 + * 不存在的 key 被视为空集。 + */ + public Set sdiff(String... keys) { + Jedis jedis = getJedis(); + try { + Set data = jedis.sdiff(keys); + return data; + } + finally {close(jedis);} + } + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。 + * 如果某个 member 已经是有序集的成员,那么更新这个 member 的 score 值, + * 并通过重新插入这个 member 元素,来保证该 member 在正确的位置上。 + */ + public Long zadd(String key, double score, String member) { + Jedis jedis = getJedis(); + try { + return jedis.zadd(key, score, member); + } + finally {close(jedis);} + } + + public Long zadd(String key, Map scoreMembers) { + Jedis jedis = getJedis(); + try { +// Map para = new HashMap(); +// for (Entry e : scoreMembers.entrySet()) +// para.put(e.getKey(), e.getValue()); // valueToBytes is important + return jedis.zadd(key, scoreMembers); + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 的基数。 + */ + public Long zcard(String key) { + Jedis jedis = getJedis(); + try { + return jedis.zcard(key); + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。 + * 关于参数 min 和 max 的详细使用方法,请参考 ZRANGEBYSCORE 命令。 + */ + public Long zcount(String key, double min, double max) { + Jedis jedis = getJedis(); + try { + return jedis.zcount(key, min, max); + } + finally {close(jedis);} + } + + /** + * 为有序集 key 的成员 member 的 score 值加上增量 increment 。 + */ + public Double zincrby(String key, double score, String member) { + Jedis jedis = getJedis(); + try { + return jedis.zincrby(key, score, member); + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中,指定区间内的成员。 + * 其中成员的位置按 score 值递增(从小到大)来排序。 + * 具有相同 score 值的成员按字典序(lexicographical order )来排列。 + * 如果你需要成员按 score 值递减(从大到小)来排列,请使用 ZREVRANGE 命令。 + */ + public Set zrange(String key, long start, long end) { + Jedis jedis = getJedis(); + try { + Set data = jedis.zrange(key, start, end); + return data; + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中,指定区间内的成员。 + * 其中成员的位置按 score 值递减(从大到小)来排列。 + * 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order)排列。 + * 除了成员按 score 值递减的次序排列这一点外, ZREVRANGE 命令的其他方面和 ZRANGE 命令一样。 + */ + public Set zrevrange(String key, long start, long end) { + Jedis jedis = getJedis(); + try { + Set data = jedis.zrevrange(key, start, end); + return data; + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。 + * 有序集成员按 score 值递增(从小到大)次序排列。 + */ + public Set zrangeByScore(String key, double min, double max) { + Jedis jedis = getJedis(); + try { + Set data = jedis.zrangeByScore(key, min, max); + return data; + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 + * 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。 + * 使用 ZREVRANK 命令可以获得成员按 score 值递减(从大到小)排列的排名。 + */ + public Long zrank(String key, String member) { + Jedis jedis = getJedis(); + try { + return jedis.zrank(key, member); + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序。 + * 排名以 0 为底,也就是说, score 值最大的成员排名为 0 。 + * 使用 ZRANK 命令可以获得成员按 score 值递增(从小到大)排列的排名。 + */ + public Long zrevrank(String key, String member) { + Jedis jedis = getJedis(); + try { + return jedis.zrevrank(key, member); + } + finally {close(jedis);} + } + + /** + * 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。 + * 当 key 存在但不是有序集类型时,返回一个错误。 + */ + public Long zrem(String key, String... members) { + Jedis jedis = getJedis(); + try { + return jedis.zrem(key, members); + } + finally {close(jedis);} + } + + /** + * 返回有序集 key 中,成员 member 的 score 值。 + * 如果 member 元素不是有序集 key 的成员,或 key 不存在,返回 nil 。 + */ + public Double zscore(String key, String member) { + Jedis jedis = getJedis(); + try { + return jedis.zscore(key, member); + } + finally {close(jedis);} + } + + + /** + * del key + * rpush key values + */ + public void rpushAll(final String key, final List values) { + Jedis jedis = getJedis(); + try { + Pipeline pipeline = getJedis().pipelined(); + pipeline.del(key); + for (String value : values) { + pipeline.rpush(key, value); + } + pipeline.sync(); + } finally { + close(jedis); + } + + } + + /** + * call script + * @param func + * @return + */ + public Object call(final String func) { + return call(func,0,new String[0]); + } + + /** + * call script + * @param func + * @param keyCount + * @param params + * @return + */ + public Object call(final String func,int keyCount, String... params) { + Jedis jedis = getJedis(); + try { + String sha = jedis.get("script#"+func); + if(StringUtil.isNotEmpty(sha)) { + return jedis.evalsha(sha,keyCount,params); + } + }finally {close(jedis);} + return null; + } + + /* ======================================Pub/Sub====================================== */ + + /** + * publish 订阅 + */ + public Long publish(final String channel, final String message) { + Jedis jedis =getJedis(); + try { + return jedis.publish(channel, message); + } + finally {close(jedis);} + + } + + /** + * 订阅给定的一个频道的信息 + */ + public void subscribe(final JedisPubSub jedisPubSub, final String channel) { + Jedis jedis =getJedis(); + try { + jedis.subscribe(jedisPubSub, channel); + } + finally {close(jedis);} + } + + /** + * 取消订阅 + */ + public void unsubscribe(final JedisPubSub jedisPubSub) { + jedisPubSub.unsubscribe(); + } + + + // --------- + + public String getName() { + return name; + } + + public JedisPool getJedisPool() { + return jedisPool; + } + // --------- + + public Jedis getJedis() { + Jedis jedis = jedisPool.getResource(); + return jedis; + } + + public void close(Jedis jedis) { + if (jedis != null) + jedis.close(); + } + + +} + + + + + + diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Redis.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Redis.java new file mode 100644 index 0000000..a76d4b3 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/Redis.java @@ -0,0 +1,70 @@ +package com.taurus.core.plugin.redis; + +import java.util.concurrent.ConcurrentHashMap; + +import com.taurus.core.util.StringUtil; + +/** + * Redis. + * redis 工具类 + *
+ * 例如:
+ * Redis.use().set("key", "value");
+ * Redis.use().get("key");
+ * 
+ */ +public class Redis { + + static Cache mainCache = null; + + static final ConcurrentHashMap cacheMap = new ConcurrentHashMap(); + + static void addCache(Cache cache) { + if (cache == null) + throw new IllegalArgumentException("cache can not be null"); + if (cacheMap.containsKey(cache.getName())) + throw new IllegalArgumentException("The cache name already exists"); + + cacheMap.put(cache.getName(), cache); + if (mainCache == null) + mainCache = cache; + } + + static void removeCache(String cacheName) { + Cache cache = cacheMap.remove(cacheName); + if(cache == mainCache) { + cache.jedisPool.destroy(); + mainCache = null; + } + } + + /** + * 提供一个设置设置主缓存 mainCache 的机会,否则第一个被初始化的 Cache 将成为 mainCache + */ + public static void setMainCache(String cacheName) { + if (StringUtil.isEmpty(cacheName)) + throw new IllegalArgumentException("cacheName can not be blank"); + cacheName = cacheName.trim(); + Cache cache = cacheMap.get(cacheName); + if (cache == null) + throw new IllegalArgumentException("the cache not exists: " + cacheName); + + Redis.mainCache = cache; + } + + public static Cache use() { + return mainCache; + } + + public static Cache use(String cacheName) { + return cacheMap.get(cacheName); + } + + public static ConcurrentHashMap getCacheMap() { + return cacheMap; + } +} + + + + diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisLock.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisLock.java new file mode 100644 index 0000000..8028caf --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisLock.java @@ -0,0 +1,76 @@ +package com.taurus.core.plugin.redis; + +import java.util.UUID; + +import redis.clients.jedis.Jedis; + +/** + * RedisLock + */ +public class RedisLock { + private static final long DEFAULT_TIME_OUT = 180000; + private static final int EXPIRE = 10000; + private static final String LOCK_SUCCESS = "OK"; + private static final String SET_IF_NOT_EXIST = "NX"; + private static final String SET_WITH_EXPIRE_TIME = "PX"; + private static final String checkAndDelScript = "if redis.call('get', KEYS[1]) == ARGV[1] then " + + "return redis.call('del', KEYS[1]) " + + "else " + + "return 0 " + + "end"; + + private Jedis jedis; + private String key; + private String lock_value; + + /** + * This creates a RedisLock + * + * @param key key + * @param jedis + */ + public RedisLock(String key, Jedis jedis) { + this.key = key + "{lock}"; + this.jedis = jedis; + lock_value = UUID.randomUUID().toString()+Thread.currentThread().getId() + System.nanoTime(); + } + + /** + * lock(); try { doSomething(); } finally { unlock() } + */ + public boolean lock() { + long time = System.currentTimeMillis(); + try { + while ((System.currentTimeMillis() - time) < DEFAULT_TIME_OUT) { + String result = jedis.set(key, lock_value, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, EXPIRE); + if (LOCK_SUCCESS.equals(result)) { + return true; + } + Thread.sleep(5); + } + } catch (Exception e) { + throw new RuntimeException("Locking error", e); + } + return false; + } + + /** + * lock(); try { doSomething(); } finally { unlock() } + */ + public void unlock() { + unlock(true); + } + + /** + * lock(); try { doSomething(); } finally { unlock() } + */ + public void unlock(boolean closeJedis) { + try { + jedis.eval(checkAndDelScript, 1, key, lock_value); + } finally { + if (closeJedis) { + this.jedis.close(); + } + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisPlugin.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisPlugin.java new file mode 100644 index 0000000..ed30d09 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/plugin/redis/RedisPlugin.java @@ -0,0 +1,141 @@ +package com.taurus.core.plugin.redis; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.jdom.Element; + +import com.taurus.core.plugin.IPlugin; +import com.taurus.core.plugin.redis.RedisPlugin.RedisConfig.InfoConfig; +import com.taurus.core.util.StringUtil; + +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +/** + * RedisPlugin. + * RedisPlugin 支持多个 Redis 服务端,只需要创建多个 RedisPlugin 对象 + * 对应这多个不同的 Redis 服务端即可。也支持多个 RedisPlugin 对象对应同一 + */ +public class RedisPlugin implements IPlugin{ + private static final int TIMEOUT = 5000; + private String id; + private final RedisConfig config; + + + + public RedisPlugin() { + config = new RedisConfig(); + } + + public boolean start() { + JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + jedisPoolConfig.setMaxTotal(config.poolConfig.maxTotal); + jedisPoolConfig.setMaxIdle(config.poolConfig.maxIdle); + jedisPoolConfig.setMaxIdle(config.poolConfig.minIdle); + jedisPoolConfig.setMaxWaitMillis(config.poolConfig.maxWaitMillis); + jedisPoolConfig.setTestOnBorrow(config.poolConfig.testOnBorrow); + jedisPoolConfig.setTestOnReturn(config.poolConfig.testOnReturn); + jedisPoolConfig.setTestWhileIdle(config.poolConfig.testWhileIdle); + jedisPoolConfig.setNumTestsPerEvictionRun(config.poolConfig.numTestsPerEvictionRun); + jedisPoolConfig.setMinEvictableIdleTimeMillis(config.poolConfig.minEvictableIdleTimeMillis); + jedisPoolConfig.setTimeBetweenEvictionRunsMillis(config.poolConfig.timeBetweenEvictionRunsMillis); + jedisPoolConfig.setSoftMinEvictableIdleTimeMillis(config.poolConfig.softMinEvictableIdleTimeMillis); + jedisPoolConfig.setBlockWhenExhausted(config.poolConfig.blockWhenExhausted); + + for (InfoConfig sis : config.infos) { + String passwd = StringUtil.isEmpty(sis.password) ? null : sis.password; + JedisPool jedisPool = new JedisPool(jedisPoolConfig, sis.host, sis.port, TIMEOUT, passwd, sis.database); + Cache cache = new Cache(sis.name, jedisPool); + Redis.addCache(cache); + } + return true; + } + + public boolean stop() { + Set keys = Redis.cacheMap.keySet(); + for(String key : keys) { + Redis.removeCache(key); + } + return true; + } + + + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + @Override + public boolean loadConfig(Element element) { + Element pcEm = element.getChild("poolConfig"); + this.config.poolConfig.maxTotal = Integer.parseInt(pcEm.getChild("maxTotal").getTextTrim()); + this.config.poolConfig.maxIdle = Integer.parseInt(pcEm.getChild("maxIdle").getTextTrim()); + this.config.poolConfig.minIdle = Integer.parseInt(pcEm.getChild("minIdle").getTextTrim()); + this.config.poolConfig.maxWaitMillis = Integer.parseInt(pcEm.getChild("maxWaitMillis").getTextTrim()); + this.config.poolConfig.testOnBorrow = Boolean.parseBoolean(pcEm.getChild("testOnBorrow").getTextTrim()); + this.config.poolConfig.testOnReturn = Boolean.parseBoolean(pcEm.getChild("testOnReturn").getTextTrim()); + this.config.poolConfig.testWhileIdle = Boolean.parseBoolean(pcEm.getChild("testWhileIdle").getTextTrim()); + this.config.poolConfig.numTestsPerEvictionRun = Integer.parseInt(pcEm.getChild("numTestsPerEvictionRun").getTextTrim()); + this.config.poolConfig.minEvictableIdleTimeMillis = Integer.parseInt(pcEm.getChild("minEvictableIdleTimeMillis").getTextTrim()); + this.config.poolConfig.timeBetweenEvictionRunsMillis = Integer.parseInt(pcEm.getChild("timeBetweenEvictionRunsMillis").getTextTrim()); + this.config.poolConfig.softMinEvictableIdleTimeMillis = Integer.parseInt(pcEm.getChild("softMinEvictableIdleTimeMillis").getTextTrim()); + this.config.poolConfig.blockWhenExhausted = Boolean.parseBoolean(pcEm.getChild("blockWhenExhausted").getTextTrim()); + + Element dblistEm = element.getChild("infos"); + + Iterator itr = (dblistEm.getChildren()).iterator(); + while(itr.hasNext()) { + Element infoEm = (Element)itr.next(); + InfoConfig infoConfig = new InfoConfig(); + infoConfig.name = infoEm.getAttributeValue("name", StringUtil.Empty); + infoConfig.host = infoEm.getAttributeValue("host", "127.0.0.1"); + infoConfig.port = Integer.parseInt(infoEm.getAttributeValue("port", "6379")); + infoConfig.database = Integer.parseInt(infoEm.getAttributeValue("database", "0")); + infoConfig.password = infoEm.getAttributeValue("password"); + this.config.infos.add(infoConfig); + } + return true; + } + + public static final class RedisConfig{ + + public volatile PoolConfig poolConfig = new PoolConfig(); + + public volatile List infos = new ArrayList(); + + + public static final class PoolConfig { + public int maxTotal = 8; + public int maxIdle = 8; + public int minIdle = 0; + public int maxWaitMillis = 8; + public boolean testOnBorrow = true; + public boolean testOnReturn = true; + public boolean testWhileIdle = true; + public int numTestsPerEvictionRun = 3; + public int minEvictableIdleTimeMillis = 6000; + public int timeBetweenEvictionRunsMillis = 3000; + public int softMinEvictableIdleTimeMillis = 1000; + public boolean blockWhenExhausted = true; + } + + public static final class InfoConfig { + public String name =""; + public String host = "127.0.0.1"; + public int port = 6379; + public String password = ""; + public int database = 0; + } + } +} + + diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Action.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Action.java new file mode 100644 index 0000000..2a306a5 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Action.java @@ -0,0 +1,68 @@ +package com.taurus.core.routes; + +import java.lang.reflect.Method; + +/** + * Action. + * + * + */ +public class Action { + private final Class controllerClass; + private final IController controller; + private final String controllerKey; + private final String actionKey; + private final Method method; + private final String methodName; + private final Interceptor interceptor; + private final ActionKey actionKeyObj; + + public Action(String controllerKey, String actionKey, Class ctrClass,IController controller, Method method, String methodName,Interceptor interceptor,ActionKey actionKeyObj) { + this.controllerKey = controllerKey; + this.controller = controller; + this.actionKey = actionKey; + this.controllerClass = ctrClass; + this.method = method; + this.methodName = methodName; + this.interceptor = interceptor; + this.actionKeyObj = actionKeyObj; + } + + public Class getControllerClass() { + return controllerClass; + } + + public IController getController() { + return controller; + } + + public String getControllerKey() { + return controllerKey; + } + + public String getActionKey() { + return actionKey; + } + + public Method getMethod() { + return method; + } + + + public String getMethodName() { + return methodName; + } + + public Interceptor getInterceptor() { + return interceptor; + } + + public ActionKey getActionKeyObj() { + return actionKeyObj; + } + + @Override + public String toString() { + return actionKey; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionKey.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionKey.java new file mode 100644 index 0000000..d3415ad --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionKey.java @@ -0,0 +1,23 @@ +package com.taurus.core.routes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * ActionKey is used to configure actionKey for method of controller. + */ +@Inherited +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ActionKey { + String value(); + + int validate() default 0; + + /**参数{"a","1","b","2"}*/ + String[] params() default {}; +} + diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionMapping.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionMapping.java new file mode 100644 index 0000000..3743634 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/ActionMapping.java @@ -0,0 +1,94 @@ +package com.taurus.core.routes; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.taurus.core.routes.Routes.Route; +import com.taurus.core.util.StringUtil; + +/** + * ActionMapping. + * + * + */ +public class ActionMapping { + protected static final String SLASH = "/"; + protected Routes routes; + protected Map mapping = new HashMap(2048, 0.5F); + + public ActionMapping(Routes routes) { + this.routes = routes; + } + + protected List getRoutesList() { + List routesList = Routes.getRoutesList(); + List ret = new ArrayList(routesList.size() + 1); + ret.add(routes); + ret.addAll(routesList); + return ret; + } + + public void buildActionMapping() { + mapping.clear(); + for (Routes routes : getRoutesList()) { + for (Route route : routes.getRouteItemList()) { + Class controllerClass = route.getControllerClass(); + + Method[] methods = controllerClass.getMethods(); + for (Method method : methods) { + String methodName = method.getName(); + if (!Modifier.isPublic(method.getModifiers())) + continue ; + ActionKey ak = method.getAnnotation(ActionKey.class); + if (ak == null)continue ; + String controllerKey = route.getControllerKey(); + String actionKey = ak.value().trim(); + if (StringUtil.isEmpty(actionKey)) + throw new IllegalArgumentException(controllerClass.getName() + "." + methodName + "(): The argument of ActionKey can not be blank."); + Interceptor interceptor = routes.getInterceptor(); + Action action = new Action(controllerKey, actionKey, route.getControllerClass(), + route.getController(),method, methodName,interceptor,ak); + if(!StringUtil.isEmpty(controllerKey)) { + actionKey =controllerKey.equals(SLASH) ? SLASH+ actionKey : (controllerKey + SLASH+actionKey); + } + if (mapping.put(actionKey, action) != null) { + throw new RuntimeException(buildMsg(actionKey, controllerClass, method)); + } + } + } + } + } + + protected String buildMsg(String actionKey, Class controllerClass, Method method) { + StringBuilder sb = new StringBuilder("The action \"") + .append(controllerClass.getName()).append(".") + .append(method.getName()).append("()\" can not be mapped, ") + .append("actionKey \"").append(actionKey).append("\" is already in use."); + + String msg = sb.toString(); + System.err.println("\nException: " + msg); + return msg; + } + + /** + * Support four types of url + */ + public Action getAction(String url) { + Action action = mapping.get(url); + if (action != null) { + return action; + } + return action; + } + + public List getAllActionKeys() { + List allActionKeys = new ArrayList(mapping.keySet()); + Collections.sort(allActionKeys); + return allActionKeys; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Extension.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Extension.java new file mode 100644 index 0000000..14084ae --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Extension.java @@ -0,0 +1,57 @@ +package com.taurus.core.routes; + +/** + * Extension class. + * + * + */ +public abstract class Extension { + private String name; + + /** + * Config route + */ + public abstract void configRoute(Routes me); + + /** + * Call back server start + */ + public void onStart() {} + + /** + * Call back server stop + */ + public void onStop() {} + + /** + * set extension name + * @param name + */ + public void setName(String name) { + this.name = name; + } + + /** + * read ver + * @return + */ + public int readVersion() { + return 0; + } + + /** + * get extension name + * @return + */ + public String getName() { + return this.name; + } + + /** + * get conncurrent number + * @return + */ + public int getConcurrentSize() { + return 0; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/IController.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/IController.java new file mode 100644 index 0000000..68590a5 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/IController.java @@ -0,0 +1,11 @@ +package com.taurus.core.routes; + + +/** + * Controller interface + * + * + */ +public interface IController { + +} \ No newline at end of file diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Interceptor.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Interceptor.java new file mode 100644 index 0000000..1792166 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Interceptor.java @@ -0,0 +1,10 @@ +package com.taurus.core.routes; + +/** + * Interceptor + * + * + */ +public interface Interceptor { + void intercept(Action action,IController controller,Object... args) throws Exception; +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Routes.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Routes.java new file mode 100644 index 0000000..24f0443 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/routes/Routes.java @@ -0,0 +1,155 @@ +package com.taurus.core.routes; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import com.taurus.core.util.StringUtil; + +/** + * Routes + * + * + */ +public abstract class Routes { + /**controller to class*/ + public static final int CONTROLLER_CLASS = 1; + /**controller to instance*/ + public static final int CONTROLLER_INSTANCE = 2; + private static List routesList = new ArrayList(); + private static Set controllerKeySet = new HashSet(); + + private List routeItemList = new ArrayList(); + private Interceptor interceptor; + private boolean addSlash = true; + + private int falg = CONTROLLER_CLASS; + + public Routes(int falg) { + this.falg = falg; + } + + /** + * Implement this method to add route, add interceptor and set baseViewPath + */ + public abstract void config(); + + /** + * 设置拦截器 + * @param interceptor + */ + public void setInterceptor(Interceptor interceptor) { + this.interceptor = interceptor; + } + + /** + * Add Routes + */ + public Routes add(Routes routes) { + routes.config(); + routesList.add(routes); + return this; + } + + /** + * Add route + * @param controllerKey A key can find controller + * @param controller Controller Class + */ + public Routes add(String controllerKey, Class controller) { + if((falg &CONTROLLER_CLASS) == 0) { + throw new RuntimeException("class is not supported!"); + } + routeItemList.add(new Route(controllerKey, controller,this.addSlash)); + return this; + } + + /** + * Add route + * @param controllerKey A key can find controller + * @param controller Controller instance + */ + public Routes add(String controllerKey, IController controller) { + if((falg &CONTROLLER_INSTANCE) == 0) { + throw new RuntimeException("instance is not supported!"); + } + routeItemList.add(new Route(controllerKey, controller,this.addSlash)); + return this; + } + + public static List getRoutesList() { + return routesList; + } + + public List getRouteItemList() { + return routeItemList; + } + + public Interceptor getInterceptor() { + return interceptor; + } + + public void setAddSlash(boolean add) { + this.addSlash =add; + } + + + public static class Route { + private String controllerKey; + private Class ctrClass; + private IController controller; + + public Route(String controllerKey, Class controller,boolean addSlash) { + if (StringUtil.isEmpty(controllerKey)) { + throw new IllegalArgumentException("controllerKey can not be blank"); + } + if (controller == null) { + throw new IllegalArgumentException("controllerClass can not be null"); + } + + this.controllerKey = processControllerKey(controllerKey,addSlash); + this.ctrClass = controller; + } + + public Route(String controllerKey, IController controller,boolean addSlash) { + if (controllerKey == null) { + throw new IllegalArgumentException("controllerKey can not be blank"); + } + if (controller == null) { + throw new IllegalArgumentException("controllerClass can not be null"); + } + + this.controllerKey = processControllerKey(controllerKey,addSlash); + this.controller = controller; + this.ctrClass = controller.getClass(); + } + + private String processControllerKey(String controllerKey,boolean addSlash) { + controllerKey = controllerKey.trim(); + if(addSlash) { + if (!controllerKey.startsWith("/")) { + controllerKey = "/" + controllerKey; + } + } + if (controllerKeySet.contains(controllerKey)) { + throw new IllegalArgumentException("controllerKey already exists: " + controllerKey); + } + controllerKeySet.add(controllerKey); + return controllerKey; + } + + public String getControllerKey() { + return controllerKey; + } + + public Class getControllerClass() { + return ctrClass; + } + + public IController getController() { + return controller; + } + + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/service/AbstractService.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/service/AbstractService.java new file mode 100644 index 0000000..8376864 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/service/AbstractService.java @@ -0,0 +1,48 @@ +package com.taurus.core.service; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * AbstractService + * + * + */ +public abstract class AbstractService implements IService { + private static final AtomicInteger serviceId = new AtomicInteger(0); + private static final String DEFAULT_NAME = "Service-"; + protected String name; + protected volatile boolean active = false; + + public void init(Object o) { + name = getServiceId(); + active = true; + } + + public void destroy(Object o) { + active = false; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void handleMessage(Object param) { + throw new UnsupportedOperationException("This method should be overridden by the child class!"); + } + + public boolean isActive() { + return active; + } + + public String toString() { + return "[Core Service]: " + name + ", State: " + (isActive() ? "active" : "not active"); + } + + protected static String getServiceId() { + return DEFAULT_NAME + serviceId.getAndIncrement(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/service/IService.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/service/IService.java new file mode 100644 index 0000000..8c12297 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/service/IService.java @@ -0,0 +1,39 @@ +package com.taurus.core.service; + +/** + * 通用服务接口 + * + * + */ +public interface IService { + + /** + * 初始化Service + * @param o + */ + public void init(Object o); + + /** + * 销毁Service + * @param o + */ + public void destroy(Object o); + + /** + * 获取Service名称 + * @return + */ + public String getName(); + + /** + * 设置Service名称 + * @param name + */ + public void setName(String name); + + /** + * Service是否激活 + * @return + */ + public boolean isActive(); +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Base64.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Base64.java new file mode 100644 index 0000000..9dc80fd --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Base64.java @@ -0,0 +1,239 @@ +package com.taurus.core.util; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +/** + * base64 + */ +public final class Base64 { + private static final char[] CA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); + private static final int[] IA = new int[256]; + + static { + Arrays.fill(IA, -1); + int i = 0; + for (int iS = CA.length; i < iS; i++) { + IA[CA[i]] = i; + } + IA[61] = 0; + } + + private static final char[] encodeToChar(byte[] sArr, boolean lineSep) { + int sLen = sArr != null ? sArr.length : 0; + if (sLen == 0) { + return new char[0]; + } + int eLen = sLen / 3 * 3; + int cCnt = (sLen - 1) / 3 + 1 << 2; + int dLen = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); + char[] dArr = new char[dLen]; + + int s = 0; + int d = 0; + for (int cc = 0; s < eLen;) { + int i = (sArr[(s++)] & 0xFF) << 16 | (sArr[(s++)] & 0xFF) << 8 | sArr[(s++)] & 0xFF; + + dArr[(d++)] = CA[(i >>> 18 & 0x3F)]; + dArr[(d++)] = CA[(i >>> 12 & 0x3F)]; + dArr[(d++)] = CA[(i >>> 6 & 0x3F)]; + dArr[(d++)] = CA[(i & 0x3F)]; + if (lineSep) { + cc++; + if ((cc == 19) && (d < dLen - 2)) { + dArr[(d++)] = '\r'; + dArr[(d++)] = '\n'; + cc = 0; + } + } + } + int left = sLen - eLen; + if (left > 0) { + int i = (sArr[eLen] & 0xFF) << 10 | (left == 2 ? (sArr[(sLen - 1)] & 0xFF) << 2 : 0); + + dArr[(dLen - 4)] = CA[(i >> 12)]; + dArr[(dLen - 3)] = CA[(i >>> 6 & 0x3F)]; + dArr[(dLen - 2)] = (left == 2 ? CA[(i & 0x3F)] : '='); + dArr[(dLen - 1)] = '='; + } + return dArr; + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + private static final String encodeToString(byte[] src, boolean lineSep) { + return new String(encodeToChar(src, lineSep)); + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + public static final byte[] encode(String src) { + try { + return StringUtil.getBytes(encodeToString(StringUtil.getBytes(src), false)); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + public static final byte[] encode(byte[] src) { + try { + return StringUtil.getBytes(encodeToString(src, false)); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + public static final String encodeToString(String src) { + try { + return encodeToString(StringUtil.getBytes(src), false); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Encodes all bytes from the specified byte array into a newly-allocated + * byte array using the {@link Base64} encoding scheme. The returned byte + * array is of the length of the resulting bytes. + * + * @param src the byte array to encode + * @return A newly-allocated byte array containing the resulting encoded bytes. + */ + public static final String encodeToString(byte[] src) { + return encodeToString(src, false); + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src the byte array to decode + * @return A newly-allocated byte array containing the decoded bytes. + */ + public static final String decodeToString(byte[] src) { + try { + return StringUtil.getString(decode(src)); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src the byte array to decode + * @return A newly-allocated byte array containing the decoded bytes. + */ + public static final String decodeToString(String src) { + try { + return StringUtil.getString(decode(src)); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src the byte array to decode + * @return A newly-allocated byte array containing the decoded bytes. + */ + public static final byte[] decode(byte[] src) { + try { + return decode(StringUtil.getString(src)); + } catch (UnsupportedEncodingException e) { + return null; + } + } + + /** + * Decodes all bytes from the input byte array using the {@link Base64} + * encoding scheme, writing the results into a newly-allocated output + * byte array. The returned byte array is of the length of the resulting + * bytes. + * + * @param src the byte array to decode + * @return A newly-allocated byte array containing the decoded bytes. + */ + public static final byte[] decode(String src) { + int sLen = src != null ? src.length() : 0; + if (sLen == 0) { + return new byte[0]; + } + int sepCnt = 0; + for (int i = 0; i < sLen; i++) { + if (IA[src.charAt(i)] < 0) { + sepCnt++; + } + } + if ((sLen - sepCnt) % 4 != 0) { + return null; + } + int pad = 0; + for (int i = sLen; (i > 1) && (IA[src.charAt(--i)] <= 0);) { + if (src.charAt(i) == '=') { + pad++; + } + } + int len = ((sLen - sepCnt) * 6 >> 3) - pad; + + byte[] dArr = new byte[len]; + + int s = 0; + for (int d = 0; d < len;) { + int i = 0; + for (int j = 0; j < 4; j++) { + int c = IA[src.charAt(s++)]; + if (c >= 0) { + i |= c << 18 - j * 6; + } else { + j--; + } + } + dArr[(d++)] = ((byte) (i >> 16)); + if (d < len) { + dArr[(d++)] = ((byte) (i >> 8)); + if (d < len) { + dArr[(d++)] = ((byte) i); + } + } + } + return dArr; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ByteArray.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ByteArray.java new file mode 100644 index 0000000..c74b8b9 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ByteArray.java @@ -0,0 +1,259 @@ +package com.taurus.core.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +/** + * byte array + * + */ +public class ByteArray { + private byte[] buffer; + private int _position; + private boolean compressed; + + public ByteArray() { + _position = 0; + buffer = new byte[0]; + } + + public ByteArray(byte[] buf) { + _position = 0; + buffer = buf; + } + + public byte[] reverseOrder(byte[] dt) { + return dt; + } + + public void writeByte(byte b) { + byte[] buf = new byte[1]; + buf[0] = b; + writeBytes(buf); + } + + public void writeBytes(byte[] data) { + writeBytes(data,0, data.length); + } + + public void writeBytes(byte[] data, int ofs,int count) { + byte[] dst = new byte[count + buffer.length]; + System.arraycopy(buffer, 0, dst, 0, buffer.length); + System.arraycopy(data, ofs, dst, buffer.length, count); + this.buffer = dst; + } + + public void writeBool(boolean b) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeByte(b ? 1 : 0); + writeBytes(bos.toByteArray()); + } + + public void writeInt(int i) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeInt(i); + writeBytes(reverseOrder(bos.toByteArray())); + } + + public void writeShort(short s) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeShort(s); + writeBytes(reverseOrder(bos.toByteArray())); + } + + public void writeUShort(int s) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + byte[] tem = new byte[2]; + int b1 = (s & 0xFF00) >> 8; + int b2 = s & 0xFF; + tem[0] = (byte)b1; + tem[1] = (byte)b2; + dos.writeByte((byte) b1); + dos.writeByte((byte) b2); + writeBytes(bos.toByteArray()); + } + + public void writeLong(long l) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeLong(l); + writeBytes(reverseOrder(bos.toByteArray())); + } + + public void writeFloat(float f) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeFloat(f); + writeBytes(reverseOrder(bos.toByteArray())); + } + + public void writeDouble(double d) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(bos); + dos.writeDouble(d); + writeBytes(reverseOrder(bos.toByteArray())); + } + + public void writeString(String str) throws IOException { + if(StringUtil.isEmpty(str)) { + writeInt(0); + return; + } + try { + byte[] bytes = StringUtil.getBytes(str); + int utfLen = bytes.length; + writeInt(utfLen); + writeBytes(bytes); + } catch (UnsupportedEncodingException e) { + throw new IOException("Error writing to data buffer"); + } + } + + public byte readByte() throws IOException { + return this.buffer[(this._position++)]; + } + + public byte[] readBytes(int count) { + byte[] res = new byte[count]; + ByteBuffer buf = ByteBuffer.wrap(this.buffer); + buf.position(this._position); + buf.get(res); + this._position += count; + return res; + } + + public boolean readBool() throws IOException { + return this.buffer[(this._position++)] == 1; + } + + public int readInt() throws IOException { + byte[] data = reverseOrder(readBytes(4)); + ByteArrayInputStream bis = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bis); + return dis.readInt(); + } + + public short readShort() throws IOException { + byte[] data = reverseOrder(readBytes(2)); + ByteArrayInputStream bis = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bis); + return dis.readShort(); + } + + public int readUShort() throws IOException { + byte[] data = reverseOrder(readBytes(2)); + + int ib1 = new Integer(data[0]).intValue(); + if (ib1 < 0) { + ib1 = data[0] & 0x80; + ib1 += (data[0] & 0x7F); + } + int ib2 = new Integer(data[1]).intValue(); + if (ib2 < 0) { + ib2 = data[1] & 0x80; + ib2 += (data[1] & 0x7F); + } + return ib1 * 256 + ib2; + } + + public long readLong() throws IOException { + byte[] data = reverseOrder(readBytes(8)); + ByteArrayInputStream bis = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bis); + return dis.readLong(); + } + + public float readFloat() throws IOException { + byte[] data = reverseOrder(readBytes(4)); + ByteArrayInputStream bis = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bis); + return dis.readFloat(); + + } + + public double readDouble() throws IOException { + byte[] data = reverseOrder(readBytes(8)); + ByteArrayInputStream bis = new ByteArrayInputStream(data); + DataInputStream dis = new DataInputStream(bis); + return dis.readDouble(); + } + + public String readString() throws IOException { + int size = readInt(); + if (size == 0) { + return null; + } + byte[] data = readBytes(size); + return StringUtil.getString(data); + } + + public byte[] bytes() { + return this.buffer; + } + + public ByteArray bytes(byte[] buffer) { + this.buffer = buffer; + return this; + } + + public int length() { + return this.buffer.length; + } + + public int position() { + return this._position; + } + + public ByteArray position(int position) { + this._position = position; + return this; + } + + public boolean isCompressed() { + return this.compressed; + } + + public void setCompressed(final boolean compressed) { + this.compressed = compressed; + } + + public void compress() throws Exception { + if (this.compressed) { + throw new Exception("Buffer is already compressed"); + } + try { + buffer = Utils.compress(this.buffer); + this._position = 0; + this.compressed = true; + }catch (IOException e) { + throw new Exception("Error compressing data"); + } + } + + public void uncompress() throws Exception { + try { + buffer = Utils.uncompress(this.buffer); + this._position = 0; + this.compressed = false; + }catch (IOException e2) { + throw new Exception("Error decompressing data"); + } + } + + public int bytesAvailable() { + int val = this.buffer.length - this._position; + if ((val > this.buffer.length) || (val < 0)) { + val = 0; + } + return val; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/DateUtils.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/DateUtils.java new file mode 100644 index 0000000..33e9769 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/DateUtils.java @@ -0,0 +1,191 @@ +package com.taurus.core.util; + +import java.util.Calendar; + +/** + * date util class + * + * + */ +public class DateUtils { + + /** + * 获取当天的开始时间 + * @param cal + */ + private static void setDayBegin(Calendar cal) { + cal.set(Calendar.HOUR_OF_DAY, 0); + cal.set(Calendar.MINUTE, 0); + cal.set(Calendar.SECOND, 0); + cal.set(Calendar.MILLISECOND, 0); + } + + /** + * 获取当天的结束时间 + * @param cal + */ + private static void setDayEnd(Calendar cal) { + cal.set(Calendar.HOUR_OF_DAY, 23); + cal.set(Calendar.MINUTE, 59); + cal.set(Calendar.SECOND, 59); + cal.set(Calendar.MILLISECOND, 999); + } + + private static int getTimeSec(Calendar cal) { + int timeSec = (int) (cal.getTimeInMillis() / 1000); + return timeSec; + } + + /** + * 今天开始时间 + * @return + */ + public static int getBeginDay() { + Calendar cal= Calendar.getInstance(); + setDayBegin(cal); + return getTimeSec(cal); + } + + /** + * 今天结束时间 + * @return + */ + public static int getEndDay() { + Calendar cal= Calendar.getInstance(); + setDayEnd(cal); + return getTimeSec(cal); + } + + + /** + * 获取昨天的开始时间 + * @return + */ + public static int getBeginLastday() { + return getBeginDay() - 24*60*60; + } + + /** + * 获取昨天的结束时间 + * @return + */ + public static int getEndLastDay() { + return getBeginDay()-1; + } + + /** + * 获取本周的开始时间 + * @return + */ + public static int getBeginWeek() { + Calendar cal = Calendar.getInstance(); + int dayofweek = cal.get(Calendar.DAY_OF_WEEK); + if (dayofweek == 1) { + dayofweek += 7; + } + cal.add(Calendar.DATE, 2 - dayofweek); + setDayBegin(cal); + return getTimeSec(cal); + } + + /** + * 获取本周的结束时间 + * @return + */ + public static int getEndWeek() { + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(getBeginWeek()*1000L); + cal.add(Calendar.DAY_OF_WEEK, 6); + setDayEnd(cal); + return getTimeSec(cal); + } + + /** + * 获取上周的开始时间 + * @return + */ + public static int getBeginLastWeek() { + Calendar cal = Calendar.getInstance(); + int dayofweek = cal.get(Calendar.DAY_OF_WEEK); + if (dayofweek == 1) { + dayofweek += 7; + } + cal.add(Calendar.DATE, 2 - dayofweek - 7); + setDayBegin(cal); + return getTimeSec(cal); + } + + /** + * 获取上周的结束时间 + * @return + */ + public static int getEndLastWeek() { + return getBeginWeek() -1 ; + } + + /** + * 获取本月的开始时间 + */ + public static int getBeginMonth() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, 0); + cal.set(Calendar.DAY_OF_MONTH, 1); + setDayBegin(cal); + return getTimeSec(cal); + } + + /** + * 获取本月的结束时间 + * @return + */ + public static int getEndMonth() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, 1); + cal.set(Calendar.DAY_OF_MONTH, 0); + setDayEnd(cal); + return getTimeSec(cal); + } + + /** + * 获取上月的开始时间 + */ + public static int getBeginLastMonth() { + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.MONTH, -1); + cal.set(Calendar.DAY_OF_MONTH, 1); + setDayBegin(cal); + return getTimeSec(cal); + } + + /** + * 获取上月的结束时间 + * @return + */ + public static int getEndLastMonth() { + return getBeginMonth() -1; + } + + /** + * 两个日期相减得到的天数 + * @param begin + * @param end + * @return + */ + public static int getDiffDays(int begin, int end) { + int diff = (end- begin) / (60 * 60 * 24); + return diff; + } + + /** + * 两个日期相减得到的毫秒数 + * @param begin + * @param end + * @return + */ + public static int dateDiff(int begin, int end) { + return end - begin; + } + + + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FileUtil.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FileUtil.java new file mode 100644 index 0000000..9e907ab --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FileUtil.java @@ -0,0 +1,89 @@ +package com.taurus.core.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +/** + * 文件处理工具 + * + * + * + */ +public class FileUtil { + + /** + * delete file + * @param file + */ + public static void delete(File file) { + if (file != null && file.exists()) { + if (file.isFile()) { + file.delete(); + } else if (file.isDirectory()) { + File files[] = file.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + delete(files[i]); + } + } + file.delete(); + } + } + } + + /** + * get file extension + * @param fileFullName + * @return + */ + public static String getFileExtension(String fileFullName) { + if (StringUtil.isEmpty(fileFullName)) { + throw new RuntimeException("fileFullName is empty"); + } + return getFileExtension(new File(fileFullName)); + } + + /** + * get file extension + * @param file + * @return + */ + public static String getFileExtension(File file) { + if (null == file) { + throw new NullPointerException(); + } + String fileName = file.getName(); + int dotIdx = fileName.lastIndexOf('.'); + return (dotIdx == -1) ? StringUtil.Empty : fileName.substring(dotIdx + 1); + } + + /** + * read utf text file + * @param path + * @return + * @throws Exception + */ + public static String readTxt(String path) throws Exception { + InputStream is = new FileInputStream(path); + byte[] bytes = new byte[is.available()]; + is.read(bytes); + is.close(); + String str = new String(bytes,StringUtil.UTF_8); + return str; + } + + /** + * read binary file + * @param path + * @return + * @throws Exception + */ + public static byte[] readBytes(String path) throws Exception { + InputStream is = new FileInputStream(path); + byte[] bytes = new byte[is.available()]; + is.read(bytes); + is.close(); + return bytes; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FixedIndexThreadPool.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FixedIndexThreadPool.java new file mode 100644 index 0000000..9b7726e --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/FixedIndexThreadPool.java @@ -0,0 +1,136 @@ +package com.taurus.core.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * fixed index thread pool class. + * + * + * + */ +public class FixedIndexThreadPool { + private int poolSize; + private String poolName; + private volatile boolean _run; + private List works; + + public FixedIndexThreadPool(int poolSize, String poolName, Class workClass) { + this.poolSize = poolSize; + this.poolName = poolName; + _run = true; + works = new ArrayList(); + try { + for (int i = 0; i < poolSize; ++i) { + Work work = workClass.newInstance(); + work.init(this, i); + works.add(work); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * execute task + * + * @param index + * @param task + */ + public void execute(int index, Object task) { + Work work = works.get(index % poolSize); + work.addTask(task); + } + + /** + * shut down all work + * + * @return + */ + public synchronized int shutdown() { + int count = 0; + this._run = false; + for (Work work : works) { + count += work.stop(); + } + return count; + } + + public boolean isRun() { + return _run; + } + + /** + * get thread pool name + * + * @return + */ + public String getPoolName() { + return poolName; + } + + /** + * Thread work class + */ + public static abstract class Work implements Runnable { + protected FixedIndexThreadPool pool; + protected Thread thread; + protected BlockingQueue taskQueue; + protected Logger log; + + public void init(FixedIndexThreadPool pool, int id) { + this.pool = pool; + this.thread = new Thread(this, pool.poolName + "-" + id); + this.thread.start(); + taskQueue = new LinkedBlockingQueue(); + log = Logger.getLogger(this.getClass()); + } + + /** + * 添加任务 + * @param task + */ + public void addTask(Object task) { + if (task != null) { + taskQueue.add(task); + } + } + + /** + * stop work + * @return + */ + public synchronized int stop() { + if (thread != null) { + thread.interrupt(); + thread = null; + } + return taskQueue.size(); + } + + /** + * 处理任务 + * @param task + * @throws Exception + */ + protected abstract void handlerTask(Object task) throws Exception; + + @Override + public void run() { + while (pool.isRun()) { + try { + Object task = taskQueue.take(); + if (task != null) { + handlerTask(task); + } + } catch (InterruptedException e) { + log.error(e); + } catch (Exception e) { + log.error(e); + } + } + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ICallback.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ICallback.java new file mode 100644 index 0000000..437c681 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/ICallback.java @@ -0,0 +1,13 @@ +package com.taurus.core.util; + +/** + * Callback 监听接口 + * + * + */ +public interface ICallback{ + + + public void action(T t); + +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Logger.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Logger.java new file mode 100644 index 0000000..1cf5873 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Logger.java @@ -0,0 +1,214 @@ +package com.taurus.core.util; + +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * Logger日志类 + * + * + * + */ +public class Logger { + private static final String NULL = ""; + private static final String ROOT_LOGGER_NAME = "ROOT"; + + private static Class _customClass; + private String _name = ROOT_LOGGER_NAME; + + /** + * 设置自定义Class + * + * @param className + */ + public static final void setCustomClass(Class customClass) { + _customClass = customClass; + } + + public static final Logger getLogger(Class log_class) { + Logger logger = null; + if (_customClass != null) { + if (Logger.class.isAssignableFrom(_customClass)) { + try { + Constructor c1 = _customClass.getDeclaredConstructor(new Class[] { Class.class }); + c1.setAccessible(true); + logger = (Logger) c1.newInstance(log_class); + return logger; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + try { + Class.forName("org.apache.log4j.Logger"); + logger = new Log4j(log_class); + return logger; + } catch (ClassNotFoundException e) { + // e.printStackTrace(); + } + logger = new Logger(log_class); + return logger; + } + + public static final Logger getLogger(String name) { + Logger logger = null; + if (_customClass != null) { + if (Logger.class.isAssignableFrom(_customClass)) { + try { + Constructor c1 = _customClass.getDeclaredConstructor(new Class[] { Class.class }); + c1.setAccessible(true); + logger = (Logger) c1.newInstance(name); + return logger; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + try { + Class.forName("org.apache.log4j.Logger"); + logger = new Log4j(name); + return logger; + } catch (ClassNotFoundException e) { + // e.printStackTrace(); + } + logger = new Logger(name); + return logger; + } + + protected Logger(Class log_class) { + _name = log_class == null ? ROOT_LOGGER_NAME : log_class.getSimpleName(); + } + + protected Logger(String name) { + _name = name; + } + + public String getName() { + return _name; + } + + private void printThrowable(PrintStream print, Throwable throwable) { + print.println(throwable); + StackTraceElement[] trace = throwable.getStackTrace(); + for (StackTraceElement traceElement : trace) + print.println("\tat " + traceElement); + } + + protected void print(LoggerLevel level, Object msg, Throwable throwable) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + String date = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(calendar.getTime()); + msg = StringUtil.isEmpty(msg.toString()) ? NULL : msg; + msg = String.format("%s %-5s [%s] %s -%s", date, level.name(), Thread.currentThread().getName(), _name, msg); + System.out.println(msg); + if (throwable != null) { + printThrowable(System.out, throwable); + } + } + + public void trace(Object msg) { + print(LoggerLevel.TRACE, msg, null); + } + + public void trace(Object msg, Object... params) { + String str = String.format(msg.toString(), params); + trace(str); + } + + public void debug(Object msg) { + print(LoggerLevel.DEBUG, msg, null); + } + + public void debug(Object msg, Object... params) { + String str = String.format(msg.toString(), params); + debug(str); + } + + public void info(Object msg) { + print(LoggerLevel.INFO, msg, null); + } + + public void info(Object msg, Object... params) { + String str = String.format(msg.toString(), params); + info(str); + } + + public void warn(Object msg) { + print(LoggerLevel.WARN, msg, null); + } + + public void warn(Object msg, Object... params) { + String str = String.format(msg.toString(), params); + warn(str); + } + + public void error(Object msg) { + print(LoggerLevel.ERROR, msg, null); + } + + public void error(Object msg, Object... params) { + String str = String.format(msg.toString(), params); + error(str); + } + + public void error(Throwable throwable) { + error(NULL, throwable); + } + + public void error(Object msg, Throwable throwable) { + print(LoggerLevel.ERROR, msg, throwable); + } + + /** + * 日志等级 + * + * + * + */ + public static enum LoggerLevel { + DEBUG, INFO, WARN, ERROR, TRACE + } + + /** + * log4j 扩展 + * + * + */ + public static final class Log4j extends Logger { + private org.apache.log4j.Logger logger; + + protected Log4j(Class log_class) { + super(log_class); + logger = org.apache.log4j.Logger.getLogger(log_class); + } + + protected Log4j(String name) { + super(name); + logger = org.apache.log4j.Logger.getLogger(name); + } + + @Override + protected void print(LoggerLevel level, Object msg, Throwable throwable) { + switch (level) { + case DEBUG: + logger.debug(msg); + break; + case ERROR: + logger.error(msg, throwable); + break; + case WARN: + logger.warn(msg); + break; + case TRACE: + logger.trace(msg); + break; + case INFO: + logger.info(msg); + break; + } + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/MD5.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/MD5.java new file mode 100644 index 0000000..4975b04 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/MD5.java @@ -0,0 +1,48 @@ +package com.taurus.core.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * md5 + */ +public final class MD5 { + private static MD5 _instance = new MD5(); + private MessageDigest messageDigest; + private final Logger log; + + private MD5() { + this.log = Logger.getLogger(getClass()); + try { + this.messageDigest = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + this.log.error("Could not instantiate the MD5 Message Digest!"); + } + } + + public static MD5 getInstance() { + return _instance; + } + + public synchronized String getHash(String s) { + byte[] data = s.getBytes(); + + this.messageDigest.update(data); + + return toHexString(this.messageDigest.digest()); + } + + private String toHexString(byte[] byteData) { + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < byteData.length; i++) { + String hex = Integer.toHexString(byteData[i] & 0xFF); + if (hex.length() == 1) { + hex = "0" + hex; + } + sb.append(hex); + } + + return sb.toString(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/SHA1.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/SHA1.java new file mode 100644 index 0000000..dcafcff --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/SHA1.java @@ -0,0 +1,54 @@ +package com.taurus.core.util; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * sha1 + */ +public final class SHA1 { + private static SHA1 _instance = new SHA1(); + private MessageDigest messageDigest; + private final Logger log; + + private SHA1() { + this.log = Logger.getLogger(getClass()); + try { + this.messageDigest = MessageDigest.getInstance("SHA-1"); + } catch (NoSuchAlgorithmException e) { + this.log.error("Could not instantiate the SHA-1 Message Digest!"); + } + } + + public static SHA1 getInstance() { + return _instance; + } + + public synchronized String getHash(String s) { + byte[] data = s.getBytes(); + this.messageDigest.update(data); + + return toHexString(this.messageDigest.digest()); + } + + public synchronized String getBase64Hash(String s) { + byte[] data = s.getBytes(); + this.messageDigest.update(data); + + return Base64.encodeToString(this.messageDigest.digest()); + } + + private String toHexString(byte[] byteData) { + StringBuffer sb = new StringBuffer(); + + for (int i = 0; i < byteData.length; i++) { + String hex = Integer.toHexString(byteData[i] & 0xFF); + if (hex.length() == 1) { + hex = "0" + hex; + } + sb.append(hex); + } + + return sb.toString(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/StringUtil.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/StringUtil.java new file mode 100644 index 0000000..d9318da --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/StringUtil.java @@ -0,0 +1,233 @@ +package com.taurus.core.util; + +import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * string tools + * + */ +public class StringUtil { + + public static final String UTF_8 = "UTF-8"; + /** + * 空字符 + */ + public static final String Empty = ""; + + private static final String EMOJI_FILTER ="[\ud800\udc00-\udbff\udfff\ud800-\udfff]"; + /** + * 流数据转换为字符串 UTF-8 + * @param bytes + * @return + * @throws UnsupportedEncodingException + */ + public static String getString(byte[] bytes) throws UnsupportedEncodingException { + return new String(bytes,UTF_8); + } + + public static byte[] getBytes(String str) throws UnsupportedEncodingException { + return str==null?null:str.getBytes(UTF_8); + } + + /** + * 获得非空 + * @param str + * @return + */ + public static String getStr(String str) { + if (isEmpty(str)) return StringUtil.Empty; + return str; + } + + /** + * + * @param str + * @return + */ + public static int getBytesLength(String str) { + if (isEmpty(str)) { + return 0; + } + return str.getBytes().length; + } + + /** + * 字符串是否为空 + * @param str + * @return + */ + public static boolean isEmpty(String str) { + if (str == null) { + return true; + } + int len = str.length(); + if (len == 0) { + return true; + } + for (int i = 0; i < len; i++) { + switch (str.charAt(i)) { + case ' ': + case '\t': + case '\n': + case '\r': + break; + default: + return false; + } + } + return false; + } + + /** + * 字符串不为空 + * @param str + * @return + */ + public static boolean isNotEmpty(String str) { + return !isEmpty(str); + } + + private static final String DEFAULT_STR = "?"; + /** + * 将emoji表情替换成空串 + * + * @param source + * @return 过滤后的字符串 + */ + public static String filterEmoji(String source) { + if(StringUtil.isEmpty(source)) { + return DEFAULT_STR; + } + source = source.replaceAll(EMOJI_FILTER, StringUtil.Empty); + if(StringUtil.isEmpty(source)) { + return DEFAULT_STR; + } + return source; + } + + /** + * 首字母大写 + * @param str + * @return + */ + public static String capitalize(final String str) { + final int strLen; + if (str == null || (strLen = str.length()) == 0) { + return str; + } + return new StringBuffer(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1)).toString(); + } + + /** + * 首字母小写 + * @param str + * @return + */ + public static String uncapitalize(final String str) { + final int strLen; + if (str == null || (strLen = str.length()) == 0) { + return str; + } + return new StringBuffer(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1)).toString(); + } + + public static String getCurrentTime() { + SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd"); + String time = f.format(new Date()); + return time; + } + + public static Object removeEndChar(String object, String cha) { + while ((isNotEmpty(object)) && (object.endsWith(cha))) { + object = object.substring(0, object.length() - 1); + } + return object; + } + + /** + * 获取正则表达式转换后的字符串 + * @param str + * @param regex 正则表达式 + * @return + */ + public static String getRegexStr(String str, String regex) { + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(str); + if (m.find()) { + return m.group(1); + } + + return null; + } + + /** + * 获取正则表达式转换后的字符串数组 + * @param str + * @param regex 正则表达式 + * @return + */ + public static List getRegexStrs(String str, String regex) { + List list = new ArrayList(); + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(str); + while (m.find()) { + list.add(m.group(1)); + } + return list; + } + + /** + * 获取MD5字符串 + * @param str + * @return + */ + public static String getMD5(String str) { + String result = MD5.getInstance().getHash(str); + return result; + } + + public static boolean isInteger(String str, Integer big, Integer small) { + boolean returnb; + if (isNotEmpty(str)) { + try { + int intStr = Integer.parseInt(str); + if ((big.intValue() == 0) && (small.intValue() == 0)) { + returnb = true; + } else if ((intStr <= big.intValue()) && (intStr >= small.intValue())) { + returnb = true; + } else { + returnb = false; + } + } catch (Exception e) { + returnb = false; + } + } else { + returnb = false; + } + + return returnb; + } + + /** + * 判断字符串是否是电话号码 + * @param telephone + * @return + */ + public static boolean isPhone(String telephone) { + boolean b; + if (isEmpty(telephone)) { + b = false; + } else { + Pattern p = Pattern.compile("^[1]([3|5|4|7|8][0-9]{1})[0-9]{8}$"); + Matcher m = p.matcher(telephone); + b = m.matches(); + } + return b; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Utils.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Utils.java new file mode 100644 index 0000000..50c7a13 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/Utils.java @@ -0,0 +1,313 @@ +package com.taurus.core.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; + +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TArray; +import com.taurus.core.entity.TDataType; +import com.taurus.core.entity.TDataWrapper; +import com.taurus.core.entity.TObject; + +import java.util.Map.Entry; + +/** + * 工具类 + * + */ +public final class Utils { + private static final String DELIMITER = "__"; + private static final String BUFFER_TYPE_DIRCT = "DIRECT"; + private static final String BUFFER_TYPE_HEAP = "HEAP"; + public static final Random rand = new Random(); + static { + rand.setSeed(System.currentTimeMillis()); + } + + /** + * 重置byte数组大小 + * @param source + * @param pos + * @param size + * @return + */ + public static byte[] resizeByteArray(byte[] source, int pos, int size) { + byte[] tTArray = new byte[size]; + System.arraycopy(source, pos, tTArray, 0, size); + return tTArray; + } + + public static ITObject bytesToJson(byte[] bytes) throws IOException { + if (bytes == null) + return null; + String json = uncompressString(bytes); + ITObject p = TObject.newFromJsonData(json); + return p; + } + + public static byte[] jsonToBytes(ITObject json) throws IOException { + if (json != null) { + return compress(StringUtil.getBytes(json.toJson())); + } + return null; + } + + /** + * 将密码字符串转换为MD5 + * @param session + * @param clearPass + * @return + */ + public static String getClientPassword(String hashId, String clearPass) { + return MD5.getInstance().getHash(hashId + clearPass); + } + + /** + * 获取字符串转换为MD5 + * @param str + * @return + */ + public static String getMD5Hash(String str) { + return MD5.getInstance().getHash(str); + } + + /** + * 生成session hash key + * @param fullIpAddress + * @return + */ + public static String getUniqueSessionToken(String fullIpAddress) { + String key = fullIpAddress + DELIMITER + String.valueOf(rand.nextInt()) + System.currentTimeMillis(); + + return MD5.getInstance().getHash(key); + } + + /** + * 获取十六进制文件名 + * @param name + * @return + */ + public static String getHexFileName(String name) { + StringBuilder sb = new StringBuilder(); + char[] c = name.toCharArray(); + for (int i = 0; i < c.length; i++) { + sb.append(Integer.toHexString(c[i])); + } + + return sb.toString(); + } + + /** + * 根据类型创建ByteBuffer + * @param size + * @param type + * @return + */ + public static ByteBuffer allocateBuffer(int size, String type) { + ByteBuffer bb = null; + if (type.equalsIgnoreCase(BUFFER_TYPE_DIRCT)) { + bb = ByteBuffer.allocateDirect(size); + } else if (type.equalsIgnoreCase(BUFFER_TYPE_HEAP)) { + bb = ByteBuffer.allocate(size); + } + return bb; + } + + + /** + * ITArray 深拷贝 + * @param from + * @param to + */ + public static final void arrayCopyDeep(ITArray from, ITArray to) { + for (Iterator it = from.iterator(); it.hasNext();) { + TDataWrapper value = (TDataWrapper) it.next(); + if (value.getTypeId() == TDataType.TOBJECT) { + ITObject obj = TObject.newInstance(); + to.addTObject(obj); + objectCopyDeep((ITObject) value.getObject(),obj); + } else if (value.getTypeId() == TDataType.TARRAY) { + ITArray arr = TArray.newInstance(); + to.addTArray(arr); + arrayCopyDeep((ITArray) value.getObject(),arr); + } else { + TDataWrapper v = new TDataWrapper(value.getTypeId(), value.getObject()); + to.add(v); + } + } + } + + /** + * TObject 深拷贝 + * + * @param from + * @param to + */ + public static final void objectCopyDeep(ITObject from, ITObject to) { + for (Iterator> it = from.iterator(); it.hasNext();) { + Entry entry = it.next(); + String key = (String) entry.getKey(); + TDataWrapper value = (TDataWrapper) entry.getValue(); + if (value.getTypeId() == TDataType.TOBJECT) { + ITObject obj = TObject.newInstance(); + to.putTObject(key, obj); + objectCopyDeep((ITObject) value.getObject(),obj); + } else if (value.getTypeId() == TDataType.TARRAY) { + ITArray arr = TArray.newInstance(); + to.putTArray(key, arr); + arrayCopyDeep((ITArray) value.getObject(),arr); + } else { + TDataWrapper v = new TDataWrapper(value.getTypeId(), value.getObject()); + to.put(key, v); + } + } + } + + /** + * TArray copy + * @param from + * @param to + */ + public static final void arrayCopy(ITArray from,ITArray to) { + for (Iterator it = from.iterator(); it.hasNext();) { + TDataWrapper value = (TDataWrapper) it.next(); + to.add(value); + } + } + + /** + * TObject copy + * @param from + * @param to + */ + public static final void objectCopy(ITObject from,ITObject to) { + for (Iterator> it = from.iterator(); it.hasNext();) { + Entry entry = it.next(); + String key = (String) entry.getKey(); + TDataWrapper value = (TDataWrapper) entry.getValue(); + to.put(key, value); + } + } + + /** + * TObject to {@code Map} + * @param from + * @param map + */ + public static final void objectToMap(ITObject from,Map map) { + for (Iterator> it = from.iterator(); it.hasNext();) { + Entry entry = it.next(); + String key = (String) entry.getKey(); + TDataWrapper value = (TDataWrapper) entry.getValue(); + if (value.getTypeId() == TDataType.TOBJECT || value.getTypeId() == TDataType.TARRAY) { + map.put(key, ((ITObject) value.getObject()).toJson()); + }else { + map.put(key, value.getObject().toString()); + } + } + } + + /** + * list to TArray + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (Integer card : list) { + result.addInt(card); + } + return result; + } + + /** + * 压缩字节数组 + * @param data + * @return + * @throws IOException + */ + public static byte[] compress(byte[] data) throws IOException{ + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + compress(data,bos); + byte[] output = bos.toByteArray(); + return output; + }finally { + bos.close(); + } + } + + /** + * 压缩 字节数组到输出流 + * @param data + * @param os + * @throws IOException + */ + public static void compress(byte[] data, OutputStream os) throws IOException { + Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, false); + DeflaterOutputStream dos = new DeflaterOutputStream(os,deflater); + dos.write(data, 0, data.length); + dos.finish(); + dos.flush(); + } + + /** + * 解压缩 字节数组 + * @param data + * @return + * @throws IOException + */ + public static String uncompressString(byte[] data) throws IOException { + byte[] output = uncompress(data); + String str= StringUtil.getString(output); + return str; + } + + /** + * 解压缩 字节数组 + * @param data + * @return + * @throws IOException + */ + public static byte[] uncompress(byte[] data) throws IOException { + ByteArrayInputStream bis = new ByteArrayInputStream(data); + try { + byte[] output =uncompress(bis); + return output; + }finally { + bis.close(); + } + } + + /** + * 解压缩 输入流 到字节数组 + * @param is + * @return + * @throws IOException + */ + public static byte[] uncompress(InputStream is) throws IOException { + Inflater decompresser = new Inflater(false); + InflaterInputStream iis = new InflaterInputStream(is,decompresser); + ByteArrayOutputStream o = new ByteArrayOutputStream(1024); + int i = 1024; + byte[] buf = new byte[i]; + + while ((i = iis.read(buf, 0, i)) > 0) { + o.write(buf, 0, i); + } + return o.toByteArray(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONParser.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONParser.java new file mode 100644 index 0000000..f96d6d5 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONParser.java @@ -0,0 +1,370 @@ +package com.taurus.core.util.json; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class JSONParser { + + private String text; + private int index = 0; + private char ch; + + private Token token; + private String stringValue; + private long longValue; + private double doubleValue; + + public JSONParser(String text){ + this.text = text; + ch = text.charAt(0); + nextToken(); + } + + public Object parse() { + if (token == Token.LBRACE) { + return parseMap(); + } + + if (token == Token.INT) { + Object value; + if (this.longValue >= Integer.MIN_VALUE && this.longValue <= Integer.MAX_VALUE) { + value = (int) this.longValue; + } else { + value = this.longValue; + } + + nextToken(); + return value; + } + + if (token == Token.DOUBLE) { + Object value = this.doubleValue; + nextToken(); + return value; + } + + if (token == Token.STRING) { + Object value = this.stringValue; + nextToken(); + return value; + } + + if (token == Token.LBRACKET) { + return parseArray(); + } + + if (token == Token.TRUE) { + nextToken(); + return true; + } + + if (token == Token.FALSE) { + nextToken(); + return false; + } + + if (token == Token.NULL) { + nextToken(); + return null; + } + + throw new IllegalArgumentException("illegal token : " + token); + } + + public List parseArray() { + accept(Token.LBRACKET); + ArrayList list = new ArrayList(); + + for (;;) { + if (token == Token.RBRACKET) { + break; + } + + if (token == Token.COMMA) { + nextToken(); + continue; + } + + Object item = parse(); + list.add(item); + } + + accept(Token.RBRACKET); + return list; + } + + public Map parseMap() { + accept(Token.LBRACE); + Map map = new LinkedHashMap(); + + for (;;) { + if (token == Token.RBRACE) { + break; + } + + if (token == Token.COMMA) { + nextToken(); + continue; + } + + String key; + { + if (token != Token.STRING) { + throw new IllegalArgumentException("illegal json, " + token + " : " + text); + } + key = this.stringValue; + nextToken(); + } + + accept(Token.COLON); + + Object value = parse(); + + map.put(key, value); + } + + accept(Token.RBRACE); + return map; + } + + void accept(Token token) { + if (this.token == token) { + nextToken(); + return; + } + + throw new IllegalArgumentException("illegal token : " + this.token + ", expect " + token); + } + private final static boolean[] whitespaceFlags = new boolean[256]; + static { + for (int i = 0; i <= 32; ++i) { + whitespaceFlags[i] = true; + } + + whitespaceFlags[0x1A] = false; + for (int i = 0x7F; i <= 0xA0; ++i) { + whitespaceFlags[i] = true; + } + + whitespaceFlags[160] = true; // 特别处理 + } + public static boolean isWhitespace(char c) { + return (c <= whitespaceFlags.length && whitespaceFlags[c]) // + || c == ' '; // Chinese space + } + + final void nextToken() { + if (index == Integer.MIN_VALUE) { + token = Token.EOF; + return; + } + + for (;;) { + if (isWhitespace(ch)) { + nextChar(); + continue; + } + + if (index >= text.length()) { + token = Token.EOF; + return; + } + + break; + } + + switch (ch) { + case '{': + token = Token.LBRACE; + nextChar(); + break; + case '}': + token = Token.RBRACE; + nextChar(); + break; + case '[': + token = Token.LBRACKET; + nextChar(); + break; + case ']': + token = Token.RBRACKET; + nextChar(); + break; + case ',': + token = Token.COMMA; + nextChar(); + break; + case ':': + token = Token.COLON; + nextChar(); + break; + case '"': + scanString(); + break; + default: + if (isDigit(ch) || ch == '-') { + scanDigit(); + return; + } + + if (text.startsWith("null", index)) { + token = Token.NULL; + index += 3; + nextChar(); + return; + } + + if (text.startsWith("true", index)) { + token = Token.TRUE; + index += 3; + nextChar(); + return; + } + + if (text.startsWith("false", index)) { + token = Token.FALSE; + index += 4; + nextChar(); + return; + } + throw new IllegalArgumentException("illegal json char : " + ch); + } + } + + private void scanDigit() { + boolean isNegate = false; + if (ch == '-') { + isNegate = true; + nextChar(); + } + + int dotCount = 0; + StringBuilder digitBuf = new StringBuilder(); + for (;;) { + digitBuf.append(ch); + nextChar(); + + if (ch == '.') { + dotCount++; + digitBuf.append('.'); + nextChar(); + continue; + } + + if (!isDigit(ch)) { + break; + } + } + + if (dotCount == 0) { + long longValue = Long.parseLong(digitBuf.toString()); + if (isNegate) { + longValue = -longValue; + } + this.longValue = longValue; + token = Token.INT; + } else { + double doubleValue = Double.parseDouble(digitBuf.toString()); + if (isNegate) { + doubleValue = -doubleValue; + } + this.doubleValue = doubleValue; + token = Token.DOUBLE; + } + } + + private void scanString() { + nextChar(); + StringBuilder strBuf = new StringBuilder(); + for (;;) { + if (index >= text.length()) { + throw new IllegalArgumentException("illegal string : " + strBuf); + } + if (ch == '"') { + nextChar(); + break; + } + + if (ch == '\\') { + nextChar(); + if (ch == '"' || ch == '\\' || ch == '/') { + strBuf.append(ch); + } else if (ch == 'n') { + strBuf.append('\n'); + } else if (ch == 'r') { + strBuf.append('\r'); + } else if (ch == 'b') { + strBuf.append('\b'); + } else if (ch == 'f') { + strBuf.append('\f'); + } else if (ch == 't') { + strBuf.append('\t'); + } else if (ch == 'u') { + nextChar(); + char c1 = ch; + nextChar(); + char c2 = ch; + nextChar(); + char c3 = ch; + nextChar(); + char c4 = ch; + int val = Integer.parseInt(new String(new char[] { c1, c2, c3, c4 }), 16); + strBuf.append((char) val); + } else { + throw new IllegalArgumentException("illegal string : " + strBuf); + } + } else { + strBuf.append(ch); + } + nextChar(); + } + stringValue = strBuf.toString(); + token = Token.STRING; + } + + static boolean isDigit(char ch) { + return ch >= '0' && ch <= '9'; + } + + void nextChar() { + ++index; + if (index >= text.length()) { + index = Integer.MIN_VALUE; + return; + } + + ch = text.charAt(index); + } + + enum Token { + INT, // + DOUBLE, // + STRING, // + BOOLEAN, // + TRUE, // + FALSE, // + NULL, // + EOF, // + + LBRACE("{"), // + RBRACE("}"), // + LBRACKET("["), // + RBRACKET("]"), // + COMMA(","), // + COLON(":"), + + ; + + public final String name; + + Token(){ + this(null); + } + + Token(String name){ + this.name = name; + } + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONUtils.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONUtils.java new file mode 100644 index 0000000..70a8c32 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONUtils.java @@ -0,0 +1,15 @@ +package com.taurus.core.util.json; + +public class JSONUtils { + + public static String toJSONString(Object o) { + JSONWriter writer = new JSONWriter(); + writer.writeObject(o); + return writer.toString(); + } + + public static Object parse(String text) { + JSONParser parser = new JSONParser(text); + return parser.parse(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONWriter.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONWriter.java new file mode 100644 index 0000000..50d578b --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/json/JSONWriter.java @@ -0,0 +1,314 @@ + +package com.taurus.core.util.json; + + +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.TabularData; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.Map; + +public class JSONWriter { + + private StringBuilder out; + + + + public JSONWriter(){ + this.out = new StringBuilder(); + } + + public void writeArrayStart() { + write('['); + } + + public void writeComma() { + write(','); + } + + public void writeArrayEnd() { + write(']'); + } + + public void writeNull() { + write("null"); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void writeObject(Object o) { + if (o == null) { + writeNull(); + return; + } + + if (o instanceof String) { + writeString((String) o); + return; + } + + if (o instanceof Number) { + write(o.toString()); + return; + } + + if (o instanceof Boolean) { + write(o.toString()); + return; + } + + if (o instanceof Date) { + writeDate((Date) o); + return; + } + + if (o instanceof Collection) { + writeArray((Collection) o); + return; + } + + if (o instanceof Throwable) { + writeError((Throwable) o); + return; + } + + if (o instanceof int[]) { + int[] array = (int[]) o; + write('['); + for (int i = 0; i < array.length; ++i) { + if (i != 0) { + write(','); + } + write(array[i]); + } + write(']'); + return; + } + + if (o instanceof long[]) { + long[] array = (long[]) o; + write('['); + for (int i = 0; i < array.length; ++i) { + if (i != 0) { + write(','); + } + write(array[i]); + } + write(']'); + return; + } + + if (o instanceof TabularData) { + writeTabularData((TabularData) o); + return; + } + + if (o instanceof CompositeData) { + writeCompositeData((CompositeData) o); + return; + } + + if (o instanceof Map) { + writeMap((Map) o); + return; + } + + throw new IllegalArgumentException("not support type : " + o.getClass()); + } + + public void writeDate(Date date) { + if (date == null) { + writeNull(); + return; + } + //SimpleDataFormat is not thread-safe, we need to make it local. + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + writeString(dateFormat.format(date)); + } + + public void writeError(Throwable error) { + if (error == null) { + writeNull(); + return; + } + error.printStackTrace(); + + write("{\"Class\":"); + writeString(error.getClass().getName()); + write(",\"Message\":"); + writeString(error.getMessage()); + write(",\"StackTrace\":"); + writeString(getStackTrace(error)); + write('}'); + } + + public static String getStackTrace(Throwable ex) { + StringWriter buf = new StringWriter(); + ex.printStackTrace(new PrintWriter(buf)); + + return buf.toString(); + } + + public void writeArray(Object[] array) { + if (array == null) { + writeNull(); + return; + } + + write('['); + + for (int i = 0; i < array.length; ++i) { + if (i != 0) { + write(','); + } + writeObject(array[i]); + } + + write(']'); + } + + public void writeArray(Collection list) { + if (list == null) { + writeNull(); + return; + } + + int entryIndex = 0; + write('['); + + for (Object entry : list) { + if (entryIndex != 0) { + write(','); + } + writeObject(entry); + entryIndex++; + } + + write(']'); + } + + public void writeString(String text) { + if (text == null) { + writeNull(); + return; + } + + write('"'); + for (int i = 0; i < text.length(); ++i) { + char c = text.charAt(i); + if (c == '"') { + write("\\\""); + } else if (c == '\n') { + write("\\n"); + } else if (c == '\r') { + write("\\r"); + } else if (c == '\\') { + write("\\\\"); + } else if (c == '\t') { + write("\\t"); + } else if (c < 16) { + write("\\u000"); + write(Integer.toHexString(c)); + } else if (c < 32) { + write("\\u00"); + write(Integer.toHexString(c)); + } else if (c >= 0x7f && c <= 0xA0) { + write("\\u00"); + write(Integer.toHexString(c)); + } else { + write(c); + } + } + write('"'); + } + + public void writeTabularData(TabularData tabularData) { + if (tabularData == null) { + writeNull(); + return; + } + + int entryIndex = 0; + write('['); + + for (Object item : tabularData.values()) { + if (entryIndex != 0) { + write(','); + } + CompositeData row = (CompositeData) item; + writeCompositeData(row); + + entryIndex++; + } + write(']'); + } + + public void writeCompositeData(CompositeData compositeData) { + if (compositeData == null) { + writeNull(); + return; + } + + int entryIndex = 0; + write('{'); + + for (Object key : compositeData.getCompositeType().keySet()) { + if (entryIndex != 0) { + write(','); + } + writeString((String) key); + write(':'); + Object value = compositeData.get((String) key); + writeObject(value); + entryIndex++; + } + + write('}'); + } + + public void writeMap(Map map) { + if (map == null) { + writeNull(); + return; + } + + int entryIndex = 0; + write('{'); + for (Map.Entry entry : map.entrySet()) { + if (entryIndex != 0) { + write(','); + } + + writeString(entry.getKey()); + write(':'); + writeObject(entry.getValue()); + + entryIndex++; + } + + write('}'); + } + + protected void write(String text) { + out.append(text); + } + + protected void write(char c) { + out.append(c); + } + + protected void write(int c) { + out.append(c); + } + + protected void write(long c) { + out.append(c); + } + + public String toString() { + return out.toString(); + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/ITaskHandler.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/ITaskHandler.java new file mode 100644 index 0000000..c08d297 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/ITaskHandler.java @@ -0,0 +1,16 @@ +package com.taurus.core.util.task; + +/** + * 任务处理器通用接口 + * + * + */ +public interface ITaskHandler { + + /** + * + * @param task + * @throws Exception + */ + public void doTask(Task ask) throws Exception; +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/Task.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/Task.java new file mode 100644 index 0000000..c8afa95 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/Task.java @@ -0,0 +1,45 @@ +package com.taurus.core.util.task; + +import java.util.HashMap; +import java.util.Map; + +/** + * 任务数据基类 + * + * + */ +public class Task { + private Object id; + private Map parameters; + private volatile boolean active = true; + + public Task() { + this.parameters = new HashMap(); + } + + public Task(Object id) { + this(); + this.id = id; + } + + public Task(Object id, Map mapObj) { + this.id = id; + this.parameters = mapObj; + } + + public Object getId() { + return this.id; + } + + public Map getParameters() { + return this.parameters; + } + + public boolean isActive() { + return this.active; + } + + public void setActive(boolean active) { + this.active = active; + } +} diff --git a/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/TaskScheduler.java b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/TaskScheduler.java new file mode 100644 index 0000000..1e9dc23 --- /dev/null +++ b/taurus-server/taurus-core/src/main/java/com/taurus/core/util/task/TaskScheduler.java @@ -0,0 +1,139 @@ +package com.taurus.core.util.task; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; + +import com.taurus.core.service.AbstractService; +import com.taurus.core.util.Logger; + +/** + * 计时器/任务调度器 + * + * + */ +public class TaskScheduler extends AbstractService implements Runnable { + private static AtomicInteger schedulerId = new AtomicInteger(0); + + private volatile int threadId = 1; + private long SLEEP_TIME = 250L; + private ExecutorService taskExecutor; + private LinkedList taskList; + private LinkedList addList; + private Logger logger; + private volatile boolean running = false; + + public TaskScheduler() { + schedulerId.incrementAndGet(); + this.taskList = new LinkedList(); + this.addList = new LinkedList(); + this.logger = Logger.getLogger(TaskScheduler.class); + } + + public void init(Object o) { + super.init(o); + startService(); + } + + public void destroy(Object o) { + super.destroy(o); + stopService(); + } + + public void handleMessage(Object message) { + throw new UnsupportedOperationException("not supported in this class version"); + } + + public void startService() { + running = true; + taskExecutor = Executors.newSingleThreadExecutor(); + taskExecutor.execute(this); + } + + public void stopService() { + running = false; + List leftOvers = taskExecutor.shutdownNow(); + taskExecutor = null; + logger.info("Scheduler stopped. Unprocessed tasks: " + leftOvers.size()); + } + + public void run() { + Thread.currentThread().setName("Scheduler" + schedulerId.get() + "-thread-" + this.threadId++); + logger.info("Scheduler started: " + name); + + while (running) { + try { + executeTasks(); + Thread.sleep(SLEEP_TIME); + } catch (InterruptedException ie) { + logger.warn("Scheduler: " + name + " interrupted."); + } catch (Exception e) { + logger.error( "Scheduler: " + name + " caught a generic exception: " + e, e); + } + } + } + + public void addScheduledTask(Task task, int interval, boolean loop, ITaskHandler callback) { + synchronized (addList) { + addList.add(new ScheduledTask(task, interval, loop, callback)); + } + } + + private void executeTasks() { + long now = System.currentTimeMillis(); + + if (taskList.size() > 0) { + synchronized (taskList) { + for (Iterator it = taskList.iterator(); it.hasNext();) { + ScheduledTask t = (ScheduledTask) it.next(); + + if (!t.task.isActive()) { + it.remove(); + } else { + if (now < t.expiry) { + continue; + } + try { + t.callback.doTask(t.task); + } catch (Exception e) { + logger.error("Scheduler callback exception. Callback: " + t.callback + ", Exception: " + e, e); + } + + if (t.loop) { + t.expiry += t.interval * 1000; + } else { + it.remove(); + } + } + } + } + + } + + if (addList.size() > 0) { + synchronized (taskList) { + taskList.addAll(addList); + addList.clear(); + } + } + } + + private final class ScheduledTask { + long expiry; + int interval; + boolean loop; + ITaskHandler callback; + Task task; + + public ScheduledTask(Task t, int interval, boolean loop, ITaskHandler callback) { + this.task = t; + this.interval = interval; + this.expiry = (System.currentTimeMillis() + interval * 1000); + this.callback = callback; + this.loop = loop; + } + } +} diff --git a/taurus-server/taurus-core/src/test/java/Test.java b/taurus-server/taurus-core/src/test/java/Test.java new file mode 100644 index 0000000..f04b677 --- /dev/null +++ b/taurus-server/taurus-core/src/test/java/Test.java @@ -0,0 +1,221 @@ +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.UUID; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jdom.output.XMLOutputter; + +import com.mysql.cj.util.Util; +import com.sun.management.OperatingSystemMXBean; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.TArray; +import com.taurus.core.plugin.PluginService; +import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.Utils; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Transaction; + +public class Test { + private static final int[] PIDS= { + 48,49,50,51,52,53,54,55,56,57, +// 65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90, + 97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122 + }; + private static final Random rnd = new Random(System.currentTimeMillis()); + + private static final String rndId() { + char[] chars = new char[8]; + for(int i=0;i searchFiles(File folder, final String keyword) { + List result = new ArrayList(); + if (folder.isFile()) + result.add(folder); + + File[] subFolders = folder.listFiles(new FileFilter() { + @Override + public boolean accept(File file) { + if (file.isDirectory()) { + return true; + } + if (file.getName().toLowerCase().contains(keyword)) { + return true; + } + return false; + } + }); + + if (subFolders != null) { + for (File file : subFolders) { + if (file.isFile()) { + // 如果是文件则将文件添加到结果列表中 + result.add(file); + } else { + // 如果是文件夹,则递归调用本方法,然后把所有的文件加到结果列表中 + result.addAll(searchFiles(file, keyword)); + } + } + } + + return result; + } + + private static void read(Data data) throws Exception { + InputStream is = new FileInputStream(data.file); + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(is); + Element root = document.getRootElement(); + is.close(); + data.document = document; + data.root = root; + data.id = root.getAttributeValue("id"); + } + + private static final class Data{ + public File file; + public Document document; + public Element root; + public String id; + + public boolean equals(Object obj) { + if(obj instanceof Data) { + return this == obj; + } + if(obj instanceof String) { + return id.equals(obj); + } + return false; + } + } + + private static final String exceId(List datas) { + String id = rndId(); + if(datas.contains(id)) { + return exceId(datas); + } + return id; + } + + private static void emoji_test() { + try { + PluginService.me().loadConfig(); + String sql = "insert into test(nick) values('12🦌🦌🦌12')"; + long time = System.currentTimeMillis(); + for(int i=0;i<1;++i) { + DataBase.use().executeUpdate(sql); + } + System.out.println("use time:"+(System.currentTimeMillis() - time)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private static void find_test() { + try { + PluginService.me().loadConfig(); + String sql = "select * from test"; + long time = System.currentTimeMillis(); + for(int i=0;i<2000;++i) { + DataBase.use().executeQueryByTArray(sql); + } + System.out.println("use time:"+(System.currentTimeMillis() - time)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + private static OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + public static int cpuLoad() { + double cpuLoad = osmxb.getSystemCpuLoad(); + int percentCpuLoad = (int) (cpuLoad * 100); + return percentCpuLoad; + } + + public static void main(String[] args) { + try { + PluginService.me().loadConfig(); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + new Thread(() -> { + while (true) { + long bac = 1000000; + bac = bac >> 1; + } + }).start();; + + while (true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(cpuLoad()); + } + + + + +// find_test(); +// for(int i =0;i<100;++i) +// System.out.println(rndId()); + + /* + List files = searchFiles(new File("F:\\work\\pro\\qyq_client\\client\\new_pro\\qyq_new_ui\\"), "package.xml"); + List files1 = searchFiles(new File("F:\\work\\pro\\qyq_client\\client\\new_pro\\qyq_exinfo_ui\\"), "package.xml"); + files.addAll(files1); + List datas = new ArrayList<>(); + try { + for(File f : files) { + Data d = new Data(); + d.file = f; + read(d); + datas.add(d); + } + }catch (Exception e) { + e.printStackTrace(); + } + List listTemp = new ArrayList(); + for(int i=0;i + + 4.0.0 + + com.taurus + taurus-server + 1.0.1 + + jar + taurus-web + 1.0.1 + + + + junit + junit + + + + + com.taurus + taurus-core + + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + + + diff --git a/taurus-web/src/main/java/com/taurus/web/Controller.java b/taurus-web/src/main/java/com/taurus/web/Controller.java new file mode 100644 index 0000000..f61bb74 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/Controller.java @@ -0,0 +1,133 @@ +package com.taurus.web; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.routes.IController; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; + +/** + * Controller + * + * + */ +public abstract class Controller implements IController{ + private String actionKey; + private String session; + private String tokens; + private ITObject param; + private HttpServletRequest request; + private HttpServletResponse response; + private volatile boolean isFinish; + protected Logger logger; + + void _init(HttpServletRequest request,HttpServletResponse response,String actionKey,String session, String tokens, ITObject param){ + this.logger = Logger.getLogger(getClass()); + this.request = request; + this.response = response; + this.actionKey = actionKey; + this.session = session; + this.param = param; + this.tokens = tokens; + } + + /** + * get action key. + * @return + */ + public String getActionKey() { + return actionKey; + } + + public String getTokens() { return tokens; } + + /** + * 获取session对象 + * @return + */ + public String getSession() { + return session; + } + + public void setSession(String session) { + this.session = session; + } + + /** + * 获取参数 + * @return + */ + public ITObject getParams() { + return param; + } + + /** + * 动态响应客户端请示 + * @param result 响应结果 0成功 + * @param params 数据参数 + */ + public void sendResponse(int result, ITObject params) { + if(isFinish) { + throw new RuntimeException("This response is finish!"); + } + isFinish = true; + try { + WebUtils.httpResponse(this.response, result, params); + } catch (IOException e) { + logger.error("response client execption!\n",e); + } + } + + + + /** + * 获取客户端Host + * @return + */ + public String getRemoteAddr() { + return getIpAddr(this.request); + } + + private static final String[] HEADERS = { + "X-Forwarded-For", + "Proxy-Client-IP", + "WL-Proxy-Client-IP", + "HTTP_X_FORWARDED_FOR", + "HTTP_X_FORWARDED", + "HTTP_X_CLUSTER_CLIENT_IP", + "HTTP_CLIENT_IP", + "HTTP_FORWARDED_FOR", + "HTTP_FORWARDED", + "HTTP_VIA", + "REMOTE_ADDR", + "X-Real-IP" + }; + + private static final String UNKNOWN = "unknown"; + /** + * 判断ip是否为空,空返回true + * @param ip + * @return + */ + private static boolean isEmptyIp(final String ip){ + return (StringUtil.isEmpty(ip) || UNKNOWN.equalsIgnoreCase(ip)); + } + + private static String getIpAddr(HttpServletRequest request) { + String ip = StringUtil.Empty; + for (String header : HEADERS) { + ip = request.getHeader(header); + if(!isEmptyIp(ip)) { + break; + } + } + if(isEmptyIp(ip)){ + ip = request.getRemoteAddr(); + } + return ip; + } +} diff --git a/taurus-web/src/main/java/com/taurus/web/JettyServer.java b/taurus-web/src/main/java/com/taurus/web/JettyServer.java new file mode 100644 index 0000000..eafae99 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/JettyServer.java @@ -0,0 +1,158 @@ + +package com.taurus.web; + +import java.io.IOException; +import java.net.DatagramSocket; +import java.net.ServerSocket; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppClassLoader; +import org.eclipse.jetty.webapp.WebAppContext; + +import com.taurus.core.util.StringUtil; + + + +/** + * JettyServer is used to config and start jetty web server. + */ +public class JettyServer{ + private static final int DEFAULT_PORT = 80; + private static final String DEFAULT_WEBAPPDIR = "webapp"; + + private String webAppDir; + private int port; + private String context; + private boolean running = false; + private Server server; + private WebAppContext webApp; + + public JettyServer(){ + this(DEFAULT_WEBAPPDIR,DEFAULT_PORT,"/"); + } + + public JettyServer(String webAppDir, int port, String context) { + + if (webAppDir == null) { + throw new IllegalStateException("Invalid webAppDir of web server: " + webAppDir); + } + if (port < 0 || port > 65535) { + throw new IllegalArgumentException("Invalid port of web server: " + port); + } + if (StringUtil.isEmpty(context)) { + throw new IllegalStateException("Invalid context of web server: " + context); + } + + this.webAppDir = webAppDir; + this.port = port; + this.context = context; + } + + public void start() { + if (!running) { + try { + running = true; + doStart(); + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + } + + public void stop() { + if (running) { + try {server.stop();} catch (Exception e) {e.printStackTrace();} + running = false; + } + } + + private void doStart() { + if (!available(port)) { + throw new IllegalStateException("port: " + port + " already in use!"); + } + + System.out.println("Starting taurus web server "); + server = new Server(port); + webApp = new WebAppContext(); + webApp.setThrowUnavailableOnStartupException(true); + webApp.setContextPath(context); + webApp.setResourceBase(webAppDir); + webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); + webApp.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); + + server.setHandler(webApp); + changeClassLoader(webApp); + + + try { + System.out.println("Starting web server on port: " + port); + server.start(); + System.out.println("Starting Complete."); + server.join(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(100); + } + return; + } + + private void changeClassLoader(WebAppContext webApp) { + try { + WebAppClassLoader jfcl = new WebAppClassLoader(webApp); + webApp.setClassLoader(jfcl); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static boolean available(int port) { + if (port <= 0) { + throw new IllegalArgumentException("Invalid start port: " + port); + } + + ServerSocket ss = null; + DatagramSocket ds = null; + try { + ss = new ServerSocket(port); + ss.setReuseAddress(true); + ds = new DatagramSocket(port); + ds.setReuseAddress(true); + return true; + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (ds != null) { + ds.close(); + } + + if (ss != null) { + try { + ss.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return false; + } + + + + public static void main(String[] args) { + if (args == null || args.length == 0) { + JettyServer server = new JettyServer(); + server.start(); + return; + } + + if (args.length == 3) { + String webAppDir = args[0]; + int port = Integer.parseInt(args[1]); + String context = args[2]; + JettyServer server = new JettyServer(webAppDir, port, context); + server.start(); + return ; + } + } + +} \ No newline at end of file diff --git a/taurus-web/src/main/java/com/taurus/web/ServletHealthCheck.java b/taurus-web/src/main/java/com/taurus/web/ServletHealthCheck.java new file mode 100644 index 0000000..c5464a8 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/ServletHealthCheck.java @@ -0,0 +1,23 @@ +package com.taurus.web; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.util.StringUtil; + + +@WebServlet("/health") +public class ServletHealthCheck extends HttpServlet { + + private static final long serialVersionUID = 1L; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.getWriter().println(StringUtil.Empty); + } + +} diff --git a/taurus-web/src/main/java/com/taurus/web/SessionInfo.java b/taurus-web/src/main/java/com/taurus/web/SessionInfo.java new file mode 100644 index 0000000..42ad702 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/SessionInfo.java @@ -0,0 +1,11 @@ +package com.taurus.web; + +/** + * session info + * + * + */ +public class SessionInfo { + public String target; + public String method; +} diff --git a/taurus-web/src/main/java/com/taurus/web/StatusServlet.java b/taurus-web/src/main/java/com/taurus/web/StatusServlet.java new file mode 100644 index 0000000..f54a6f3 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/StatusServlet.java @@ -0,0 +1,66 @@ +package com.taurus.web; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.plugin.redis.Cache; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.StringUtil; + +import redis.clients.jedis.JedisPool; + +@WebServlet("/status") +public class StatusServlet extends HttpServlet{ + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + String str = ""; + String tem = req.getParameter("info"); + boolean is_info = false; + if(StringUtil.isNotEmpty(tem)) { + is_info = Boolean.parseBoolean(tem); + } + int size = TWebServer.me().getConcurrentSize(); + str += "connect-num:"+size + "
"; + if(is_info) { + List concurrentList = TWebServer.me().getConcurrentList(); + List list = null; + synchronized (concurrentList) { + list = new ArrayList<>(concurrentList); + } + int i= 0; + for(SessionInfo info : list) { + i++; + str +=String.format("
[%s] action->%s method->%s
",i, info.target,info.method); + } + } + + ConcurrentHashMap map = Redis.getCacheMap(); + Set> entrySet = map.entrySet(); + for(Entry entry : entrySet) { + JedisPool pool = entry.getValue().getJedisPool(); + str += String.format("
%s
",entry.getKey()); + str += "active-num:"+pool.getNumActive(); + str += "\tidle-num:"+pool.getNumIdle(); + str += "\twait-num:"+pool.getNumWaiters(); + } + str+=""; + + resp.getWriter().write(str); + } +} diff --git a/taurus-web/src/main/java/com/taurus/web/TWebServer.java b/taurus-web/src/main/java/com/taurus/web/TWebServer.java new file mode 100644 index 0000000..56266ec --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/TWebServer.java @@ -0,0 +1,231 @@ +package com.taurus.web; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.plugin.PluginService; +import com.taurus.core.routes.Action; +import com.taurus.core.routes.ActionMapping; +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; + +/** + * The web server main class. + * + * + * + */ +public class TWebServer { + private static final String _POST = "POST"; + private static final String _Session = "$s"; + private static final String _Version = "$v"; + /** + * The server class instance. + */ + private static TWebServer _instance = null; + private Logger log; + private Extension extension; + private ActionMapping actionMapping; + private ScheduledThreadPoolExecutor timeScheduler; + private int forceVer = 1; + private Routes routes; + private String contextPath; + private String contextRealPath; + /** + * 当前并发数 + */ + private final List concurrentList; + + /** + * get main instance + */ + public static TWebServer me() { + if (_instance == null) { + _instance = new TWebServer(); + } + return _instance; + } + + public TWebServer() { + log = Logger.getLogger(WebFilter.class); + this.routes = new Routes(Routes.CONTROLLER_CLASS) { + public void config() { + } + }; + concurrentList = new ArrayList(); + timeScheduler = new ScheduledThreadPoolExecutor(1); + actionMapping = new ActionMapping(routes); + } + + void init(FilterConfig filterConfig) throws Exception { + String path = filterConfig.getServletContext().getRealPath("/"); + System.setProperty("WORKDIR", path); + PluginService.me().loadConfig(path); + this.contextRealPath = path; + this.contextPath = filterConfig.getServletContext().getContextPath(); + String extensionClass = filterConfig.getInitParameter("main"); + this.extension = instanceExtension(extensionClass); + this.extension.configRoute(routes); + actionMapping.buildActionMapping(); + this.extension.onStart(); + timeScheduler.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { + forceVer = extension.readVersion(); + } + }, 5, 5, TimeUnit.SECONDS); + } + + private Extension instanceExtension(String extensionClass) { + if (StringUtil.isEmpty(extensionClass)) { + throw new RuntimeException("Extension class parameter is missing!"); + } + Extension extension = null; + try { + Class exclass = Class.forName(extensionClass); + if (!Extension.class.isAssignableFrom(exclass)) { + throw new RuntimeException("You extension does not implement Extension "); + } + extension = (Extension) exclass.newInstance(); + } catch (IllegalAccessException e) { + throw new RuntimeException("Illegal access while instantiating class: " + extensionClass); + } catch (InstantiationException e) { + throw new RuntimeException("Cannot instantiate class: " + extensionClass); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Class not found: " + extensionClass); + } + return extension; + } + + void handle(String target,HttpServletRequest request,HttpServletResponse response,FilterChain chain) + throws IOException, ServletException { + String method = request.getMethod(); + SessionInfo info = new SessionInfo(); + info.target = target; + info.method = method; + synchronized (concurrentList) { + concurrentList.add(info); + } + Action action =actionMapping.getAction(target); + try { + if (action != null) { + if (!method.equals(_POST)) { + return; + } + + ITObject obj = WebUtils.httpRequest(request); + if (obj == null) { + throw new RuntimeException("data is null!"); + } + if (!obj.containsKey(_Version)) { + WebUtils.httpResponse(response, -1, null); + return; + } + int client_ver = obj.getInt(_Version); + if (client_ver < forceVer) { + WebUtils.httpResponse(response, -1, null); + return; + } + long startTime = System.currentTimeMillis(); + String session = null; + String token = null; + if (obj.containsKey(_Session)) { + String str_session = obj.getString(_Session); + String[] sourceStrArray = str_session.split(","); + if (sourceStrArray.length == 2) + { + session = sourceStrArray[0]; + token = sourceStrArray[1]; + } + else { + session = str_session; + } + } + ITObject params = obj.getTObject(WebUtils._Param); + Controller controller = null; + try { + controller = (Controller)action.getControllerClass().newInstance(); + controller._init(request, response, action.getActionKey(), session, token, params); + + if (action.getInterceptor() != null) { + action.getInterceptor().intercept(action, controller); + } + action.getMethod().invoke(controller); + } catch (InvocationTargetException e) { + Throwable targetException = e.getTargetException(); + if (targetException instanceof WebException) { + WebException we = (WebException) targetException; + controller.sendResponse(we.getCode(), null); + } else { + controller.sendResponse(500, null); + log.error(targetException); + } + }catch (WebException e) { + controller.sendResponse(e.getCode(), null); + }catch (Exception e) { + if (controller != null) { + controller.sendResponse(500, null); + } + log.error(e); + } + long endTime = System.currentTimeMillis(); + log.info("action: "+action + "[" + session+"] time:"+(endTime - startTime)+"ms"); + } else { + chain.doFilter(request, response); + } + }finally { + synchronized (concurrentList) { + concurrentList.remove(info); + } + } + } + void destroy() { + if (timeScheduler != null) { + timeScheduler.shutdownNow(); + } + if (extension != null) { + extension.onStop(); + } + PluginService.me().stop(); + synchronized (concurrentList) { + concurrentList.clear(); + } + } + + public int getForceVer() { + return forceVer; + } + + public String getContextPath() { + return contextPath; + } + + public String getContextRealPath() { + return contextRealPath; + } + + public List getConcurrentList(){ + return concurrentList; + } + + public int getConcurrentSize() { + int size = concurrentList.size(); + if(extension!=null) { + size +=extension.getConcurrentSize(); + } + return size; + } +} diff --git a/taurus-web/src/main/java/com/taurus/web/WebException.java b/taurus-web/src/main/java/com/taurus/web/WebException.java new file mode 100644 index 0000000..1a1ec72 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/WebException.java @@ -0,0 +1,17 @@ +package com.taurus.web; + +public class WebException extends Exception{ + /** + * + */ + private static final long serialVersionUID = 1L; + private int code; + + public WebException(int code) { + this.code = code; + } + + public int getCode() { + return code; + } +} diff --git a/taurus-web/src/main/java/com/taurus/web/WebFilter.java b/taurus-web/src/main/java/com/taurus/web/WebFilter.java new file mode 100644 index 0000000..565a376 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/WebFilter.java @@ -0,0 +1,72 @@ +package com.taurus.web; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.util.StringUtil; + +/** + * + * main filter class + * + */ +public class WebFilter implements Filter { + private static final String _UTF8 = "UTF-8"; + private static final String _ALLOW_ORIGIN = "Access-Control-Allow-Origin"; + private static final String _ALLOW_ORIGIN_V = "*"; + private int contextPathLength; + + private TWebServer tweb; + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + try { + String contextPath = filterConfig.getServletContext().getContextPath(); + contextPathLength = StringUtil.isNotEmpty(contextPath) ? contextPath.length() : 0; + tweb = TWebServer.me(); + tweb.init(filterConfig); + } catch (Exception e) { + e.printStackTrace(); + throw new ServletException(e); + } + } + + + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + HttpServletRequest request = (HttpServletRequest) req; + HttpServletResponse response = (HttpServletResponse) res; + + String target = request.getRequestURI(); + if (StringUtil.isEmpty(target)) { + return; + } + if (contextPathLength != 0) { + target = target.substring(contextPathLength); + } + // 添加对/config/目录的访问限制 + if (target.contains("/config/") || target.contains(".") ) { + response.setStatus(HttpServletResponse.SC_FORBIDDEN); + response.getWriter().write("Access to config directory is forbidden"); + return; + } + request.setCharacterEncoding(_UTF8); + response.setCharacterEncoding(_UTF8); + response.setHeader(_ALLOW_ORIGIN, _ALLOW_ORIGIN_V); + tweb.handle(target, request, response, chain); + } + + @Override + public void destroy() { + tweb.destroy(); + } + +} diff --git a/taurus-web/src/main/java/com/taurus/web/WebUtils.java b/taurus-web/src/main/java/com/taurus/web/WebUtils.java new file mode 100644 index 0000000..b8415d4 --- /dev/null +++ b/taurus-web/src/main/java/com/taurus/web/WebUtils.java @@ -0,0 +1,42 @@ +package com.taurus.web; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Utils; + +/** + * WebUtils + * + * + */ +public class WebUtils{ + static final String _Result = "$r"; + static final String _Param = "$p"; + + + static final ITObject httpRequest(HttpServletRequest request) throws IOException { + InputStream in = request.getInputStream(); + byte[] bytes = Utils.uncompress(in); + ITObject obj = TObject.newFromBinaryData(bytes); + return obj; + } + + final static void httpResponse(HttpServletResponse response, int result, ITObject param) throws IOException { + ITObject tem = TObject.newInstance(); + tem.putInt(_Result, result); + param = param == null ? TObject.newInstance() : param; + tem.putTObject(_Param, param); + byte[] bytes = tem.toBinary(); + OutputStream out = response.getOutputStream(); + Utils.compress(bytes, out); + out.close(); + } + +} diff --git a/taurus-web/src/test/java/com/taurus/Test.java b/taurus-web/src/test/java/com/taurus/Test.java new file mode 100644 index 0000000..790c675 --- /dev/null +++ b/taurus-web/src/test/java/com/taurus/Test.java @@ -0,0 +1,14 @@ +package com.taurus; + +public class Test { + + public static void main(String[] args) { + +// UndertowServer.create(AppConfig.class) +// .addHotSwapClassPrefix("com.abc.") +// .setPort(8000) +// .setDevMode(true) +// .start(); + } + +} diff --git a/web_group/build/local/taurus-core.xml b/web_group/build/local/taurus-core.xml new file mode 100644 index 0000000..e677c8e --- /dev/null +++ b/web_group/build/local/taurus-core.xml @@ -0,0 +1,96 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + \ No newline at end of file diff --git a/web_group/build/pro/bank_hp.lua b/web_group/build/pro/bank_hp.lua new file mode 100644 index 0000000..d3a02ce --- /dev/null +++ b/web_group/build/pro/bank_hp.lua @@ -0,0 +1,19 @@ +local tag_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local bank_hp = tonumber(redis.call('hget', KEYS[2],KEYS[3])) +bank_hp = not bank_hp and 0 or bank_hp +local hp = tonumber(ARGV[1]) +local opt = tonumber(ARGV[2]) +if opt==0 then + if bank_hp < hp then + return 3 + end + bank_hp = redis.call('hincrBy',KEYS[2],KEYS[3],-hp) + tag_hp = redis.call('hincrBy',KEYS[1],'hp',hp) +else + if tag_hp < hp then + return 4 + end + bank_hp = redis.call('hincrBy',KEYS[2],KEYS[3],hp) + tag_hp = redis.call('hincrBy',KEYS[1],'hp',-hp) +end +return {tag_hp,bank_hp} \ No newline at end of file diff --git a/web_group/build/pro/log4j.properties b/web_group/build/pro/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_group/build/pro/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_group/build/pro/mgr.lua b/web_group/build/pro/mgr.lua new file mode 100644 index 0000000..50b3c69 --- /dev/null +++ b/web_group/build/pro/mgr.lua @@ -0,0 +1,25 @@ +-- redis.call('select',0) +local mgr_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local tag_hp = tonumber(redis.call('hget', KEYS[2],'hp')) + +local ulev = tonumber(ARGV[2]) +local hp = tonumber(ARGV[1]) +if ulev == 3 or ulev == 2 then + if hp > 0 and mgr_hp 0 and reward_hp < hp then + return 3 +else + reward_hp = redis.call('incrBy',KEYS[1],-hp) + tag_hp = redis.call('hincrBy',KEYS[2],'hp',hp) +end +return {reward_hp,tag_hp} \ No newline at end of file diff --git a/web_group/build/pro/taurus-core.xml b/web_group/build/pro/taurus-core.xml new file mode 100644 index 0000000..49049a5 --- /dev/null +++ b/web_group/build/pro/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_group/build/pro/trade.lua b/web_group/build/pro/trade.lua new file mode 100644 index 0000000..c03a438 --- /dev/null +++ b/web_group/build/pro/trade.lua @@ -0,0 +1,12 @@ +local mgr_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local tag_hp = tonumber(redis.call('hget', KEYS[2],'hp')) +mgr_hp = not mgr_hp and 0 or mgr_hp +tag_hp = not tag_hp and 0 or tag_hp +local hp = tonumber(ARGV[1]) +if hp > 0 and mgr_hp 0 and mgr_hp 0 and reward_hp < hp then + return 3 +else + reward_hp = redis.call('incrBy',KEYS[1],-hp) + tag_hp = redis.call('hincrBy',KEYS[2],'hp',hp) +end +return {reward_hp,tag_hp} \ No newline at end of file diff --git a/web_group/build/test/taurus-core.xml b/web_group/build/test/taurus-core.xml new file mode 100644 index 0000000..bde0e53 --- /dev/null +++ b/web_group/build/test/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 1 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_group/build/test/trade.lua b/web_group/build/test/trade.lua new file mode 100644 index 0000000..c03a438 --- /dev/null +++ b/web_group/build/test/trade.lua @@ -0,0 +1,12 @@ +local mgr_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local tag_hp = tonumber(redis.call('hget', KEYS[2],'hp')) +mgr_hp = not mgr_hp and 0 or mgr_hp +tag_hp = not tag_hp and 0 or tag_hp +local hp = tonumber(ARGV[1]) +if hp > 0 and mgr_hp + 4.0.0 + com.group + web_group + war + 1.0.0 + + UTF-8 + 1.8 + 1.8 + pro + + + + + junit + junit + 3.8.1 + test + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + mysql + mysql-connector-java + 8.0.16 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + com.google.code.gson + gson + 2.8.5 + + + + com.aliyun + aliyun-java-sdk-core + 4.0.3 + + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + org.quartz-scheduler + quartz + 2.2.3 + compile + + + + + + + ROOT + + + org.apache.maven.plugins + maven-war-plugin + + 1.8 + 1.8 + UTF-8 + logs/**,config/** + + + config/ + ${project.basedir}/build/${build.type}/ + + + + + + + + diff --git a/web_group/src/main/java/com/group/MainServer.java b/web_group/src/main/java/com/group/MainServer.java new file mode 100644 index 0000000..1854ef8 --- /dev/null +++ b/web_group/src/main/java/com/group/MainServer.java @@ -0,0 +1,133 @@ +package com.group; + + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.group.controller.GroupController; +import com.group.controller.GroupLogController; +import com.group.controller.GroupRoomController; +import com.group.job.UpdatePlayRoomJob; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; +import com.taurus.core.util.FileUtil; + +import org.quartz.CronTrigger; +import org.quartz.JobDetail; +import org.quartz.Scheduler; +import org.quartz.SchedulerFactory; +import org.quartz.impl.StdSchedulerFactory; +import redis.clients.jedis.Jedis; + +import static org.quartz.CronScheduleBuilder.cronSchedule; +import static org.quartz.JobBuilder.newJob; +import static org.quartz.TriggerBuilder.newTrigger; + +public class MainServer extends Extension { + private ScheduledThreadPoolExecutor timeScheduler; + + private static final String WEB_CONFIG_KEY = "web_config"; + private static final String FORCE_VER_KEY = "force_ver"; + + public static Map lua_map = new HashMap<>(); + public MainServer() { + super(); + //3秒 +// NetManager.TIMEOUT_TIME =3; + timeScheduler = new ScheduledThreadPoolExecutor(1); + timeScheduler.scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + AccountCache.clearData(); + GroupCache.clearData(); + System.gc(); + } + }, 0,600, TimeUnit.SECONDS); + loadLua(); + initJob(); + } + + @Override + public int readVersion() { + int ver = Integer.parseInt(Redis.use("group1_db1").hget(WEB_CONFIG_KEY,FORCE_VER_KEY)); + return ver; + } + + + @Override + public void configRoute(Routes me) { + me.setInterceptor(new WebInterceptor()); + + me.add("group", GroupController.class); + me.add("group/room", GroupRoomController.class); + me.add("group/log",GroupLogController.class); + } + + private static void loadLua() { + String path = System.getProperty("WORKDIR"); + try { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + String str = FileUtil.readTxt(path + "/config/mgr.lua"); + lua_map.put("mgr", jedis10.scriptLoad(str)); + str = FileUtil.readTxt(path + "/config/trade.lua"); + lua_map.put("trade", jedis10.scriptLoad(str)); + str = FileUtil.readTxt(path + "/config/take_hp.lua"); + lua_map.put("take_hp", jedis10.scriptLoad(str)); + str = FileUtil.readTxt(path + "/config/bank_hp.lua"); + lua_map.put("bank_hp", jedis10.scriptLoad(str)); + } finally { + jedis10.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void initJob() { + + try { + SchedulerFactory sf = new StdSchedulerFactory(); + Scheduler sched = sf.getScheduler(); + + JobDetail job = newJob(UpdatePlayRoomJob.class).withIdentity("update_play_room", "group").build(); + CronTrigger trigger= newTrigger().withIdentity("update_play_room_trigger", "group").withSchedule(cronSchedule("0/5 * * * * ? ")).build(); + sched.scheduleJob(job, trigger); + + job = newJob(UpdatePlayRoomJob.class).withIdentity("create_play_room", "group").build(); + trigger= newTrigger().withIdentity("create_play_room_trigger", "group").withSchedule(cronSchedule("0/3 * * * * ? ")).build(); + sched.scheduleJob(job, trigger); + + sched.start(); + } + catch(Exception e) { + + } + } + + + @Override + public void onStart() { + System.out.println("web group start!"); + } + + @Override + public void onStop() { + if(timeScheduler!=null) { + timeScheduler.shutdownNow(); + } + } + + + + + + + +} diff --git a/web_group/src/main/java/com/group/Protocol.java b/web_group/src/main/java/com/group/Protocol.java new file mode 100644 index 0000000..6025a82 --- /dev/null +++ b/web_group/src/main/java/com/group/Protocol.java @@ -0,0 +1,219 @@ +package com.group; + + +public class Protocol { + + + + // --------------------group-------------------------- + + + /**获取圈子列表*/ + public static final String GET_GROUPS = "get_groups"; + /**获取创建圈子*/ + public static final String CREATE_GROUP = "create_group"; + /**加入圈子*/ + public static final String JOIN_GROUP = "join_group"; + /**删除圈子*/ + public static final String DEL_GROUP = "del_group"; + /**获取申请列表*/ + public static final String GET_GROUP_JOINS = "get_group_joins"; + /**授权加入圈子*/ + public static final String VERIFY_JOIN_GROUP = "verify_join_group"; + /**获取成员列表*/ + public static final String GET_GROUP_MEMBERS = "get_group_members"; + + public static final String GET_MY_MEMBERS = "get_my_members"; + + /** 获取下级成员 **/ + public static final String GET_CHILD_MEMBERS = "get_child_members"; + + public static final String GET_MEMBERS_COUNT = "get_members_count"; + + /**获取合伙人列表*/ + public static final String GET_GROUP_PARTNERS = "get_group_partners"; + /**删除成员*/ + public static final String GROUP_KICK = "group_kick"; + + public static final String GET_KICK_LOG = "get_kick_log"; + + /** 邀请加入圈子*/ + public static final String INVITE_GROUP_MEMBER = "invite_group_member"; + /** 获取玩家信息 */ + public static final String GET_PLAYER_INFO = "get_player_info"; + + public static final String CLONE_GROUP = "clone_group"; + + + /** 获取提取数据信息*/ + public static final String TRADE_TAKE_INFO = "get_take_info"; + /** 提取体力值*/ + public static final String TAKE_HP = "take_hp"; + /** 提取体力值*/ + public static final String GROUP_TAKE_HP = "group_take_hp"; + + public static final String GET_BANK_HP = "get_bank_hp"; + public static final String TAKE_BANK_HP = "take_bank_hp"; + public static final String SAVE_BANK_HP = "save_bake_hp"; + + /** 获取提取日志*/ + public static final String GET_TAKE_LOG = "get_take_log"; + + public static final String GET_BANK_LOG = "get_bank_log"; + + + /** 更新成员体力值*/ + public static final String UPDATE_MEMBER_HP = "update_member_hp"; + public static final String UPDATE_MEMBER_SCORE = "update_member_score"; + + public static final String UPDATE_MEMBER_QUEUEID = "update_member_queueid"; //分组id + + public static final String UPDATE_MEMBER_SEEID = "update_member_seeid"; //权限id + + public static final String UPDATE_MEMBER_DIAOKONG = "update_member_diaokong"; //分组id + + /** 进入圈子*/ + public static final String ENTER_GROUP = "enter_group"; + + /** 进入圈子*/ + public static final String ENTER_GROUP_3 = "enter_group_3"; + + + /** 置顶圈子*/ + public static final String STICK_GROUP = "stick_group"; + + /**获取所有玩法列表*/ + public static final String GET_ALLPLAY = "get_all_play"; + + public static final String SET_BANPLAY = "set_ban_play"; + + /** 添加玩法 */ + public static final String ADD_PLAY = "add_play"; + /** 删除玩法 */ + public static final String DEL_PLAY = "del_play"; + /** 更新玩法*/ + public static final String UPDATE_PLAY = "update_play"; + /** 快速加入房间 */ + public static final String GROUP_MATCH_ROOM = "match_room"; + /** 加入房间 */ + public static final String GROUP_JOIN_ROOM = "join_room"; + /** 删除房间 */ + public static final String GROUP_DEL_ROOM = "del__room"; + /** 更新圈子配置 */ + public static final String GROUP_UPDATE_INFO = "update_info"; + /** 成员禁止娱乐*/ + public static final String GROUP_BAN_MEMBER = "ban_member"; + /** 成员禁止娱乐*/ + public static final String GROUP_BLACK_MEMBER = "black_member"; + /** 成员禁止娱乐*/ + public static final String GROUP_GET_BLACK_MEMBER = "get_black_member"; + /** 玩法禁止娱乐*/ + public static final String GROUP_BAN_PLAY = "ban_play"; + /** 标识玩法*/ + public static final String GROUP_MARK_PLAY = "mark_play"; + /** 更新成员管理*/ + public static final String GROUP_SET_MEMBER_MGR = "set_member_mgr"; + /** 更新成员管理*/ + public static final String GROUP_SET_PARTNER = "set_partner"; + /** 获取成员上级合伙人列表*/ + public static final String GET_MEMBER_PARENTS = "get_member_parents"; + /** 查询成员*/ + public static final String FIND_MEMBER = "find_member"; + /** 查询成员1*/ + public static final String FIND_MEMBER1 = "find_member1"; + /** 获取管理上下分记录*/ + public static final String GET_HPLOG_MGR = "get_hplog_mgr"; + /** 获取管理上下分记录统计*/ + public static final String GET_HPLOG_MGR_COUNT = "get_hplog_mgr_count"; + /** 获取管理员上下分详细信息*/ + public static final String GET_HPLOG_MGR_INFO = "get_hplog_mgr_info"; + /** 获取玩家体力值详细*/ + public static final String GET_HPLOG_INFO = "get_hplog_info"; + + /** 获取玩家详细体力值*/ + public static final String GET_HPLOG_DETAIL_INFO = "get_hplog_detail_info"; + + /** 获取抽水体力值详细*/ + public static final String GET_HPLOG_PUMP = "get_hplog_pump"; + /** 设置奖励*/ + public static final String GROUP_SET_REWARD = "set_reward"; + /** 设置奖励*/ + public static final String GROUP_SET_XIPAI_REWARD = "set_xipai_reward"; + /** 获取奖励数据*/ + public static final String GROUP_GET_REWARDS = "get_rewards"; + /** 获取奖励日志*/ + public static final String GROUP_GET_REWARD_LOG = "get_reward_log"; + /** 获取奖励统计*/ + public static final String GROUP_GET_REWARD_COUNT = "get_reward_count"; + /** 获取玩法局数统计*/ + public static final String GROUP_GET_PLAY_ROUND_COUNT = "get_play_round_count"; + /** 获取消耗统计*/ + public static final String GROUP_GET_COST_COUNT = "get_cost_count"; + /** 获取局数统计*/ + public static final String GROUP_GET_ROUND_COUNT = "get_round_count"; + /**获得成员统计*/ + public static final String GROUP_GET_MEMBER_STAT = "get_member_stat"; + /**获得合伙人统计*/ + public static final String GROUP_GET_PARTNER_STAT = "get_partner_stat"; + /**查找合伙人统计*/ + public static final String GROUP_FIND_PARTNER_STAT = "find_partner_stat"; + /**获得合伙人统计 成员*/ + public static final String GROUP_GET_PARTNER_STAT_MEMBER = "get_partner_stat_member"; + /**查找合伙人统计 成员*/ + public static final String GROUP_FIND_PARTNER_STAT_MEMBER = "find_partner_stat_member"; + + public static final String GROUP_GET_DIRECT_STAT_MEMBER = "get_direct_stat_member"; + /**获得合伙人统计 玩法*/ + public static final String GROUP_GET_PARTNER_STAT_PLAY = "get_partner_stat_play"; + /** 获取成员排行*/ + public static final String GROUP_GET_MEMBER_RANK = "get_member_rank"; + /** 获取战绩列表*/ + public static final String GROUP_GET_RECORDS = "get_records"; + /** 获取个人亲友圈战绩列表*/ + public static final String GROUP_GET_PERSON_RECORDS = "get_person_records"; + /** 根据房间ID查询战绩*/ + public static final String GROUP_FIND_RECORD_ROOM = "find_record_room"; + /** 调配成员*/ + public static final String DISTRIBUTE_MEMBER = "distribute_member"; + /** 退出圈子*/ + public static final String EXIT_GROUP = "exit_group"; + /** 获取合伙人[日志]管理列表*/ + public static final String GET_PARTNER_INFOS = "get_partner_data"; + /**搜索合伙人信息*/ + public static final String QUERY_PARTNER_INFOS = "query_partner_data"; + /** 获取合伙人[日志]成员列表*/ + public static final String GET_PARTNER_MEMBERS = "get_partner_members"; + + /** 设置管理员权限*/ + public static final String SET_MGR_PERMISSION = "set_mgr_permission"; + /** 获取禁止同桌列表*/ + public static final String GET_BAN_DESK_LIST = "get_ban_desk_list"; + /** 设置禁止同桌*/ + public static final String SET_BAN_DESK = "set_ban_desk"; + /**获取体力值信息*/ + public static final String GET_HP_COUNT_INFO ="get_hp_count_info"; + /** 获取体力值消耗统计*/ + public static final String GROUP_GET_HPCONSUME_COUNT = "get_hpconsume_count"; + /** 转移合伙人*/ + public static final String MOVE_PARTNER = "move_partner"; + /**获取整线体力值*/ + public static final String GET_HP_TOTAL = "get_hp_total"; + /**更新推广设置*/ + public static final String UPDATE_PROMOTION = "update_promotion"; + /**获取推广设置*/ + public static final String GET_PROMOTION = "get_promotion"; + /**获取邮件列表*/ + public static final String GET_MAIL_LIST = "get_mail_list"; + /**删除所以邮件*/ + public static final String DEL_MAIL_ALL = "del_mail_all"; + + /**设置亲友圈合伙人阀值*/ + public static final String SET_AUTO_SCORE ="set_auto_score"; + + /**幸运号数据*/ + public static final String GET_XINGYUNHAO_INFO ="get_xingyunhao_info"; + + /** 重置密码*/ + public static final String GROUP_RESET_PASSWORD = "group_reset_password"; + +} diff --git a/web_group/src/main/java/com/group/WebInterceptor.java b/web_group/src/main/java/com/group/WebInterceptor.java new file mode 100644 index 0000000..1aaf2d2 --- /dev/null +++ b/web_group/src/main/java/com/group/WebInterceptor.java @@ -0,0 +1,186 @@ +package com.group; + +import com.data.bean.AccountBean; +import com.data.bean.GroupBean; +import com.data.bean.GroupMemberBean; +import com.data.bean.GroupPlayBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.util.ErrorCode; +import com.group.service.GroupRoomService; +import com.taurus.core.entity.ITObject; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.Action; +import com.taurus.core.routes.IController; +import com.taurus.core.routes.Interceptor; +import com.taurus.core.util.StringUtil; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +public class WebInterceptor implements Interceptor{ + /** + * 验证session + */ + public static final int V_SESSION = 1; + /** + * 验证圈子 + */ + public static final int V_GROUP = 2; + /** + * 验证圈主 + */ + public static final int V_GROUP_OWNER = 4; + /** + * 验证合伙人 + */ + public static final int V_GROUP_PARTNER= 8; + /** + * 验证玩法 + */ + public static final int V_GROUP_PLAY= 16; + /** + * 验证管理员 + */ + public static final int V_GROUP_MGR= 32; + /** + * 验证管理员或者合伙人 + */ + public static final int V_GROUP_MGR_OR_PARTNER= 64; + /** + * 检测玩家在不在房间 + */ + public static final int V_GROUP_CHECK_ROOM= 128; + + /** + * 验证圈主或合伙人 + */ + public static final int V_GROUP_OWNER_OR_MGR_OR_PARTNER = 256; + + @Override + public void intercept(Action action, IController controller, Object... args) throws Exception { + Controller ctr = (Controller) controller; + int validate = action.getActionKeyObj().validate(); + String session = ctr.getSession(); + String token = ctr.getTokens(); + if (StringUtil.isNotEmpty(token) && StringUtil.isNotEmpty(session)) + { + String token_session = Redis.use("group1_db0").hget(token, "user"); + if (StringUtil.isEmpty(token_session)) + { + throw new WebException(ErrorCode._NO_SESSION); + } + else { + if (!token_session.equals(session)) + { + throw new WebException(ErrorCode._NO_SESSION); + } + } + } + else { + throw new WebException(ErrorCode._NO_SESSION); + } + + if ((validate&V_SESSION)!=0 ) { + if (!Redis.use("group1_db0").exists(session)) { + throw new WebException(ErrorCode._NO_SESSION); + } + String opt = Redis.use("group1_db0").hget(session, "opt"); +// background del sign + if (!StringUtil.isEmpty(opt) && Integer.parseInt(opt) == 1) { + throw new WebException(ErrorCode._NO_SESSION); + } + } + + if((validate&V_GROUP)!=0) { + ITObject reqData = ctr.getParams(); + if(!reqData.containsKey("id")) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + int groupId = reqData.getInt("id"); + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + if (gb.stop == 1) { + throw new WebException(ErrorCode.GROUP_STOP_SERVICE); + } + AccountBean acc = AccountCache.getAccount(session); + if((validate&V_GROUP_CHECK_ROOM)!=0) { + boolean checkRoom = GroupRoomService.checkRoom(groupId, acc.id); + if(checkRoom) { + throw new WebException(ErrorCode.GROUP_EXIST_ROOMS); + } + } + boolean v_o_p = (validate&V_GROUP_OWNER_OR_MGR_OR_PARTNER)!=0; + if (v_o_p) + { + if(gb.owner != acc.id) { + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb==null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (gmb.lev >= 3) + { + if(gmb.partnerLev<=0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + } + } + } + else if((validate&V_GROUP_OWNER)!=0) { + if(gb.owner != acc.id) { + throw new WebException(ErrorCode.GROUP_NOT_OWNER); + } + }else { + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb==null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int count = 0; + boolean v_m_p = (validate&V_GROUP_MGR_OR_PARTNER)!=0; + + if((validate&V_GROUP_PARTNER)!=0 || v_m_p) { + if(gmb.partnerLev<=0) { + if(v_m_p) { + count ++; + }else { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + } + } + + if((validate&V_GROUP_MGR)!=0 || v_m_p) { + if(gmb.lev == 3) { + if(v_m_p) { + count ++; + }else { + throw new WebException(ErrorCode.GROUP_MGR_EXIST); + } + } + } + + if(v_m_p && count==0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + } + + + if((validate&V_GROUP_PLAY)!=0) { + int pid = reqData.getInt("pid"); + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb==null) { + throw new WebException(ErrorCode.GROUP_PLAY_EXIST); + } + } + + + } + + + + } + + + +} diff --git a/web_group/src/main/java/com/group/controller/GroupController.java b/web_group/src/main/java/com/group/controller/GroupController.java new file mode 100644 index 0000000..582b55d --- /dev/null +++ b/web_group/src/main/java/com/group/controller/GroupController.java @@ -0,0 +1,1575 @@ +package com.group.controller; + +import java.util.Set; + +import com.data.bean.AccountBean; +import com.data.bean.GroupBean; +import com.data.bean.GroupMemberBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupMemberCache; +import com.data.util.ErrorCode; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.group.Protocol; +import com.group.WebInterceptor; +import com.group.service.GroupLogService; +import com.group.service.GroupRoomService; +import com.group.service.GroupService; +import com.group.service.RSAUtils; +import com.taurus.core.entity.ITArray; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.Utils; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +import redis.clients.jedis.Jedis; + +public class GroupController extends Controller { + + /** + * 获取圈子列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_GROUPS, validate = WebInterceptor.V_SESSION) + public final void getGroups() throws Exception { + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + logger.info("jefe_test: " + acc.id); + ITArray list = GroupService.getGroups(acc.id); + ITObject resData = TObject.newInstance(); + resData.putTArray("groups", list); + sendResponse(0, resData); + } + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HP_TOTAL, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getHpTotal() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int tag = reqData.getInt("tagId"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + ITObject resData = GroupService.getPersonHpTotal(groupId, acc.id, tag); + sendResponse(0, resData); + } + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_GROUP_MEMBERS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getMembers() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); +// boolean minus_only = reqData.getBoolean("minus_only"); +// int type = reqData.getInt("type"); + ITObject resData = GroupService.getMembers(groupId, acc.id, limit, num); + sendResponse(0, resData); + } + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_ALLPLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getAllplays() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int uid = reqData.getInt("uid"); + ITObject resData = GroupService.getAllplay(groupId, uid); + sendResponse(0, resData); + } + + /** + * 设置屏蔽玩法列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.SET_BANPLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void setBanplays() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int uid = reqData.getInt("uid"); + String bans = reqData.getString("bans"); + GroupService.setBanplay(groupId, uid, bans); + this.sendResponse(0, null); + } + + @ActionKey(value = Protocol.GET_MY_MEMBERS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getMembers_1() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int type = reqData.getInt("type"); // 1-我的成员 2-全部成员 + int online = reqData.getInt("online"); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + + if (tagId == 0) { + tagId = acc.id; + } + + //////////////////////////////////////////////////////// + ITObject resData = GroupService.getMembers_1(groupId, acc.id, tagId, 0, type, limit, num); + sendResponse(0, resData); + + //////////////////////////////////////////////////////// + } + + @ActionKey(value = Protocol.GET_CHILD_MEMBERS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getMembers_child() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int type = 1; // = reqData.getInt("type"); //1-我的成员 2-全部成员 + // int online = reqData.getInt("online"); + int tagId = 0; + try { + tagId = reqData.getInt("tagId");// 目标查询id + } catch (Exception e) { + + } + + //////////////////////////////////////////////////////// + ITObject resData = GroupService.getMembers_child(groupId, acc.id, tagId, 0, type, limit, num); + sendResponse(0, resData); + + //////////////////////////////////////////////////////// + } + + @ActionKey(value = Protocol.GET_MEMBERS_COUNT, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getMembersCount() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + logger.info("查看盟主自身数据" + Protocol.GET_MEMBERS_COUNT); + + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + //////////////////////////////////////////////////////// + ITObject resData = GroupService.getMemberCount(groupId, acc.id); + sendResponse(0, resData); + + //////////////////////////////////////////////////////// + } + + /** + * 查询成员 + * + * @throws Exception + */ + @ActionKey(value = Protocol.FIND_MEMBER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void findMember() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int uid = 0; + int groupId = 0; + int tagId = 0; + int tagtype = 0; + String tagName = StringUtil.Empty; + try { + uid = AccountCache.getAccount(session).id; + groupId = reqData.getInt("id"); + tagId = reqData.containsKey("tagId") ? reqData.getInt("tagId") : 0; + tagName = reqData.containsKey("tagName") ? reqData.getUtfString("tagName") : StringUtil.Empty; + tagtype = reqData.containsKey("tagType") ? reqData.getInt("tagType") : 0; + } catch (Exception e) { + sendResponse(0, null); + return; + } + if (tagtype == 1) { + // + Integer parentid = GroupService.getParents(groupId, tagId); + logger.info("jefe parentid: " + parentid); + ITObject resData = GroupService.findMember(groupId, parentid, parentid, parentid.toString()); + sendResponse(0, resData); + } else { + ITObject resData = GroupService.findMember(groupId, uid, tagId, tagName); + sendResponse(0, resData); + } + } + + /** + * 查询成员 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.FIND_MEMBER1, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor. + * V_GROUP_MGR_OR_PARTNER) public final void findMember1() throws Exception{ + * ITObject reqData = this.getParams(); int groupId = reqData.getInt("id"); int + * tagId = reqData.getInt("tagId"); ITObject resData = + * GroupService.findMember1(groupId,tagId); sendResponse(0, resData); } + */ + + /** + * 获取合伙人 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.GET_GROUP_PARTNERS, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor. + * V_GROUP_MGR_OR_PARTNER) public final void getPartners() throws Exception { + * ITObject reqData = this.getParams(); int groupId = reqData.getInt("id"); + * String session = this.getSession(); AccountBean acc = + * AccountCache.getAccount(session); int limit = reqData.getInt("limit"); int + * num = reqData.getInt("num"); int qid = reqData.getInt("qid"); ITObject + * resData = GroupService.getPartners(groupId,acc.id,limit,num,qid); + * sendResponse(0, resData); } + */ + + /** + * 获取成员上级合伙人列表 + * + * @throws Exception + */ + /* + * 容易被黑客关注,获取到盟主ID + * + * @ActionKey(value = Protocol.GET_MEMBER_PARENTS, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor. + * V_GROUP_MGR_OR_PARTNER) public final void getMemberParents() throws Exception + * { ITObject reqData = this.getParams(); int groupId = reqData.getInt("id"); + * int tagId = reqData.getInt("tagId"); ITArray list = + * GroupService.getMemberParents(groupId, tagId); ITObject resData = + * TObject.newInstance(); resData.putTArray("parents", list); sendResponse(0, + * resData); } + */ + + /** + * 获取邀请玩家列表 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.GET_GROUP_JOINS, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + * public final void getGroupJoins() throws Exception { ITObject reqData = + * this.getParams(); int groupId = reqData.getInt("id"); + * + * ITArray array = GroupService.getGroupJoins(groupId); ITObject resData = new + * TObject(); resData.putTArray("joins", array); sendResponse(ErrorCode._SUCC, + * resData); } + */ + + /** + * 删除圈子 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.DEL_GROUP, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_OWNER) + * public final void delGroup() throws Exception { String session = + * this.getSession(); ITObject reqData = this.getParams(); int groupId = + * reqData.getInt("id"); AccountBean acc = AccountCache.getAccount(session); + * GroupService.delGroup(groupId,acc.id); this.sendResponse(0, null); } + */ + + /** + * 创建圈子 + * + * @throws Exception + */ + @ActionKey(value = Protocol.CREATE_GROUP, validate = WebInterceptor.V_SESSION) + public final void createGroup() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + String name = reqData.getString("name").trim(); + if (StringUtil.isEmpty(name)) { + throw new WebException(ErrorCode._FAILED); + } + name = StringUtil.filterEmoji(name); + if (StringUtil.isEmpty(name)) { + throw new WebException(ErrorCode._FAILED); + } + AccountBean acc = AccountCache.getAccount(session); + int type = reqData.getInt("type"); + int pay_type = reqData.getInt("pay_type"); + int num = 0; + if (reqData.containsKey("num")) { + num = reqData.getInt("num"); + } + + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + String mng = jedis0.hget(acc.redis_key, "mng"); + if (StringUtil.isEmpty(mng) || !mng.equals("2")) { + throw new WebException(ErrorCode._FAILED); + } + } finally { + jedis0.close(); + } + + ITObject info = GroupService.createGroup(name, acc.id, type, pay_type, num); + if (info != null) { + ITObject resData = TObject.newInstance(); + resData.putTObject("info", info); + this.sendResponse(0, resData); + } else { + throw new WebException(ErrorCode._FAILED); + } + } + + /** + * 创建圈子 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.STICK_GROUP, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) public final void topGroup() + * throws Exception { String session = this.getSession(); ITObject reqData = + * this.getParams(); int groupId = reqData.getInt("id"); boolean top = + * reqData.getBoolean("top"); AccountBean acc = + * AccountCache.getAccount(session); int top_time + * =GroupService.topGroup(groupId, acc.id, top); + * + * ITObject resData = TObject.newInstance(); resData.putInt("top_time", + * top_time); this.sendResponse(0, resData); } + */ + + /** + * 进入圈子 + * + * @throws Exception + */ + @ActionKey(value = Protocol.ENTER_GROUP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void enterGroup() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + AccountBean acc = AccountCache.getAccount(session); + ITObject tem = GroupService.enterGroup(groupId, acc.id); + if (tem == null) { + throw new WebException(ErrorCode._FAILED); + } +// ITObject resData = TObject.newInstance(); +// resData.putString("host", tem.getString("host")); +// ITArray arr = GroupService.getPlayList(groupId); +// resData.putTArray("playList", arr); + this.sendResponse(0, tem); + } + + /** + * 进入圈子 + * + * @throws Exception + */ + @ActionKey(value = Protocol.ENTER_GROUP_3, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void enterGroup3() throws Exception { + ITObject reqData = this.getParams(); + + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); + Integer id = Integer.parseInt(object.get("id").toString().replaceAll("\"", "")); + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + + + try { + Set banDeviceList = jedis1.smembers("bandevice"); +// logger.info("banDeviceList:" + banDeviceList); + + for (String banDevice : banDeviceList) { + if (banDevice.equalsIgnoreCase(deviceCode)) { + throw new WebException(ErrorCode._FAILED); + } + } + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + +// if(acc.id==100095) { +// Set canDeviceList = jedis1.smembers("candevice"); +//// logger.info("banDeviceList:" + banDeviceList); +// +// for (String canDevice : canDeviceList) { +// if (!canDevice.equalsIgnoreCase(deviceCode)) { +// throw new WebException(ErrorCode._FAILED); +// } +// } +// } + + ITObject tem = GroupService.enterGroup(id, acc.id); + if (tem == null) { + throw new WebException(ErrorCode._FAILED); + } +// ITObject resData = TObject.newInstance(); +// resData.putString("host", tem.getString("host")); +// ITArray arr = GroupService.getPlayList(groupId); +// resData.putTArray("playList", arr); + this.sendResponse(0, tem); + } finally { + jedis1.close(); + } + + } + + /** + * 退出圈子 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.EXIT_GROUP, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) public final void + * exitGroup() throws Exception{ ITObject reqData = this.getParams(); String + * session = this.getSession(); int groupId = reqData.getInt("id"); AccountBean + * acc = AccountCache.getAccount(session); GroupService.exitGroup(groupId, + * acc.id); this.sendResponse(0, null); } + */ + + /** + * 创建圈子玩法 + * + * @throws Exception + */ + @ActionKey(value = Protocol.ADD_PLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void addPlay() throws Exception { + ITObject reqData = this.getParams(); + + int groupId = reqData.getInt("id"); + int hpOnOff = reqData.getInt("hpOnOff"); + int groupType = reqData.getInt("gtype"); + if (hpOnOff == 0 && groupType == 2) { + throw new WebException(ErrorCode.GROUP_TYPE2_MUST_HP); + } + int gameId = reqData.getInt("gameId"); + ITObject config = reqData.getTObject("config"); + String name = reqData.getString("name"); + int deskId = reqData.containsKey("deskId") ? reqData.getInt("deskId") : 0; + ITObject hpData = reqData.getTObject("hpData"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + ITObject obj = GroupService.addPlay(groupId, gameId, name, deskId, config, hpData, hpOnOff, acc.id); + + this.sendResponse(0, obj); + + } + + /** + * 创建圈子玩法 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_PLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR | WebInterceptor.V_GROUP_PLAY) + public final void updatePlay() throws Exception { + ITObject reqData = this.getParams(); + + int groupId = reqData.getInt("id"); + int groupType = reqData.getInt("gtype"); + int hpOnOff = reqData.getInt("hpOnOff"); + if (hpOnOff == 0 && groupType == 2) { + throw new WebException(ErrorCode.GROUP_TYPE2_MUST_HP); + } + int pid = reqData.getInt("pid"); + int gameId = reqData.getInt("gameId"); + ITObject config = reqData.getTObject("config"); + String name = reqData.getString("name"); + ITObject hpData = reqData.getTObject("hpData"); + int deskId = reqData.containsKey("deskId") ? reqData.getInt("deskId") : 0; + + GroupService.updatePlay(groupId, pid, gameId, name, deskId, config, hpData, hpOnOff); + int maxPlayers = config.getInt("maxPlayers"); + int maxRound = config.getInt("maxRound"); + + ITObject params = TObject.newInstance(); + params.putInt("maxPlayers", maxPlayers); + params.putInt("maxRound", maxRound); + + this.sendResponse(0, params); + } + + /** + * 删除圈子玩法 + * + * @throws Exception + */ + @ActionKey(value = Protocol.DEL_PLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER | WebInterceptor.V_GROUP_PLAY) + public final void delPlay() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + int result = GroupService.delPlay(groupId, pid); + this.sendResponse(result, null); + } + + /** + * 加入圈子 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.JOIN_GROUP, validate = WebInterceptor.V_SESSION) + * public final void applyGroup() throws Exception { String session = + * this.getSession(); ITObject reqData = this.getParams(); AccountBean acc = + * AccountCache.getAccount(session); int result = + * GroupService.applyGroup(reqData.getInt("id"), acc.id); sendResponse(result, + * null); } + */ + + /** + * 审核加入圈子 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.VERIFY_JOIN_GROUP, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + * public final void verifyJoinGroup() throws Exception { String session = + * this.getSession(); ITObject reqData = this.getParams(); AccountBean acc = + * AccountCache.getAccount(session); int uid = acc.id; int groupId = + * reqData.getInt("id"); int tagId = reqData.getInt("tagId"); if(acc.id == + * tagId) { throw new WebException(ErrorCode._FAILED); } boolean allow = + * reqData.getBoolean("allow"); int result + * =GroupService.verifyJoinGroup(groupId, uid, tagId, allow); if(result!=0) { + * throw new WebException(result); } this.sendResponse(0, null); } + */ + + /** + * 添加成员 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_PLAYER_INFO, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void getPlayerInfo() throws Exception { + ITObject reqData = this.getParams(); + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(tagId); + if (acc == null) { + sendResponse(ErrorCode._FAILED, null); + return; + } + + ITObject obj = TObject.newInstance(); + obj.putInt("uid", tagId); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + sendResponse(0, obj); + } + + /** + * 添加成员 + * + * @throws Exception + */ + @ActionKey(value = Protocol.INVITE_GROUP_MEMBER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void addMember() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + AccountBean acc = AccountCache.getAccount(session); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int result = GroupService.addMember(groupId, acc.id, tagId); + if (result != 0) { + throw new WebException(result); + } + this.sendResponse(0, null); + } + + /** + * 删除成员 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_KICK, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void delMember() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + AccountBean acc = AccountCache.getAccount(session); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + + GroupService.delMember(groupId, acc.id, tagId); + + this.sendResponse(0, null); + } + + @ActionKey(value = Protocol.GET_KICK_LOG, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getKickLog() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + AccountBean acc = AccountCache.getAccount(session); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + + ITArray arr = GroupService.getKickLog(groupId, acc.id, limit, num); + + ITObject rspData = new TObject(); + rspData.putTArray("data", arr); + + this.sendResponse(0, rspData); + + logger.info("getKickLog: " + rspData); + } + + /** + * 禁止娱乐 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_BAN_MEMBER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void banMember() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + int ban = reqData.getInt("ban"); + int optType = reqData.getInt("opType"); + AccountBean acc = AccountCache.getAccount(session); + GroupService.banMember(groupId, acc.id, tagId, optType, ban); + this.sendResponse(0, null); + } + + /** + * 禁止娱乐 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_BLACK_MEMBER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void blackMember() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + int ban = reqData.getInt("ban"); + int ban_rate = reqData.getInt("ban_rate"); + int ban_value = reqData.getInt("ban_max_value"); + int optType = reqData.getInt("opType"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id == tagId) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + GroupService.blackMember(groupId, acc.id, tagId, optType, ban, ban_rate, ban_value); + // GroupService.blackPartner(groupId,acc.id, tagId, optType, ban, ban_rate, + // ban_value); + ITObject resData = TObject.newInstance(); + resData.putInt("ban", ban); + resData.putInt("playerid", acc.id); + resData.putInt("groupid", groupId); + resData.putInt("ban_rate", ban_rate); + resData.putInt("ban_max_value", ban_value); + resData.putInt("ban_value", 0); + this.sendResponse(0, resData); + } + + /** + * 禁止娱乐 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_BLACK_MEMBER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getBlackMember() throws Exception { + ITObject reqData = this.getParams(); + logger.info("set begin:" + reqData); + + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + String gm_key = GroupMemberCache.genKey(groupId, tagId); + ITObject resData = TObject.newInstance(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + String black_key = jedis10.hget(gm_key, "group_black_key"); + if (StringUtil.isEmpty(black_key)) { + black_key = gm_key; + } + + String black = jedis10.hget(black_key, "black"); + String group_black = jedis10.hget(black_key, "group_black"); + + String black_rate = jedis10.hget(black_key, "group_black_rate"); + if (StringUtil.isEmpty(black_rate)) { + black_rate = "0"; + } + + String black_max_value = jedis10.hget(black_key, "group_black_max_value"); + if (StringUtil.isEmpty(black_max_value)) { + black_max_value = "0"; + } + + String black_value = jedis10.hget(black_key, "group_black_now_value"); + if (StringUtil.isEmpty(black_value)) { + black_value = "0"; + } + + resData.putInt("ban_rate", Integer.parseInt(black_rate)); + resData.putInt("ban_max_value", Integer.parseInt(black_max_value)); + resData.putInt("ban_value", Integer.parseInt(black_value)); + + if (StringUtil.isNotEmpty(black) && black.equals("0")) { + resData.putInt("black", 0); + } else if (StringUtil.isNotEmpty(black) && black.equals("1")) { + resData.putInt("black", 1); + } else if (StringUtil.isNotEmpty(black) && black.equals("2")) { + resData.putInt("black", 2); + } else { + resData.putInt("black", 0); + } + + if (StringUtil.isNotEmpty(group_black) && group_black.equals("0")) { + resData.putInt("group_black", 0); + } else if (StringUtil.isNotEmpty(group_black) && group_black.equals("1")) { + resData.putInt("group_black", 1); + } else if (StringUtil.isNotEmpty(group_black) && group_black.equals("2")) { + resData.putInt("group_black", 2); + } else { + resData.putInt("group_black", 0); + } + } finally { + jedis10.close(); + } + + logger.info("set end:" + reqData); + resData.putInt("playerid", tagId); + resData.putInt("groupid", groupId); + this.sendResponse(0, resData); + } + + /** + * 玩法禁止娱乐 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_BAN_PLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER | WebInterceptor.V_GROUP_PLAY) + public final void banPlay() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + int ban = reqData.getInt("ban"); + GroupService.banPlay(groupId, pid, ban); + this.sendResponse(0, null); + } + + /** + * 标识玩法 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_MARK_PLAY, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER | WebInterceptor.V_GROUP_PLAY) + public final void markPlay() throws Exception { + ITObject reqData = this.getParams(); + + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + boolean mark = reqData.getBoolean("mark"); + int iMark = mark ? 1 : 0; + + int count = GroupService.getMarkedPlayCount(groupId); + if (iMark == 1) { + if (count >= 5) { + this.sendResponse(1, null); + return; + } + } + + logger.info("GROUP_MARK_PLAY count = " + count); + + GroupService.markPlay(groupId, pid, iMark); + + logger.info("GROUP_MARK_PLAY count ================> OK"); + + this.sendResponse(0, null); + } + + /** + * 更改圈子信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_UPDATE_INFO, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void updateGroupInfo() throws Exception { + ITObject reqData = this.getParams(); + String name = reqData.getString("name").trim(); + if (StringUtil.isEmpty(name)) { + throw new WebException(ErrorCode._FAILED); + } + name = StringUtil.filterEmoji(name); + if (StringUtil.isEmpty(name)) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); +// boolean ban = reqData.getBoolean("ban"); +// String notice = reqData.getString("notice"); +//// boolean ban_ip = reqData.getBoolean("ban_ip"); +//// boolean ban_gps = reqData.getBoolean("ban_gps"); +// int dissolve_opt = reqData.getInt("dissolve_opt"); +// int kick_opt = reqData.getInt("kick_opt"); +// int ban_apply = reqData.getInt("ban_apply"); + + GroupService.updateGroupInfo(groupId, name, reqData); + this.sendResponse(0, null); + } + + /** + * 更改圈子信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_SET_MEMBER_MGR, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void updateMgrLev() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + // 1 设置管理员 2 取消管理员 + int opt = reqData.getInt("opt"); + ITObject resData = GroupService.updateMemberMgr(groupId, tagId, opt); + this.sendResponse(0, resData); + } + + /** + * 更改圈子信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_SET_PARTNER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void setParent() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + // 1 设置管理员 2 取消管理员 + int opt = reqData.getInt("opt"); + ITObject resData = TObject.newInstance(); + if (opt == 2) { + resData = GroupService.cancelParent(groupId, acc.id, tagId); + } else { + resData = GroupService.setParent(groupId, acc.id, tagId); + } + + this.sendResponse(0, resData); + } + + /** + * 设置玩法奖励 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_SET_REWARD, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void setReward() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + int value = reqData.getInt("value"); + int pid = reqData.getInt("pid"); + int partnerLev = reqData.getInt("partnerLev"); + boolean all = reqData.getBoolean("all"); + int isSingle = 0; + try { + isSingle = reqData.getInt("single"); // 0:all 1:单局 + } catch (Exception e) { + + } + int result = GroupService.setReward(groupId, acc.id, tagId, partnerLev, pid, value, all, isSingle); + this.sendResponse(result, null); + } + + /** + * 设置洗牌玩法奖励 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_SET_XIPAI_REWARD, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void setXiPaiReward() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + int value = reqData.getInt("value"); + int pid = reqData.getInt("pid"); + int partnerLev = reqData.getInt("partnerLev"); + boolean all = reqData.getBoolean("all"); + int isSingle = 0; + try { + isSingle = reqData.getInt("single"); // 0:all 1:单局 + } catch (Exception e) { + + } + int result = GroupService.setXiPaiReward(groupId, acc.id, tagId, partnerLev, pid, value, all, isSingle); + this.sendResponse(result, null); + } + + /** + * 获取玩法奖励列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_REWARDS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getRewards() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); +// if(acc.id == tagId) { +// throw new WebException(ErrorCode._FAILED); +// } + + int groupId = reqData.getInt("id"); + int partnerLev = reqData.getInt("partnerLev"); + ITObject resData = TObject.newInstance(); + GroupService.getRewards(groupId, acc.id, tagId, partnerLev, resData); + + this.sendResponse(0, resData); + ; + } + + /** + * 更新我成员体力值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_MEMBER_HP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER | WebInterceptor.V_GROUP_CHECK_ROOM) + public final void updateMemberHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int hp = 0; + try { + hp = reqData.getInt("hp"); + } catch (Exception e) { + logger.info("jefe_test: " + e); + throw new WebException(ErrorCode._FAILED); + } + if (hp == 0) { + throw new WebException(ErrorCode._FAILED); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + int tag = reqData.getInt("tag"); + AccountBean acc = AccountCache.getAccount(session); + try { + // 正在游戏不允许下分操作 + if (hp < 0) { + if (GroupRoomService.checkRoom(groupId, acc.id)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + if (GroupRoomService.checkRoom(groupId, tag)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + } + + String uidKey = GroupMemberCache.genKey(groupId, acc.id); + long uid_hp = Long.parseLong(jedis10.hget(uidKey, "hp")); + if (uid_hp > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); + } + + String tagKey = GroupMemberCache.genKey(groupId, tag); + long tag_hp = Long.parseLong(jedis10.hget(tagKey, "hp")); + + if (tag_hp > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_OTHER_HP_THAN_LIMIET); + } + + if (acc.id != tag) { + if (hp < 0) { + if ((long) uid_hp + (long) Math.abs(hp) > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); + } + + if ((long) tag_hp < Math.abs(hp)) { + throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP); + } + } else if (hp > 0) { + if ((long) uid_hp < hp) { + throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP); + } + + if ((long) tag_hp + (long) Math.abs(hp) > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_OTHER_HP_THAN_LIMIET); + } + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, acc.id); + if (mng_bean != null && mng_bean.lev == 1) { + + GroupService.updateMemberHp(groupId, acc.id, acc.id, -hp, true, tag); + } + } else { + if (hp < 0) { + if ((long) uid_hp < Math.abs(hp)) { + throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP); + } + } else if (hp > 0) { + + if ((long) uid_hp + (long) Math.abs(hp) > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); + } + } + } + } catch (Exception e) { + throw e; + } finally { + jedis10.close(); + } + ITObject resData = GroupService.updateMemberHp(groupId, acc.id, tag, hp, false, 0); + this.sendResponse(0, resData); + } + + /** + * 更新我成员体力值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_MEMBER_SCORE, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER | WebInterceptor.V_GROUP_CHECK_ROOM) + public final void updateMemberScore() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int score = reqData.getInt("score"); + + int tag = reqData.getInt("tag"); + AccountBean acc = AccountCache.getAccount(session); + GroupService.updateMemberScore(groupId, acc.id, tag, score); + this.sendResponse(0, null); + } + + /** + * 更新我成员体力值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_MEMBER_QUEUEID, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER | WebInterceptor.V_GROUP_CHECK_ROOM) + public final void updateMemberQueueid() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int queueid = reqData.getInt("queueid"); + + int tag = reqData.getInt("tag"); + AccountBean acc = AccountCache.getAccount(session); + GroupService.updateMemberQueue(groupId, acc.id, tag, queueid); + this.sendResponse(0, null); + } + +// /** +// * 调控幸运值 +// * +// * @throws Exception +// */ +// @ActionKey(value = Protocol.UPDATE_MEMBER_DIAOKONG, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP +// | WebInterceptor.V_GROUP_MGR_OR_PARTNER | WebInterceptor.V_GROUP_CHECK_ROOM) +// public final void updateMemberDiaokong() throws Exception { +// ITObject reqData = this.getParams(); +// String session = this.getSession(); +// int groupId = reqData.getInt("id"); +// int queueid = reqData.getInt("queueid"); +// +// int tag = reqData.getInt("tag"); +// AccountBean acc = AccountCache.getAccount(session); +// GroupService.updateMemberDiaokong(groupId, acc.id, tag, queueid); +// this.sendResponse(0, null); +// } + + /** + * 更新我成员查看值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_MEMBER_SEEID, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER | WebInterceptor.V_GROUP_CHECK_ROOM) + public final void updateMemberSeeid() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int seeid = reqData.getInt("seeid"); + + int tag = reqData.getInt("tag"); + AccountBean acc = AccountCache.getAccount(session); + GroupService.updateMemberSee(groupId, acc.id, tag, seeid); + this.sendResponse(0, null); + } + + /** + * 获取能量包信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.TRADE_TAKE_INFO, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER_OR_MGR_OR_PARTNER) + public final void getTakeInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + + AccountBean acc = AccountCache.getAccount(session); + if (tagId == 0) { + tagId = acc.id; + } + ITObject resData = GroupService.getTakeInfo(groupId, acc.id, tagId); + this.sendResponse(0, resData); + } + + /** + * 提取体力值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.TAKE_HP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_CHECK_ROOM | WebInterceptor.V_GROUP_OWNER_OR_MGR_OR_PARTNER) + public final void takeHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int hp = reqData.getInt("hp"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + if (tagId == 0) { + tagId = acc.id; + } + ITObject resData = GroupService.takeHp(groupId, acc.id, tagId, hp); + this.sendResponse(0, resData); + } + + /** + * 盟主强行提取体力值 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_TAKE_HP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void groupTakeHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + GroupService.groupTakeHp(groupId, acc.id, tagId); + this.sendResponse(0, null); + } + + @ActionKey(value = Protocol.GET_BANK_HP, validate = WebInterceptor.V_SESSION + | WebInterceptor.V_GROUP/* |WebInterceptor.V_GROUP_PARTNER */) + public final void getBankHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + if (tagId == 0) { + tagId = acc.id; + } + ITObject resData = GroupService.getBankInfo(groupId, acc.id, tagId); + this.sendResponse(0, resData); + } + + @ActionKey(value = Protocol.TAKE_BANK_HP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_CHECK_ROOM/* |WebInterceptor.V_GROUP_PARTNER */) + public final void takeBankHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int hp = reqData.getInt("hp"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + if (tagId == 0) { + tagId = acc.id; + } + ITObject resData = GroupService.takeBankHp(groupId, acc.id, tagId, hp); + this.sendResponse(0, resData); + } + + @ActionKey(value = Protocol.SAVE_BANK_HP, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_CHECK_ROOM/* |WebInterceptor.V_GROUP_PARTNER */) + public final void saveBankHp() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int hp = reqData.getInt("hp"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } catch (Exception e) { + + } + if (tagId == 0) { + tagId = acc.id; + } + ITObject resData = GroupService.saveBankHp(groupId, acc.id, tagId, hp); + this.sendResponse(0, resData); + } + + /** + * 分配成员 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.DISTRIBUTE_MEMBER, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + * public final void distributeMember() throws Exception { ITObject reqData = + * this.getParams(); int groupId = reqData.getInt("id"); int parId = + * reqData.getInt("parId"); int tagId = reqData.getInt("tagId"); + * GroupService.distributeMember(groupId, parId, tagId); this.sendResponse(0, + * null); } + */ + + /** + * 获取合伙人管理列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_PARTNER_INFOS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getPartnerInfos() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + + int limit = 0; + int num = 0; + + int simpleAll = reqData.getInt("simple_all"); + if (simpleAll == 0) { + limit = reqData.getInt("limit"); + num = reqData.getInt("num"); + } + + boolean diff = false; + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + if (tagId > 0) { + diff = true; + } + } catch (Exception e) { + + } + + AccountBean acc = AccountCache.getAccount(session); + if (tagId == 0) { + tagId = acc.id; + } + + ITObject resData = GroupService.getPartnerInfos(groupId, acc.id, tagId, limit, num, simpleAll, diff); + sendResponse(0, resData); + } + + /** + * 获取合伙人管理列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.QUERY_PARTNER_INFOS, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void queryPartnerInfos() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + + int qid = 0; + String tagName = StringUtil.Empty; + try { + qid = reqData.getInt("qid"); + tagName = reqData.getUtfString("tagName"); + } catch (Exception e) { + sendResponse(0, null); + return; + } + + AccountBean acc = AccountCache.getAccount(session); + ITObject resData = GroupService.queryPartnerInfos(groupId, acc.id, qid, tagName); + sendResponse(0, resData); + } + + /** + * 获取合伙人管理列表 + * + * @throws Exception + */ + /* + * @ActionKey(value = Protocol.GET_PARTNER_MEMBERS, validate = + * WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor. + * V_GROUP_MGR_OR_PARTNER) public final void getPartnerMemebers() throws + * Exception { ITObject reqData = this.getParams(); int groupId = + * reqData.getInt("id"); int tagId = reqData.getInt("tagId"); int limit = + * reqData.getInt("limit"); int num = reqData.getInt("num"); int qid = + * reqData.getInt("qid"); ITObject resData + * =GroupService.getPartnerMemebers(groupId, tagId, limit, num,qid); + * sendResponse(0, resData); } + */ + + /** + * 设置合伙人上下分开关 + * + * @throws Exception + */ + @ActionKey(value = Protocol.SET_MGR_PERMISSION, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void setMgrPermission() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + int permission = reqData.getInt("permission"); + GroupService.setMgrPermission(groupId, tagId, permission); + sendResponse(0, null); + } + + /** + * 获取禁止同桌列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_BAN_DESK_LIST, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR) + public final void getBanDeskList() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int tagId = reqData.getInt("tagId"); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + ITArray arr = GroupService.getBanDeskList(groupId, acc.id, tagId); + ITObject resData = TObject.newInstance(); + resData.putTArray("ban_list", arr); + sendResponse(0, resData); + } + + /** + * 设置禁止同桌 + * + * @throws Exception + */ + @ActionKey(value = Protocol.SET_BAN_DESK, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR) + public final void setBanDesk() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int tagId = reqData.getInt("tagId"); + if (acc.id == tagId) { + throw new WebException(ErrorCode._FAILED); + } + int groupId = reqData.getInt("id"); + ITArray ban_list = reqData.getTArray("ban_list"); + ITArray del_list = reqData.getTArray("del_list"); + + GroupService.setBanDesk(groupId, acc.id, tagId, ban_list, del_list); + sendResponse(0, null); + } + + /** + * 转移合伙人 + * + * @throws Exception + */ + @ActionKey(value = Protocol.MOVE_PARTNER, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void movePartner() throws Exception { + ITObject reqData = this.getParams(); + int tagId = reqData.getInt("tagId"); + int parId = reqData.getInt("parId"); + int groupId = reqData.getInt("id"); + ITObject resData = GroupService.movePartner(groupId, parId, tagId); + sendResponse(0, resData); + } + + /** + * 获取邮件列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_MAIL_LIST, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void getMailList() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int uid = reqData.getInt("uid"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id != uid) { + throw new WebException(ErrorCode._FAILED); + } + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + ITArray arr = GroupService.getMailList(groupId, uid, limit, num); + ITObject resData = TObject.newInstance(); + resData.putTArray("mail_list", arr); + sendResponse(0, resData); + } + + /** + * 删除所有邮件 + * + * @throws Exception + */ + @ActionKey(value = Protocol.DEL_MAIL_ALL, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void delMailAll() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int uid = reqData.getInt("uid"); + AccountBean acc = AccountCache.getAccount(session); + if (acc.id != uid) { + throw new WebException(ErrorCode._FAILED); + } + GroupService.delMailAll(groupId, uid); + sendResponse(0, null); + } + + /** + * 设置阀值 + */ + @ActionKey(value = Protocol.SET_AUTO_SCORE, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void setPartenerAutoScore() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("uid"); + int score = reqData.getInt("score"); + AccountBean acc = AccountCache.getAccount(session); + int result = GroupService.setPartenerAutoScore(groupId, acc.id, tagId, score); + if (result == 0) { + this.sendResponse(-1, null); + } else { + this.sendResponse(0, null); + } + } + + @ActionKey(value = Protocol.GET_XINGYUNHAO_INFO, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP + | WebInterceptor.V_GROUP_OWNER) + public final void getXingyunhaoInfo() throws Exception { + ITObject reqData = this.getParams(); + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if (tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.getXingYunHaoMember(groupId, limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + /** + * 重置用户密码 + */ + @ActionKey(value = Protocol.GROUP_RESET_PASSWORD, validate = WebInterceptor.V_SESSION | WebInterceptor.V_GROUP) + public final void resetPassword() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int tagId = reqData.getInt("tagId"); + String password = reqData.getString("password"); + +// AccountBean acc = AccountCache.getAccount(session); + String sql = "UPDATE account SET password='" + Utils.getMD5Hash(password) + "' where id=" + tagId; + DataBase.use().executeUpdate(sql); + this.sendResponse(0, null); + } +} \ No newline at end of file diff --git a/web_group/src/main/java/com/group/controller/GroupLogController.java b/web_group/src/main/java/com/group/controller/GroupLogController.java new file mode 100644 index 0000000..318ee61 --- /dev/null +++ b/web_group/src/main/java/com/group/controller/GroupLogController.java @@ -0,0 +1,658 @@ +package com.group.controller; + +import com.data.bean.AccountBean; +import com.data.bean.GroupMemberBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.util.ErrorCode; +import com.data.util.Utility; +import com.group.Protocol; +import com.group.WebInterceptor; +import com.group.service.GroupLogService; +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.routes.ActionKey; +import com.taurus.web.Controller; +import com.taurus.web.WebException; +import redis.clients.jedis.Jedis; + +import java.util.List; + +public class GroupLogController extends Controller{ + + /** + * 获取奖励日志 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_REWARD_LOG, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getRewardLog() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + int tagId = reqData.getInt("tagId"); + AccountBean acc = AccountCache.getAccount(session); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, acc.id); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && acc.id != tagId) + { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(acc.id)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + finally { + jedis10.close(); + } + + ITObject resData = GroupLogService.getRewardLog(groupId, tagId, limit, num, beginTime, endTime); + sendResponse(0, resData); + } + + /** + * 获取奖励统计 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_REWARD_COUNT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_OWNER) + public final void getRewardLogCount() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + ITObject resData = GroupLogService.getRewardLogCount(groupId,pid, beginTime, endTime); + sendResponse(0, resData); + } + + + /** + * 获取体力值管理统计数据 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_MGR, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getHpLogMgr() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + AccountBean acc = AccountCache.getAccount(session); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + // 类型 type 1上分 2下分 3合伙人上分 4合伙人下分 + int type = reqData.getInt("type"); + int qid = reqData.getInt("qid"); + String tagName = reqData.getUtfString("tagName"); + ITObject resData = GroupLogService.getHpLogMgr(groupId, acc.id, limit, num, type, qid, tagName); + sendResponse(0, resData); + } + + /** + * 获取体力值管理统计数据 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_MGR_COUNT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + public final void getHpLogMgrCount() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + ITObject resData = GroupLogService.getHpLogMgrCount(groupId); + sendResponse(0, resData); + } + + /** + * 获取体力值管理员详细信息 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_MGR_INFO, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getHpLogMgrInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int groupId = reqData.getInt("id"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + //1 管理员 2合伙人 + int type = reqData.getInt("type"); + + ITArray arr = GroupLogService.getHpLogMgrInfo(groupId,acc.id,beginTime,endTime,type); + ITObject resData = TObject.newInstance(); + resData.putTArray("infos", arr); + sendResponse(0, resData); + } + + /** + * 获取玩家体力值详细 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_INFO, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getHpLogInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int tagId = reqData.getInt("tagId"); + int endTime = reqData.getInt("endTime"); + int beginTime = reqData.getInt("beginTime"); + // 筛选 + int choose = reqData.getInt("choose"); + AccountBean acc = AccountCache.getAccount(session); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, acc.id); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && acc.id != tagId) + { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(acc.id)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + finally { + jedis10.close(); + } + + ITObject resData = GroupLogService.getHpLogInfo(groupId, tagId, limit, num, choose,beginTime,endTime); + sendResponse(0, resData); + } + + /** + * 获取玩家体力值详细 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_DETAIL_INFO, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getHpLogDetailInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int groupId = reqData.getInt("id"); + int tagId = reqData.getInt("tagId"); + String roomId = reqData.getUtfString("roomId"); + int time = reqData.getInt("time"); + AccountBean acc = AccountCache.getAccount(session); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, acc.id); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && acc.id != tagId) + { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(acc.id)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + finally { + jedis10.close(); + } + + ITObject resData = GroupLogService.getHpLogDetailInfo(groupId, tagId, roomId, time); + sendResponse(0, resData); + } + + + /** + * 获取抽水体力值详细 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_HPLOG_PUMP, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + public final void getHpLogPumpInfo() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + ITObject resData = GroupLogService.getHpLogPumpInfo(groupId,acc.id, limit, num, beginTime, endTime); + sendResponse(0, resData); + } + + /** + * 获取玩法局数统计 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_MEMBER_RANK, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void getMemberRank() throws Exception { + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + ITObject reqData = this.getParams(); + + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + + int type = 0; + if (reqData.containsKey("type")) + { + try { + type = reqData.getInt("type"); + } + catch (Exception e) + { + + } + } + ITObject resData = GroupLogService.getMemberRank(groupId, acc.id, pid, type, limit, num, beginTime, endTime); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_GET_MEMBER_STAT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getMemberStat() throws Exception { + + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int qid = reqData.getInt("qid"); + int partnerId = reqData.getInt("partner_id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 3) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + int sortType = reqData.getInt("sortType"); + ITObject resData = GroupLogService.getMemberStat(groupId,acc.id,qid,partnerId, limit, num, tt, beginTime, endTime,sortType); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_GET_PARTNER_STAT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getPartnerStat() throws Exception { + + ITObject reqData = this.getParams(); + + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + int groupId = reqData.getInt("id"); + + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + + int tt = reqData.getInt("tt"); + //tt = 1; + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.getPartnerStat(groupId, acc.id,limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_FIND_PARTNER_STAT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void findPartnerStat() throws Exception { + + ITObject reqData = this.getParams(); + + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + + int groupId = reqData.getInt("id"); + + int tagId = reqData.getInt("tagId"); + + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.findPartnerStat(groupId, acc.id, tagId, limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_GET_PARTNER_STAT_MEMBER, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getPartnerStatMember() throws Exception { + + ITObject reqData = this.getParams(); + + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int uid = reqData.getInt("uid"); + int rootUid = reqData.getInt("root_uid"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.getPartnerStatMember(groupId, uid, rootUid, limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_FIND_PARTNER_STAT_MEMBER, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void findPartnerStatMember() throws Exception { + + ITObject reqData = this.getParams(); + + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int uid = reqData.getInt("uid"); + int rootUid = reqData.getInt("root_uid"); + int tagId = reqData.getInt("tagId"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.findPartnerStatMember(groupId, uid, rootUid, tagId, limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + @ActionKey(value = Protocol.GROUP_GET_DIRECT_STAT_MEMBER, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getDirectStatMember() throws Exception { + + ITObject reqData = this.getParams(); + + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int uid = reqData.getInt("uid"); + int rootUid = reqData.getInt("root_uid"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.getDirectStatMember(groupId, uid, rootUid, limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + + @ActionKey(value = Protocol.GROUP_GET_PARTNER_STAT_PLAY, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getPartnerStatPlay() throws Exception { + + ITObject reqData = this.getParams(); + + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + int num = reqData.getInt("num"); + int uid = reqData.getInt("uid"); + int parent_id = reqData.getInt("parent_id"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + + ITObject resData = GroupLogService.getPartnerStatPlay(groupId, uid,parent_id,limit, num, tt, beginTime, endTime); + sendResponse(0, resData); + } + + + /** + * 获取消耗统计 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_COST_COUNT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getCostCount() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + int uid = AccountCache.getAccount(session).id; + int groupId = reqData.getInt("id"); + int beginTime = 0; + int endTime = 0; + try { + beginTime = reqData.getInt("beginTime"); + endTime = reqData.getInt("endTime"); + } + catch (Exception e) + { + + } + ITObject resData = TObject.newInstance(); + resData.putTArray("cosume_logs", GroupLogService.getCostCount(groupId, uid, beginTime, endTime)); + sendResponse(0, resData); + } + + /** + * 获取消耗统计 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_ROUND_COUNT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void getRoundCount() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + ITArray arr = GroupLogService.getRoundCount(groupId,pid); + ITObject resData = TObject.newInstance(); + resData.putTArray("rounds", arr); + sendResponse(0, resData); + } + + /** + * 获取消耗统计 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_HPCONSUME_COUNT, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void getHpConsumeCount() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int tag = reqData.getInt("tagId"); + ITArray arr = GroupLogService.getHpConsumeCount(groupId,tag); + ITObject resData = TObject.newInstance(); + resData.putTArray("list", arr); + sendResponse(0, resData); + } + + /** + * 获取战绩列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_RECORDS, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void getRecords() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + + int uid = AccountCache.getAccount(session).id; + String platform = reqData.getString("platform"); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int qid = reqData.getInt("qid"); + int includeMembers = reqData.containsKey("includeMembers") ? reqData.getInt("includeMembers") : 0; + int tt = -1; + int beginTime = 0; + int endTime = 0; + if(reqData.containsKey("tt")) { + tt = reqData.getInt("tt"); + if(tt == 0) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + } + ITObject resData =GroupLogService.getRecords(platform, groupId, limit, num,qid,uid,includeMembers,tt,beginTime,endTime); + sendResponse(0, resData); + } + + /** + * 获取战绩列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_GET_PERSON_RECORDS, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void getPersonRecords() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + + int uid = AccountCache.getAccount(session).id; + String platform = reqData.getString("platform"); + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int qid = reqData.getInt("qid"); + int tt = reqData.getInt("tt"); + int beginTime = 0; + int endTime = 0; + if(tt == 3) { + beginTime = reqData.getInt("bt"); + endTime = reqData.getInt("et"); + } + ITObject resData =GroupLogService.getPersonRecords(platform, groupId, tt, beginTime, endTime, limit, num, qid, uid); + sendResponse(0, resData); + } + + + /** + * 根据房间ID查询战绩 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_FIND_RECORD_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR_OR_PARTNER) + public final void findRecordByRoom() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + + int uid = AccountCache.getAccount(session).id; + String platform = reqData.getString("platform"); + int groupId = reqData.getInt("id"); + String roomid = reqData.getString("roomid"); + ITArray data = GroupLogService.findRecordByRoom(platform, groupId, roomid,uid); + ITObject resData = TObject.newInstance(); + resData.putBoolean("is_rec", data!=null && data.size() != 0); + if(data != null) { + resData.putTArray("rec", data); + } + sendResponse(0, resData); + } + + /** + * 获取提取体力值详细 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_TAKE_LOG, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_OWNER_OR_MGR_OR_PARTNER) + public final void getHpLogTakeInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } + catch(Exception e) { + + } + if (tagId == 0) + { + tagId = acc.id; + } + ITObject resData = GroupLogService.getHpLogTakeInfo(groupId, acc.id, tagId, limit, num, beginTime, endTime); + sendResponse(0, resData); + } + + /** + * 获取提取体力值详细 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_BANK_LOG, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP/*|WebInterceptor.V_GROUP_PARTNER*/) + public final void getHpLogTakeBankInfo() throws Exception { + ITObject reqData = this.getParams(); + String session = this.getSession(); + + int groupId = reqData.getInt("id"); + int limit = reqData.getInt("limit"); + // 数量 + int num = reqData.getInt("num"); + int beginTime = reqData.getInt("beginTime"); + int endTime = reqData.getInt("endTime"); + AccountBean acc = AccountCache.getAccount(session); + int tagId = 0; + try { + tagId = reqData.getInt("tagId"); + } + catch(Exception e) { + + } + if (tagId == 0) + { + tagId = acc.id; + } + ITObject resData = GroupLogService.getHpLogTakeBankInfo(groupId, acc.id, tagId, limit, num, beginTime, endTime); + sendResponse(0, resData); + } + + /** + * 获取体力值统计信息 + */ + @ActionKey(value = Protocol.GET_HP_COUNT_INFO, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_MGR) + public final void getHpCountInfo() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + ITObject resData =GroupLogService.getHpCountInfo(groupId); + sendResponse(0, resData); + } +} diff --git a/web_group/src/main/java/com/group/controller/GroupRoomController.java b/web_group/src/main/java/com/group/controller/GroupRoomController.java new file mode 100644 index 0000000..d539b70 --- /dev/null +++ b/web_group/src/main/java/com/group/controller/GroupRoomController.java @@ -0,0 +1,66 @@ +package com.group.controller; + +import com.group.Protocol; +import com.group.WebInterceptor; +import com.group.service.GroupRoomService; +import com.taurus.core.entity.ITObject; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.ActionKey; +import com.taurus.web.Controller; +import com.taurus.web.WebException; +import jdk.nashorn.internal.objects.Global; +import redis.clients.jedis.Jedis; + +public class GroupRoomController extends Controller{ + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_MATCH_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void matchRoom() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + int pid = reqData.getInt("pid"); + String platform = reqData.getString("platform"); + boolean is_null = reqData.containsKey("is_null")? reqData.getBoolean("is_null"):false; + + logger.info("matchRoom() ==> pid = "+pid); + + ITObject resData = GroupRoomService.matchRoom(groupId, pid, session,platform,is_null); + this.sendResponse(0, resData); + } + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_JOIN_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP) + public final void joinRoom() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + String roomid = reqData.getString("room_id"); + String platform = reqData.getString("platform"); + + ITObject resData = GroupRoomService.joinRoom(groupId, roomid, session,platform); + this.sendResponse(0, resData); + } + + /** + * 获取玩家列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GROUP_DEL_ROOM, validate = WebInterceptor.V_SESSION|WebInterceptor.V_GROUP|WebInterceptor.V_GROUP_OWNER) + public final void delRoom() throws Exception { + ITObject reqData = this.getParams(); + int groupId = reqData.getInt("id"); + String roomId = reqData.getString("roomId"); + ITObject obj = GroupRoomService.delRoom(groupId, roomId); + this.sendResponse(0, obj); + } +} diff --git a/web_group/src/main/java/com/group/job/UpdatePlayRoomJob.java b/web_group/src/main/java/com/group/job/UpdatePlayRoomJob.java new file mode 100644 index 0000000..5ae4372 --- /dev/null +++ b/web_group/src/main/java/com/group/job/UpdatePlayRoomJob.java @@ -0,0 +1,843 @@ +package com.group.job; + +import com.data.bean.*; +import com.data.cache.*; +import com.data.util.ErrorCode; +import com.data.util.EventType; +import com.data.util.Utility; +import com.google.protobuf.ByteString; +import com.group.service.GroupPublisherService; +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.plugin.redis.RedisLock; +import com.taurus.core.util.*; +import com.taurus.web.WebException; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobKey; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.ScanParams; +import redis.clients.jedis.ScanResult; +import com.taurus.core.util.StringUtil; +import java.io.InputStream; +import java.net.URL; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.*; + +public class UpdatePlayRoomJob implements Job{ + + private Logger logger = Logger.getLogger(UpdatePlayRoomJob.class); + + 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"; + + public UpdatePlayRoomJob() { + + } + + private void createPlayRoom(int groupId) + { + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 11, 11); + if (pids.size() == 0) { + return; + } + + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) + { + return; + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + + for (String str : pids) { + int pid = Integer.parseInt(str); + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb == null) + continue; + + if (gpb.robot_room <= 0) + continue; + + try { + Set rooms = null; + Jedis jedis = Redis.use("group1_db11").getJedis(); + try { + int min_value = pid * 10000; + int max_value = pid * 10000 + 9999; + String grooms_key = GroupCache.genRoomsKey(groupId); + rooms = jedis.zrevrangeByScore(grooms_key, max_value, min_value); + for (String room : rooms) { + List room_list = Redis.use("group1_db0").hmget(room, "fake", "status", "round", "id", "times", "players"); + + String fake_json = room_list.get(0); + if (fake_json == null) { + continue; + } + + String status = room_list.get(1); + if (StringUtil.isEmpty(status)) { + continue; + } + + String strRound = room_list.get(2); + if (StringUtil.isEmpty(strRound)) { + continue; + } + int round = Integer.parseInt(strRound); + + String roomId = room_list.get(3); + if (StringUtil.isEmpty(roomId)) { + continue; + } + + if (round == 0) { + roomUpdateEvent(room, groupId, roomId); + round++; + updateRound(room, groupId, roomId, round); + } + } + + if (rooms.size() >= gpb.robot_room || rooms.size() >= 20) + { + continue; + } + + String exist = Redis.use("group1_db1").get("robot_exist"); + if (StringUtil.isNotEmpty(exist)) + { + createGroupRoom(groupId, pid); + } + }finally { + jedis.close(); + } + } + catch (Exception e) + { + + } + } + } finally { + jedis10.close(); + } + } + + private void updateBlackSpecial(int groupId) + { + Map mapString = Redis.use("group1_db1").hgetAll("gods_special"); + if (mapString == null) + return; + + for (Map.Entry entry : mapString.entrySet()) { + String strPlayerId = entry.getKey(); + String strPlayerValue = entry.getValue(); + int playerId = Integer.parseInt(strPlayerId); + GroupMemberBean gmb = GroupCache.getMember(groupId, playerId); + if (gmb == null) + continue; + if (Redis.use("group1_db1").sismember("gods", strPlayerId) == false) + { + String gm_key = GroupMemberCache.genKey(groupId, playerId); + String black_key = Redis.use("group1_db10").hget(gm_key, "group_black_key"); + if (StringUtil.isEmpty(black_key)) + { + return; + } + String strblack = Redis.use("group1_db10").hget(black_key, "black"); + int black = 0; + if (StringUtil.isNotEmpty(strblack)) + { + try { + black = Integer.parseInt(strblack); + if (black == 0) + { + logger.info("sadd gods " + strPlayerId); + Redis.use("group1_db1").sadd("gods", strPlayerId); + String StrWhiteValue = Redis.use("group1_db1").hget("gods_value", strPlayerId); + if (StringUtil.isEmpty(StrWhiteValue)) + { + Redis.use("group1_db1").hset("gods_value", strPlayerId, strPlayerValue); + } + } + } + catch (NumberFormatException e) { + black = 0; + } + } + } + } + } + + private void updatePlayRoom(int groupId) { + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 11, 11); + if (pids.size() == 0) { + return; + } + + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) + { + return; + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + + for (String str : pids) { + int pid = Integer.parseInt(str); + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb == null) + continue; + + if (gpb.robot_room <= 0) + continue; + + try { + Set rooms = null; + Jedis jedis = Redis.use("group1_db11").getJedis(); + try { + int min_value = pid * 10000; + int max_value = pid * 10000 + 9999; + String grooms_key = GroupCache.genRoomsKey(groupId); + rooms = jedis.zrevrangeByScore(grooms_key, max_value, min_value); + long time = System.currentTimeMillis() / 1000; + for (String room : rooms) { + List room_list = Redis.use("group1_db0").hmget(room, "fake", "status", "round", "id", "times", "players", "create_time", "fake_existTime"); + + String fake_json = room_list.get(0); + if (fake_json == null) + { + continue; + } + + String status = room_list.get(1); + if(StringUtil.isEmpty(status)) { + continue; + } + + String strRound = room_list.get(2); + if(StringUtil.isEmpty(strRound)) { + continue; + } + int round = Integer.parseInt(strRound); + + String roomId = room_list.get(3); + if(StringUtil.isEmpty(roomId)) { + continue; + } + + String maxStrRound = (room_list.get(4)); + if(StringUtil.isEmpty(maxStrRound)) { + continue; + } + + int maxRound = Integer.parseInt(maxStrRound); + if (round == 0) { + roomUpdateEvent(room, groupId, roomId); + round++; + updateRound(room, groupId, roomId, round); + continue; + } + + Long createTime = Long.parseLong(room_list.get(6)); + Long useTime = time - createTime; + + String str_fake_existTime = room_list.get(7); + int fake_existTime = 30; + if (!StringUtil.isEmpty(str_fake_existTime)) + { + fake_existTime = Integer.parseInt(str_fake_existTime); + } + + if (fake_existTime * round >= useTime) + { + continue; + } + + boolean exitGame = false; + ITArray players = TArray.newFromJsonData(room_list.get(5)); + if (round >= 1) + { + int fake_hp = (int)(Math.random() * 100000); + int rate = (int)(Math.random() * 100); + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + if (i % 2 == 0) + { + if (rate < 50) + { + Redis.use("group1_db10").hincrBy("fake_"+player_id, "fake_hp", fake_hp); + } + else { + Redis.use("group1_db10").hincrBy("fake_"+player_id, "fake_hp", -fake_hp); + } + } + else { + if (rate < 50) + { + Redis.use("group1_db10").hincrBy("fake_"+player_id, "fake_hp", -fake_hp); + } + else { + Redis.use("group1_db10").hincrBy("fake_"+player_id, "fake_hp", fake_hp); + } + } + String fakeHp = Redis.use("group1_db10").hget("fake_"+player_id, "fake_hp"); + if (!StringUtil.isEmpty(fakeHp)) + { + long curFakeHp = Long.parseLong(fakeHp); + if (curFakeHp <= 1000) + { + curFakeHp = (long)(Math.random() * 10000000); + Redis.use("group1_db10").hset("fake_"+player_id, "fake_hp", Long.toString(curFakeHp)); + exitGame = true; + break; + } + } + } + } + + round++; + + if (round > maxRound || exitGame) + { + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + Redis.use("group1_db1").srem("used_robot", Integer.toString(player_id)); + Redis.use("group1_db1").sadd("free_robot", Integer.toString(player_id)); + } + GroupPublisherService.delRoomEvt(groupId, roomId); + jedis.zrem(grooms_key, room); + Redis.use().hset(room, "status", 3 + ""); + Redis.use().hincrBy(room, "cache_ver", 1); + Redis.use().expire(room, 20); + logger.error("del robot room:" + roomId + " player:"+room_list.get(5) + " fake_json:" + fake_json); + continue; + } + updateRound(room, groupId, roomId, round); + } + }finally { + jedis.close(); + } + } + catch (Exception e) + { + + } + } + } finally { + jedis10.close(); + } + } + + /**解散时间*/ + private static final String[] DISMISS_TIME = {"30","60","90","180"}; + /**踢出时间*/ + private static final String[] KICK_TIME = {"30","60","120","180"}; + + private String createGroupRoom(int groupId, int pid) throws Exception { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb==null) { + throw new WebException(ErrorCode.GROUP_PLAY_EXIST); + } + + int gameId = gpb.gameId; + GameBean gb = GameCache.getGame(gameId); + + String grooms_key = GroupCache.genRoomsKey(groupId); + GroupBean group = GroupCache.getGroup(groupId); + ITObject configData = TObject.newFromJsonData(gpb.config); + int maxPlayers = gpb.maxPlayers; + + int opt = configData.getInt("opt"); + String owner_session = AccountCache.genKey(group.owner); + + int dissolve_opt = group.dissolve_opt; + int kick_opt = group.kick_opt; + + String newRoomId = Redis.use("group1_db1").rpop("free_room"); + Redis.use("group1_db1").lpush("free_room", newRoomId); + String room_key = "room:" + newRoomId; + + long time = System.currentTimeMillis() / 1000; + Map roomMap = new HashMap(); + /** + * 玩家列表Seat映射 + */ + + roomMap.put("id", newRoomId); + roomMap.put("owner", owner_session); + roomMap.put("AA", "0"); + roomMap.put("agent", "1"); + roomMap.put("group", groupId+""); + roomMap.put("gpid", pid+""); + roomMap.put("payer", group.owner+""); + roomMap.put("maxPlayers", maxPlayers + ""); + roomMap.put("times", gb.opt.get(opt)+""); + roomMap.put("opt", opt + ""); + roomMap.put("status", "0"); + roomMap.put("fake", "1"); + int fake_existTime = (int)((Math.random() + 0.5) * 40); + roomMap.put("fake_existTime", fake_existTime + ""); + + roomMap.put("hpOnOff", gpb.hpOnOff+""); + roomMap.put("rewardType", gpb.rewardType+""); + roomMap.put("rewardValueType", gpb.rewardValueType+""); + roomMap.put("xipai_rewardType", gpb.xipai_rewardType+""); + roomMap.put("xipai_rewardValueType", gpb.xipai_rewardValueType+""); + roomMap.put("dismiss_time", DISMISS_TIME[dissolve_opt-1]); + roomMap.put("kick_time", KICK_TIME[kick_opt-1]); + roomMap.put("hp_times",gpb.hp_times+""); + if(gpb.hpOnOff == 1) { + ITObject hpObj = TObject.newFromJsonData(gpb.hpConfig); + if (hpObj.getInt("limitInRoom") != null) { + roomMap.put("limitInRoom", hpObj.getInt("limitInRoom") + ""); + } + configData.putTObject("hpData", hpObj); + } + + configData.del("opt"); + configData.del("AA"); + roomMap.put("options", configData.toJson()); + roomMap.put("game", gameId + ""); + roomMap.put("open", "1"); + roomMap.put("round", "0"); + roomMap.put("create_time", time + ""); + roomMap.put("cache_ver", "1"); + + String exist = Redis.use("group1_db1").get("robot_exist"); + if (StringUtil.isNotEmpty(exist)) + { + jedis0.hmset(room_key, roomMap); + + /** + * pid open status 剩余空位 + * 11 1 1 00 + */ + Redis.use("group1_db11").zadd(grooms_key, pid*10000+1101, room_key); + GroupPublisherService.addRoomEvt(groupId, newRoomId); + updateRedisMap(groupId, newRoomId, room_key, roomMap, maxPlayers); + return room_key; + } + return null; + } finally { + jedis0.close(); + } + } + + /** + * 更新redis回合 + */ + private void updateRound(String roomKey, int groupId,String roomid, int round) { + Redis.use().hset(roomKey, "round", Integer.toString(round)); + roomUpdateEvent(roomKey, groupId, roomid); + } + + /** + * list to TArray + * @param list + * @return + */ + public static final ITArray toTArray(List list) { + ITArray result = new TArray(); + for (Integer card : list) { + result.addInt(card); + } + return result; + } + + + /** + * 更新房间redis数据 + */ + public void updateRedisMap(int groupId, String roomId, String roomKey, Map redis_room_map, int maxPlayers) { + Map playerMapBySeat = new HashMap(); + for(int i = 1; i <= maxPlayers; i++) + { + playerMapBySeat.put(i, getRobot(maxPlayers)); + } + + Iterator> it = playerMapBySeat.entrySet().iterator(); + List seat_list = new ArrayList<>(); + List player_list = new ArrayList<>(); + while (it.hasNext()) { + Map.Entry entry = (Map.Entry) it.next(); + seat_list.add(entry.getKey()); + player_list.add(entry.getValue()); + } + redis_room_map.put("players", toTArray(player_list).toJson()); + redis_room_map.put("seats", toTArray(seat_list).toJson()); + Redis.use().hmset(roomKey, redis_room_map); + updateRound(roomKey, groupId, roomId, 0); + } + + /** + * 玩家加入房间刷新总服圈子缓存 + */ + public void roomUpdateEvent(String roomKey, int groupId,String roomid) { + Redis.use("group1_db0").hincrBy(roomKey, "cache_ver", 1); + updateRoomEvt(groupId, roomid); + } + + + /** + * 更新房间事件 + * @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()); + } + + @Override + public void execute(JobExecutionContext context) { + + JobKey jobKey = context.getJobDetail().getKey(); +// if(jobKey.getName().equals("update_play_room") ) { +// //logger.info("执行成功" + jobKey.getName()); +// Set robotGroup = Redis.use("group1_db1").smembers("robot_group"); +// for(String strGroupId:robotGroup){ +// updatePlayRoom(Integer.parseInt(strGroupId)); +// updateBlackSpecial(Integer.parseInt(strGroupId)); +// } +// } +// else + if(jobKey.getName().equals("create_play_room") ) { + //logger.info("执行成功" + jobKey.getName()); + Set robotGroup = Redis.use("group1_db1").smembers("robot_group"); + for(String strGroupId:robotGroup){ + createPlayRoom(Integer.parseInt(strGroupId)); + } + } + } + + public int getRobot(int maxPlayers) + { + long freeRobotNum = Redis.use("group1_db1").scard("free_robot"); + if (freeRobotNum < maxPlayers) + { + long useRobotNum = Redis.use("group1_db1").scard("used_robot"); + if (useRobotNum >= 100) + { + logger.warn("robot not enough, cur used robot " + useRobotNum); + } + try { + createRobot(); + freeRobotNum = Redis.use("group1_db1").scard("free_robot"); + if (freeRobotNum < maxPlayers) + { + logger.error("create robot failed............"); + return 0; + } + + } + catch (Exception e) + { + logger.error(e); + } + } + + try { + while(freeRobotNum > 0) + { + String strRobotId = Redis.use("group1_db1").spop("free_robot"); + freeRobotNum = Redis.use("group1_db1").scard("free_robot"); + if (StringUtil.isEmpty(strRobotId)) + { + createRobot(); + continue; + } + else { + AccountBean acc_bean = AccountCache.getAccount(Integer.parseInt(strRobotId)); + if (acc_bean != null) + { + URL url = null; + try { + url = new URL(acc_bean.portrait); + InputStream in = url.openStream(); + String jsonStr = inputStreamToString(in); + String md5 = MD5.getInstance().getHash(jsonStr); + if (md5.equals("787d66f3fdfa8df70795629c62a3a850") || md5.equals("f1fce77813a0fc9660c76d523813bb59") || md5.equals("d629ac346299c2640dfb6e8fd4232646") || md5.equals("1e76068afc60d7dcff851936b3c2b24b") ) + { + //logger.info("will use robot:" + strRobotId + " head:" + acc_bean.portrait + " md5:" + md5); + url = null; + } + //logger.info("will use robot:" + strRobotId + " head:" + acc_bean.portrait + " md5:" + md5); + } catch (Exception e1) { + url = null; + } + if (url == null) + { + logger.error("robot head error, this robot:"+ strRobotId + " will not use"); + continue; + } + } + else { + continue; + } + } + + Redis.use("group1_db1").sadd("used_robot", strRobotId); + int robotId = Integer.parseInt(strRobotId); + String fakeHp = Redis.use("group1_db10").hget("fake_"+strRobotId, "fake_hp"); + if (StringUtil.isEmpty(fakeHp)) + { + int fake_hp = (int)(Math.random() * 10000000); + Redis.use("group1_db10").hset("fake_"+strRobotId, "fake_hp", Integer.toString(fake_hp)); + } + return robotId; + } + } + catch (Exception e) + { + logger.error(e); + } + return 0; + } + + /** + * 登录 + * @throws Exception + */ + public final void createRobot() throws Exception { + int num = 100; + int mng = 9999; + + String listSql = "select * from old_account"; + ITArray resultArray = DataBase.use().executeQueryByTArray(listSql); + ArrayList nameList = new ArrayList<>(); + ArrayList headList = new ArrayList<>(); + for(int i = 0; i < resultArray.size(); i++) + { + ITObject userData = resultArray.getTObject(i); + String nick = userData.getUtfString("nick"); + nameList.add(nick); + String head = userData.getUtfString("portrait"); + headList.add(head); + } + + Math.random(); + Collections.shuffle(nameList); + Collections.shuffle(headList); + + for(int i = 0; i < num; i++) + { + String sql = ""; + int accountid = create_register(mng, "xx123456xx", nameList, headList); + AccountBean acc_bean = AccountCache.getAccount(accountid); + if (acc_bean == null) + { + sql = String.format("SELECT * FROM account WHERE id ='%d'", + accountid); + + ITArray resultArray2 = DataBase.use().executeQueryByTArray(sql); + if(resultArray2.size() ==0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = resultArray2.getTObject(0); + UpdateUserData(userData, accountid); + + acc_bean = AccountCache.getAccount(accountid); + } + + Redis.use("group1_db1").sadd("free_robot", Integer.toString(acc_bean.id)); + int fake_hp = (int)(Math.random() * 10000000); + Redis.use("group1_db10").hset("fake_"+acc_bean.id, "fake_hp", Integer.toString(fake_hp)); + } + } + + /** + * + * @return + * @throws Exception + */ + private final int UpdateUserData(ITObject reqData,long id) throws Exception { + ITObject userData = TObject.newInstance(); + userData.putInt("id", (int)id); + + userData.putUtfString("acc", reqData.getUtfString("acc")); + userData.putUtfString("portrait", reqData.getUtfString("portrait")); + userData.putUtfString("nick", reqData.getUtfString("nick")); + int sex = reqData.getInt("sex"); + if(sex == 0) { + sex = 1; + reqData.putInt("sex", sex); + } + userData.putInt("sex", sex); + + userData.putInt("mng", 0); + userData.putInt("type", 0); + if(reqData.containsKey("diamo")) { + userData.putInt("diamo", reqData.getInt("diamo")); + } + + userData.putInt("invitation", 1); + updateSession(userData, (int) id); + return (int)id; + } + + + private static String updateSession(ITObject userData, int id) { + String session = AccountCache.genKey(id); + Map map = new HashMap(); + Utils.objectToMap(userData, map); + + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + jedis0.hmset(session, map); + BaseCache.updateCacheVer(jedis0, session); + }finally { + jedis0.close(); + } + + return session; + } + + + /** + * + * @description: 将输入流转换成字符串 + * @author: Jeff + * @date: 2019年12月15日 + * @param inputStream 输入流 + * @return + */ + private static String inputStreamToString(InputStream inputStream) { + StringBuffer buffer = new StringBuffer(); + InputStreamReader inputStreamReader; + try { + inputStreamReader = new InputStreamReader(inputStream, "utf-8"); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + String str = null; + while ((str = bufferedReader.readLine()) != null) { + buffer.append(str); + } + // 释放资源 + bufferedReader.close(); + inputStreamReader.close(); + inputStream.close(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return buffer.toString(); + } + + private final int create_register(int mng, String password, ArrayList nickList, ArrayList headList) throws Exception { + int count = 0; + long id = 0; + ArrayList list = new ArrayList<>(); + for(int i = 0; i < 10; i++) + { + String strId = Redis.use("group1_db1").rpop("free_account"); + if (StringUtil.isEmpty(strId)) + { + break; + } + list.add(strId); + } + //logger.info("free_account:"+list.toString()); + + Collections.shuffle(list); + + do { + id = Long.parseLong(list.remove(0)); + String sql = "SELECT id FROM account WHERE id =" + id; + ITArray resultArray = DataBase.use().executeQueryByTArray(sql); + if (resultArray.size() == 0) + { + break; + } + }while(count++ <= 10); + + for(int i = 0; i < list.size(); i++) + { + Redis.use("group1_db1").lpush("free_account", list.get(i)); + } + + if (id == 0) + { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = TObject.newInstance(); + userData.putInt("id", (int)id); + + userData.putUtfString("acc", "" + id); + userData.putUtfString("portrait", ""); + while (headList.size() > 0) + { + String head = null; + try { + head = headList.remove(0); + URL url = new URL(head); + InputStream in = url.openStream(); + String jsonStr = inputStreamToString(in); + String md5 = MD5.getInstance().getHash(jsonStr); + logger.info("robot:" + id + " head:" + head + " md5:" + md5); + if (md5.equals("787d66f3fdfa8df70795629c62a3a850") || md5.equals("f1fce77813a0fc9660c76d523813bb59") || md5.equals("d629ac346299c2640dfb6e8fd4232646") || md5.equals("1e76068afc60d7dcff851936b3c2b24b") ) + { + head = null; + } + } catch (Exception e1) { + head = null; + } + if (head != null) + { + userData.putUtfString("portrait", head); //头像 + break; + } + } + + String nick = ""; + if (nickList.size() > 0) + { + nick = nickList.remove(0); + } + nick = nick.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", " "); + userData.putUtfString("nick", nick); + int sex = 1; + if(sex == 0) { + sex = 1; + } + userData.putInt("sex", sex); + userData.putInt("diamo", 0); + userData.putInt("mng", 0); + userData.putInt("regTime", mng); + userData.putInt("type", 0); + userData.putUtfString("password", Utils.getMD5Hash(password)); + long reg_time = System.currentTimeMillis() / 1000; + userData.putLong("reg_time", reg_time); + logger.info("create robot account:"+userData.toJson()+" password:" + password); + int result = DataBase.use().insert("account", userData); + if (result == -1) { + throw new WebException(ErrorCode._FAILED); + } + userData.putInt("invitation", 1); + String session = updateSession(userData, (int) id); + return (int)id; + } +} diff --git a/web_group/src/main/java/com/group/service/GroupLogService.java b/web_group/src/main/java/com/group/service/GroupLogService.java new file mode 100644 index 0000000..f290abf --- /dev/null +++ b/web_group/src/main/java/com/group/service/GroupLogService.java @@ -0,0 +1,2346 @@ +package com.group.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.bind.annotation.XmlElementDecl.GLOBAL; + +import com.data.bean.AccountBean; +import com.data.bean.GroupBean; +import com.data.bean.GroupMemberBean; +import com.data.cache.AccountCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupMemberCache; +import com.data.util.ConsumeCode; +import com.data.util.CountUtil; +import com.data.util.ErrorCode; +import com.data.util.Utility; +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.plugin.redis.RedisLock; +import com.taurus.core.util.DateUtils; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.web.WebException; + +import jdk.nashorn.internal.objects.Global; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Pipeline; + +public class GroupLogService { + + private static final Logger log = Logger.getLogger(GroupLogService.class); + // 体力值变化 + private static final int CHOOSE_CHAGE = 1; + // 操作上分 + private static final int CHOOSE_UPPER = 2; + // 操作下分 + private static final int CHOOSE_SUB = 4; + // 抽水 + private static final int CHOOSE_PUMP = 8; + // 奖励 + private static final int CHOOSE_RWARD = 16; + // 转账 + private static final int CHOOSE_TRADE = 32; + // 提取 + private static final int CHOOSE_TAKE_REWARD = 64; + // 洗牌 + private static final int CHOOSE_XIPAI = 128; + /** + * 上下分记录类型 + */ + private static final int[] MGRLOG_TYPE = { ConsumeCode.HP_MGR_UPPER, ConsumeCode.HP_MGR_SUB, + ConsumeCode.HP_PARTNER_UPPER, ConsumeCode.HP_PARTNER_SUB }; + + /** + * 获取成员排行 + * + * @param groupId + * @param pid + * @param limit + * @param num + * @param beginTime + * @param endTime + * @return + * @throws Exception + */ + public static final ITObject getMemberRank(int groupId, int uid, int pid, int type, int limit, int num, + int beginTime, int endTime) throws Exception { + ITObject obj1 = TObject.newInstance(); + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + int mgn_partner = mng_bean.partnerLev; + int mgn_lev = mng_bean.lev; + + String strGodsList = null; + Set godsList = Redis.use("group1_db1").smembers("gods"); + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + boolean findok = false; + try { + + if (!godsList.isEmpty()) { + for (String mem : godsList) { + String havemems = jedis1.hget("gods_super", mem); + if (!StringUtil.isNotEmpty(havemems)) { + // 判断是否是超级号 + if (strGodsList == null) { + strGodsList = mem; + } else { + strGodsList += "," + mem; + } + } + } + if (!strGodsList.isEmpty()) { + strGodsList = "(" + strGodsList + ")"; + findok = true; + } + } + } finally { + jedis1.close(); + } + + // log.info("getMemberRank strGodsList:"+strGodsList+" mgn_partner:"+mgn_partner + // + " mgn_lev:"+mgn_lev); + + // if (mgn_lev == 1 && mgn_partner == 0) { + String sql = String.format( + "SELECT uid,SUM(win) AS win,SUM(round) as round,SUM(score) as score FROM group_member_log WHERE groupId = %s ", + groupId); + if (pid > 0) { + sql = sql + " AND pid =" + pid; + } + if (findok) { + sql = sql + " AND uid not in " + strGodsList; + } + if (type == 0) { + sql = sql + String.format(" AND time >=%s AND time <%s GROUP BY uid ORDER BY round DESC limit %s,%s", + beginTime, endTime, limit, num); + } else if (type == 1) { + sql = sql + String.format(" AND time >=%s AND time <%s GROUP BY uid ORDER BY score DESC limit %s,%s", + beginTime, endTime, limit, num); + } + + // log.info("getMemberRank sql:"+sql); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + } + obj1.putTArray("ranks", arr); + String sql2 = String.format( + "select count(uid) as num from group_member_log where groupId = %s and round > 0 and time >=%s AND time <%s ", + groupId, beginTime, endTime); + if (findok) { + sql2 = sql2 + " and uid not in " + strGodsList; + } + // log.info("getMemberRank sql2:"+sql2); + int allActiveNum = 0; + ITArray arr2 = DataBase.use().executeQueryByTArray(sql2); + if (arr2.size() > 0) { + ITObject obj = arr2.getTObject(0); + allActiveNum = obj.getLong("num").intValue(); + } + obj1.putInt("allActiveNum", allActiveNum); + // } + + obj1.putInt("limit", limit); + return obj1; + } + + /** + * 获取战绩列表 + * + * @param platform + * @param groupId + * @param limit + * @param num + * @return + */ + public static ITObject getPersonRecords(String platform, int groupId, int timeType, int beginTime, int endTime, + int limit, int num, int qid, int uid) throws Exception { + String qid_sql = StringUtil.Empty; + qid_sql = "and uid=" + qid; + + ITArray militaryList = TArray.newInstance(); + + ITObject obj1 = TObject.newInstance(); + if (timeType == 0) { + + beginTime = DateUtils.getBeginDay(); + endTime = DateUtils.getBeginDay() + 3600 * 24; + } else if (timeType == 1) { + + beginTime = DateUtils.getBeginDay() - 3600 * 24; + endTime = DateUtils.getBeginDay(); + } else if (timeType == 2) { + + beginTime = DateUtils.getBeginDay() - 3600 * 48; + endTime = DateUtils.getBeginDay() - 3600 * 24; + } + + int total = 0; + int consume = 0; + + String where = String.format("gid=%s and time>=%s and time<=%s", groupId, beginTime, endTime); + if (limit == 0) { + + String count_sql = String.format("SELECT count(*) AS total FROM room_rec_log where %s %s", where, qid_sql); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + total = obj.getLong("total").intValue(); + } + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + + String key = String.format("g%s:m%s:consume_hp", groupId, uid); + if (timeType >= 0 && timeType <= 2) { + + String hp_key = String.format("%s:d%s", key, beginTime); + String r_str = jedis9.get(hp_key); + int r_num = 0; + if (StringUtil.isNotEmpty(r_str)) { + r_num = Integer.parseInt(r_str); + } + consume = r_num; + } else { + int timeBegin = beginTime; + while (timeBegin <= endTime) { + + String hp_key = String.format("%s:d%s", key, timeBegin); + String r_str = jedis9.get(hp_key); + int r_num = 0; + if (StringUtil.isNotEmpty(r_str)) { + r_num = Integer.parseInt(r_str); + } + consume += r_num; + timeBegin += 86400; + } + } + + getMemberData(jedis9, uid, obj1, groupId, 0, beginTime, endTime, false, false); + } finally { + jedis9.close(); + } + } + + String sql = String.format( + "select rec_key from room_rec_log where %s %s GROUP BY roomid ORDER BY time desc limit %s,%s", where, + qid_sql, limit, num); + ITArray list = DataBase.use().executeQueryByTArray(sql); + + if (list.size() > 0) { + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + for (int i = 0; i < list.size(); ++i) { + ITObject tem = list.getTObject(i); + String rec_key = tem.getString("rec_key"); + ITObject obj = Utility.getMilitaryList(jedis5, rec_key, platform); + if (obj == null) { + continue; + } + militaryList.addTObject(obj); + } + } finally { + jedis5.close(); + } + } + + obj1.putTArray("records", militaryList); + obj1.putInt("limit", limit); + obj1.putInt("total", total); + obj1.putInt("consume", consume); + return obj1; + } + + public static ITObject getPartnerStatPlay(int groupId, int uid, int parent_id, int limit, int num, int timeType, + int beginTime, int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 10, 11); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITArray arr = TArray.newInstance(); + try { + for (String pid : pids) { + + ITObject objp = TObject.newInstance(); + + objp.putInt("pid", Integer.parseInt(pid)); + + if (timeType == 0) { + + String key = String.format("g{%s}:m%s:valid_round:p%s", groupId, uid, pid); + int round = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("round", round); + + key = String.format("g%s:hp_cost:m%s:p%s", groupId, uid, pid); + int pump = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("pump", pump); + + key = String.format("g{%s}:m%s:p%s:reward_log", groupId, uid, pid); + int award = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("award", award); + } else if (timeType == 1) { + + String curMonth = ":m" + DateUtils.getBeginMonth(); + + String key = String.format("g{%s}:m%s:valid_round:p%s%s", groupId, uid, pid, curMonth); + int round = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("round", round); + + key = String.format("g%s:hp_cost:m%s:p%s%s", groupId, uid, pid, curMonth); + int pump = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("pump", pump); + + key = String.format("g{%s}:m%s:p%s:reward_log%s", groupId, uid, pid, curMonth); + int award = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("award", award); + } else if (timeType == 2) { + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + + String key = String.format("g{%s}:m%s:valid_round:p%s%s", groupId, uid, pid, curMonth); + int round = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("round", round); + + key = String.format("g%s:hp_cost:m%s:p%s%s", groupId, uid, pid, curMonth); + int pump = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("pump", pump); + + key = String.format("g{%s}:m%s:p%s:reward_log%s", groupId, uid, pid, curMonth); + int award = _getCountValue(jedis9, key, beginTime, endTime); + objp.putInt("award", award); + } + arr.addTObject(objp); + } + } finally { + jedis9.close(); + } + + obj.putTArray("members", arr); + obj.putInt("limit", limit); + + return obj; + } + + public static ITObject getDirectStatMember(int groupId, int uid, int rootUid, int limit, int num, int timeType, + int beginTime, int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + + String limitSql = String.format("limit %s,%s", limit, num); + String sql = String.format( + "SELECT uid, partnerLev" + " FROM group_member" + + " WHERE groupId = %s and ((parentId=%s and partnerLev = 0) or uid = %s) GROUP BY uid %s", + groupId, uid, uid, limitSql); + + ITArray temp = TArray.newInstance(); + + ITArray list = DataBase.use().executeQueryByTArray(sql); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + if (objLine.containsKey("uid")) { + + int tagUid = objLine.getInt("uid"); + + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + // int newBeginTime = beginTime - 86400*30; + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, false, false); + + if (timeType == 0) { + { + String tmpKey = String.format("g{%s}:m%s:", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, tmpKey + "reward_log", beginTime, endTime); + objLine.putInt("reward_tongji", reward_hp); + } + + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getCountValue(jedis9, key, beginTime, endTime); + objLine.putInt("reward_hp", (int) reward_hp); + } else if (timeType == 1) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 2) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } + temp.addTObject(objLine); + } + } + } finally { + jedis9.close(); + } + + obj.putTArray("members", temp); + obj.putInt("limit", limit); + + return obj; + } + + public static ITObject getXingYunHaoMember(int groupId, int limit, int num, int timeType, int beginTime, + int endTime) throws Exception { + ITObject obj = TObject.newInstance(); + + String limitSql = String.format("limit %s,%s", limit, num); + + String strGodsList = null; + Set godsList = Redis.use("group1_db1").smembers("gods"); + Map mapString = Redis.use("group1_db1").hgetAll("gods_special"); + for (Map.Entry entry : mapString.entrySet()) { + String strPlayerId = entry.getKey(); + godsList.remove(strPlayerId); + } + + List allList = new ArrayList(); + allList.addAll(godsList); + for (String mem : godsList) { + if (strGodsList == null) { + strGodsList = mem; + } else { + strGodsList += "," + mem; + } + } + + String sql = String.format( + "SELECT uid, partnerLev" + " FROM group_member" + " WHERE groupId = %s and uid in (%s) GROUP BY uid %s", + groupId, strGodsList, limitSql); + + ITArray temp = TArray.newInstance(); + int allTotalWin = 0; + ITArray list = DataBase.use().executeQueryByTArray(sql); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + if (objLine.containsKey("uid")) { + + int tagUid = objLine.getInt("uid"); + + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, false, false); + + temp.addTObject(objLine); + } + } + + for (String user : allList) { + String key = String.format("g{%s}:m%s:", groupId, user); + int total_win = _getCountValue(jedis9, key + "total_win_self", beginTime, endTime); + allTotalWin += total_win; + } + } finally { + jedis9.close(); + } + + obj.putTArray("members", temp); + obj.putInt("limit", limit); + obj.putLong("all_total_win", allTotalWin); + + return obj; + } + + public static ITObject getPartnerStatMember(int groupId, int uid, int rootUid, int limit, int num, int timeType, + int beginTime, int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + + String limitSql = String.format("limit %s,%s", limit, num); + + String sql = String.format( + "SELECT uid, partnerLev" + " FROM group_member" + + " WHERE groupId = %s and (parentId=%s or uid = %s) and partnerLev > 0 GROUP BY uid %s", + groupId, uid, uid, limitSql); + + ITArray temp = TArray.newInstance(); + + ITArray list = DataBase.use().executeQueryByTArray(sql); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + if (objLine.containsKey("uid")) { + + int tagUid = objLine.getInt("uid"); + + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + if (tagUid != uid) { + // int newBeginTime = beginTime - 86400 * 30; + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, false, true); + } else { + // int newBeginTime = beginTime - 86400 * 30; + // getMemberData(jedis9,tagUid,objLine,groupId,timeType, + // beginTime,endTime,false,true); + getDirectMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime); + } + + if (tagUid == uid) { + + if (timeType == 0) { + String tmpKey = String.format("g{%s}:m%s:", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, tmpKey + "d_reward", beginTime, endTime); + objLine.putInt("reward_tongji", reward_hp); + +// String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); +// int reward_hp1 = _getCountValue(jedis9, key, beginTime, endTime); +// objLine.putInt("reward_hp", reward_hp1); + } else if (timeType == 1) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginMonth(); + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 2) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } + } else { + if (timeType == 0) { + String tmpKey = String.format("g{%s}:m%s:", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, tmpKey + "d_reward", beginTime, endTime); + objLine.putInt("reward_tongji", reward_hp); + + String undersql = "select * from group_member gm,account a where a.id=gm.uid and gm.parentId=" + + tagUid; + ITArray arr = DataBase.use().executeQueryByTArray(undersql); + int under_round = 0; + int under_win = 0; + int under_total_win = 0; + + int under_reward_hp = 0; + + if (arr.size() > 0) { +// log.info("underKey:"+uid); + + for (int ii = 0; ii < arr.size(); ii++) { + ITObject underData = arr.getTObject(ii); + String underKey = String.format("g{%s}:m%s:", groupId, underData.getInt("uid")); + under_round += _getCountValue(jedis9, underKey + "round_log", beginTime, endTime); + under_win += _getCountValue(jedis9, underKey + "valid_round", beginTime, endTime); + under_reward_hp += _getCountValue(jedis9, underKey + "d_reward", beginTime, + endTime); +// under_total_win += _getCountValue(jedis9, underKey + "total_win", beginTime, endTime); +// log.info("underKey:"+underKey); +// log.info("under_reward_hp:"+under_reward_hp); + + } + if (under_reward_hp != 0) { + objLine.putLong("reward_tongji", under_reward_hp); // 获得奖励 + + } + +// param.putInt("total_win", under_total_win); // 总赢分 + + } else { + objLine.putLong("reward_tongji", reward_hp); // 获得奖励 + } + objLine.putLong("reward_tongji", reward_hp); // 获得奖励 + +// String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); +// int reward_hp = _getCountValue(jedis9, key, beginTime, endTime); +// objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 1) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 2) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } + } + + temp.addTObject(objLine); + } + } + } finally { + jedis9.close(); + } + + obj.putTArray("members", temp); + obj.putInt("limit", limit); + + return obj; + } + + public static ITObject findPartnerStatMember(int groupId, int uid, int rootUid, int tagId, int limit, int num, + int timeType, int beginTime, int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + + String limitSql = String.format("limit %s,%s", limit, num); + + String sql = String.format("SELECT uid, partnerLev" + " FROM group_member" + + " WHERE groupId = %s and (parentId=%s or uid = %s) and partnerLev > 0 and uid=%s GROUP BY uid %s", + groupId, uid, uid, tagId, limitSql); + + ITArray temp = TArray.newInstance(); + + ITArray list = DataBase.use().executeQueryByTArray(sql); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + if (objLine.containsKey("uid")) { + + int tagUid = objLine.getInt("uid"); + + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + if (tagUid != uid) { + // int newBeginTime = beginTime - 86400 * 30; + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, false, true); + } else { + // int newBeginTime = beginTime - 86400 * 30; + // getMemberData(jedis9,tagUid,objLine,groupId,timeType, + // beginTime,endTime,false,true); + getDirectMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime); + } + + if (tagUid == uid) { + + if (timeType == 0) { + { + String tmpKey = String.format("g{%s}:m%s:", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, tmpKey + "reward_log", beginTime, endTime); + objLine.putInt("reward_tongji", reward_hp); + } + + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, key, beginTime, endTime); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 1) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginMonth(); + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 2) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } + } else { + if (timeType == 0) { + { + long reward_hp_total = 0; + List listParent = Utility.getChildParentList(groupId, tagUid, true); + for (Integer parId : listParent) { + String tmpKey = String.format("g{%s}:m%s:", groupId, parId); + int reward_hp = _getCountValue(jedis9, tmpKey + "reward_log", beginTime, endTime); + reward_hp_total += reward_hp; + } + String key = String.format("g{%s}:m%s:d_reward", groupId, tagUid); + int reward_hp = _getCountValue(jedis9, key, beginTime, endTime); + objLine.putInt("reward_hp", reward_hp); + + if (reward_hp_total == 0) { + reward_hp_total = reward_hp; + } + objLine.putInt("reward_tongji", (int) reward_hp_total); + } + + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getCountValue(jedis9, key, beginTime, endTime); + objLine.putInt("reward_hp", (int) reward_hp); + } else if (timeType == 1) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } else if (timeType == 2) { + { + String key = String.format("g{%s}:m%s:", groupId, tagUid); + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + + objLine.putInt("reward_tongji", reward_hp); + } + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + String key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, tagUid, uid); + int reward_hp = _getValue(jedis9, key + curMonth); + objLine.putInt("reward_hp", reward_hp); + } + } + + temp.addTObject(objLine); + } + } + } finally { + jedis9.close(); + } + + obj.putTArray("members", temp); + obj.putInt("limit", limit); + + return obj; + } + + public static ITObject getPartnerStat(int groupId, int uid, int limit, int num, int timeType, int beginTime, + int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + int lev = gmb.lev; + boolean mgr = lev < 3; + ITArray list = null; + String limitSql = String.format("limit %s,%s", limit, num); + if (mgr) { + + String sql = String.format("SELECT A.uid,A.partnerLev, A.autoscore," + + "(SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total " + + "FROM group_member AS A" + " where A.groupId= %s and A.partnerLev=1 %s", groupId, groupId, + limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + log.info("统计sql:"+sql); + + } else { + + String sql = String.format( + "SELECT A.uid,A.partnerLev, A.autoscore, (SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total " + + "FROM group_member AS A" + + " where A.groupId= %s and (A.parentId=%s or A.uid=%s) AND A.partnerLev >0 %s", + groupId, groupId, uid, uid, limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + log.info("统计sql:"+sql); + + } + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + int tagUid = objLine.getInt("uid"); + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, true, true); + } + }catch(Exception e) { + log.error(e); + } finally { + jedis9.close(); + jedis10.close(); + } + + obj.putTArray("members", list); + obj.putInt("limit", limit); + + return obj; + } + + public static ITObject findPartnerStat(int groupId, int uid, int tagId, int limit, int num, int timeType, + int beginTime, int endTime) throws Exception { + + ITObject obj = TObject.newInstance(); + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + int lev = gmb.lev; + boolean mgr = lev < 3; + ITArray list = null; + String limitSql = String.format("limit %s,%s", limit, num); + if (mgr) { + + String sql = String.format("SELECT A.uid,A.partnerLev, A.autoscore," + + "(SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total " + + "FROM group_member AS A" + " where A.groupId= %s and A.uid=%s %s", groupId, groupId, tagId, + limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + } else { + if (uid != tagId) { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } finally { + jedis10.close(); + } + + } + + String sql = String.format( + "SELECT A.uid,A.partnerLev, A.autoscore, (SELECT COUNT(uid) FROM group_member B where B.groupId = %s AND B.parentId = A.uid) AS total " + + "FROM group_member AS A" + " where A.groupId= %s AND A.uid=%s %s", + groupId, groupId, tagId, limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + } + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + + try { + + for (int i = 0; i < list.size(); ++i) { + + ITObject objLine = list.getTObject(i); + int tagUid = objLine.getInt("uid"); + AccountBean acc = AccountCache.getAccount(tagUid); + objLine.putString("nick", acc.nick); + + getMemberData(jedis9, tagUid, objLine, groupId, timeType, beginTime, endTime, true, true); + } + } finally { + jedis9.close(); + jedis10.close(); + } + + obj.putTArray("members", list); + obj.putInt("limit", limit); + + return obj; + } + + public static void getMemberData(Jedis jedis9, int uid, ITObject param, int groupId, int timeType, int beginTime, + int endTime, boolean rewardHP, boolean total) throws Exception { + GroupBean gb = GroupCache.getGroup(groupId); + + String key = String.format("g{%s}:m%s:", groupId, uid); + String self = total ? "" : "_self"; + if (timeType == 0) { + // 包含下级合伙人 + long reward_hp_total = 0; + // List listParent = Utility.getChildParentList(groupId, uid, true); + String uidkey = String.format("g{%s}:m%s:d_reward", groupId, uid); + int reward_hp = _getCountValue(jedis9, uidkey, beginTime, endTime); + + param.putLong("reward_hp", reward_hp); // 获得奖励 +// if (rewardHP) { +//// int reward_hp = _getCountValue(jedis9,key + "reward_log",beginTime,endTime); +//// param.putInt("reward_hp", reward_hp); +// +// // 包含下级合伙人 +// long reward_hp_total = 0; +// // List listParent = Utility.getChildParentList(groupId, uid, true); +// String uidkey = String.format("g{%s}:m%s:d_reward", groupId, uid); +// int reward_hp = _getCountValue(jedis9, uidkey, beginTime, endTime); +// +// param.putLong("reward_hp", reward_hp); // 获得奖励 +// } + int valid_round = _getCountValue(jedis9, key + "valid_round" + self, beginTime, endTime); +// param.putInt("valid_round", valid_round); + + int win_round = _getCountNumValue(jedis9, key + "valid_round", beginTime, endTime); + param.putInt("win_round", win_round); + + int total_round = _getCountValue(jedis9, key + "round_log" + self, beginTime, endTime); +// if (beginTime==1753286400&&endTime==1753372800){ +// param.putInt("total_round" , total_round+valid_round/100); +// }else { +// param.putInt("total_round" , total_round); +// } + int total_win = _getCountValue(jedis9, key + "total_win" + self, beginTime, endTime); +// g{618028}:m668628:xipai_reward_log_to:par100095:d1758470400 +// int xipai_hp_cost = jedis9.getInt("g{"+groupId+"}:m668628:xipai_reward_log_to:par100095:d1758470400"); + + String sql = "select * from group_member gm,account a where a.id=gm.uid and gm.parentId=" + uid; + ITArray arr = DataBase.use().executeQueryByTArray(sql); + int under_round = 0; + int under_win = 0; + int under_total_win = 0; + + int under_reward_hp = 0; + int xipai_hp_cost = 0; + if (arr.size() > 0) { +// log.info("underKey:"+uid); + + for (int i = 0; i < arr.size(); i++) { + ITObject underData = arr.getTObject(i); + String underKey = String.format("g{%s}:m%s:", groupId, underData.getInt("uid")); +// under_round += _getCountValue(jedis9, underKey + "round_log", beginTime, endTime); + under_win += _getCountValue(jedis9, underKey + "valid_round", beginTime, endTime); + under_reward_hp += _getCountValue(jedis9, underKey + "d_reward", beginTime, endTime); +// log.info("xipai_hp_cost_key:" + "g{" + groupId + "}:m" + underData.getInt("uid") +// + ":xipai_reward_log_to:par" + gb.owner + ":d" + beginTime + ""); +// +// String xipai_hp_cost_key = jedis9.get("g{" + groupId + "}:m" + underData.getInt("uid") +// + ":xipai_cost_log:par" + gb.owner + ":d" + beginTime + ""); +// log.info("xipai_hp_cost:" + xipai_hp_cost_key); +// +// xipai_hp_cost += (xipai_hp_cost_key == null ? 0 : Integer.parseInt(xipai_hp_cost_key)); +// under_total_win += _getCountValue(jedis9, underKey + "total_win", beginTime, endTime); +// log.info("underKey:"+underKey); +// log.info("under_reward_hp:"+under_reward_hp); + + } + if (under_reward_hp != 0) { + param.putLong("reward_hp", under_reward_hp); // 获得赠送 + } +// param.putInt("valid_round", under_win); + + } else { + param.putInt("total_round", total_round); + param.putLong("reward_hp", reward_hp); // 获得赠送 + + } + String cost_key = jedis9.get("g{" + groupId + "}:m" + uid + ":xipai_cost:d" + beginTime + ""); + int xipai_cost = cost_key == null ? 0 : Integer.parseInt(cost_key); + + param.putInt("total_win", total_win - xipai_cost); // 总赢分 + param.putInt("total_round", total_round);// 总场次 + param.putInt("valid_round", valid_round);// 大赢家 + param.putLong("reward_hp", reward_hp); // 获得赠送 + + ITObject gallc = GroupService.getAllHpCache(groupId, uid, 30); + param.putTObject("hpall", gallc); + } else if (timeType == 1) { + + String curMonth = ":m" + DateUtils.getBeginMonth(); + + if (rewardHP) { + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + param.putInt("reward_hp", reward_hp); + } + + int win_round = _getNumValue(jedis9, key + "valid_round" + self + curMonth); + param.putInt("win_round", win_round); + + int valid_round = _getValue(jedis9, key + "valid_round" + self + curMonth); + param.putInt("valid_round", valid_round); + + int total_round = _getValue(jedis9, key + "round_log" + self + curMonth); + param.putInt("total_round", total_round); + + int total_win = _getValue(jedis9, key + "total_win" + self + curMonth); + + param.putInt("total_win", total_win); + + ITObject gallc = GroupService.getAllHpCache(groupId, uid, 30); + param.putTObject("hpall", gallc); + } else if (timeType == 2) { + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + + if (rewardHP) { + int reward_hp = _getValue(jedis9, key + "reward_log" + curMonth); + param.putInt("reward_hp", reward_hp); + } + + int win_round = _getNumValue(jedis9, key + "valid_round" + self + curMonth); + param.putInt("win_round", win_round); + + int valid_round = _getValue(jedis9, key + "valid_round" + self + curMonth); + param.putInt("valid_round", valid_round); + + int total_round = _getValue(jedis9, key + "round_log" + self + curMonth); + param.putInt("total_round", total_round); + + int total_win = _getValue(jedis9, key + "total_win" + self + curMonth); + param.putInt("total_win", total_win); + + ITObject gallc = GroupService.getAllHpCache(groupId, uid, 30); + param.putTObject("hpall", gallc); + } + } + + public static List getMemberLogList(int groupId, int uid, boolean self) { + String pl_key = String.format("g{%s}:member_list:%s", groupId, uid); + Set child_list = Redis.use("group1_db10").smembers(pl_key); + List list = new ArrayList<>(); + if (self) { + list.add(uid); + } + for (String str : child_list) { + list.add(Integer.parseInt(str)); + } + return list; + } + + private static void getDirectMemberData(Jedis jedis9, int uid, ITObject param, int groupId, int timeType, + int beginTime, int endTime) { + + String key = String.format("g{%s}:m%s:", groupId, uid); + + if (timeType == 0) { + /* + * int valid_round = _getCountValue(jedis9,key + + * "d_valid_round",beginTime,endTime); param.putInt("valid_round" , + * valid_round); + * + * int total_round = _getCountValue(jedis9,key + + * "d_round_log",beginTime,endTime); param.putInt("total_round" , total_round); + * + * int total_win = _getCountValue(jedis9,key + "d_total_win",beginTime,endTime); + * param.putInt("total_win" , total_win); + */ + + int valid_round = _getCountValue(jedis9, key + "d_valid_round", beginTime, endTime); + param.putInt("valid_round", valid_round); + + int win_round = _getCountNumValue(jedis9, key + "d_valid_round", beginTime, endTime); + param.putInt("win_round", win_round); + + int total_round = _getCountValue(jedis9, key + "d_round_log", beginTime, endTime); + param.putInt("total_round", total_round); + + int total_win = _getCountValue(jedis9, key + "d_total_win", beginTime, endTime); + + param.putInt("total_win", total_win); + } else if (timeType == 1) { + + String curMonth = ":m" + DateUtils.getBeginMonth(); + + int valid_round = _getValue(jedis9, key + "d_valid_round" + curMonth); + param.putInt("valid_round", valid_round); + + int win_round = _getNumValue(jedis9, key + "d_valid_round" + curMonth); + param.putInt("win_round", win_round); + + int total_round = _getValue(jedis9, key + "d_round_log" + curMonth); + param.putInt("total_round", total_round); + + int total_win = _getValue(jedis9, key + "d_total_win" + curMonth); + param.putInt("total_win", total_win); + } else if (timeType == 2) { + + String curMonth = ":m" + DateUtils.getBeginLastMonth(); + + int valid_round = _getValue(jedis9, key + "d_valid_round" + curMonth); + param.putInt("valid_round", valid_round); + + int win_round = _getNumValue(jedis9, key + "d_valid_round" + curMonth); + param.putInt("win_round", win_round); + + int total_round = _getValue(jedis9, key + "d_round_log" + curMonth); + param.putInt("total_round", total_round); + + int total_win = _getValue(jedis9, key + "d_total_win" + curMonth); + param.putInt("total_win", total_win); + } + } + + /** + * 获取战绩列表 + * + * @param platform + * @param groupId + * @param limit + * @param num + * @return + */ + public static ITObject getMemberStat(int groupId, int uid, int qid, int partnerId, int limit, int num, int timeType, + int beginTime, int endTime, int sortType) throws Exception { + + ITObject obj1 = TObject.newInstance(); + + String qid_sql = StringUtil.Empty; + if (qid > 0) { + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + int mgn_partner = mng_bean.partnerLev; + int mgn_lev = mng_bean.lev; + if (mgn_lev == 3 && mgn_partner == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + + if (mgn_lev == 3) { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + List par_list = Utility.getMemberParents(jedis10, groupId, qid, false); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } finally { + jedis10.close(); + } + + } + + qid_sql = " AND A.uid=" + qid; + } else if (partnerId > 0) { + String ugm_key = GroupMemberCache.genKey(groupId, partnerId); + String lev = Redis.use("group1_db10").hget(ugm_key, "lev"); + boolean mgr = StringUtil.isNotEmpty(lev) && Integer.parseInt(lev) < 3; + + String p = Utility.getChildParentSql(groupId, partnerId, true); + if (mgr) { + p = p + ",0"; + } + if (Integer.parseInt(lev) > 1) { + qid_sql = String.format(" AND (A.parentId in(%s) or A.uid = %s)", p, partnerId); + } + GroupBean gb = GroupCache.getGroup(groupId); + if (gb.owner == uid && partnerId == gb.owner) { + qid_sql = ""; + } + + // qid_sql = String.format(" AND A.parentId = %s", partnerId); + } + + if (timeType == 0) { + + beginTime = DateUtils.getBeginDay(); + endTime = DateUtils.getEndDay(); + } else if (timeType == 1) { + + beginTime = DateUtils.getBeginDay() - 3600 * 24; + endTime = DateUtils.getBeginDay(); + } else if (timeType == 2) { + + beginTime = DateUtils.getBeginDay() - 3600 * 48; + endTime = DateUtils.getBeginDay() - 3600 * 24; + } + + String order_sql = "ORDER BY win DESC "; + + if (sortType > 0) { + ArrayList tempSortList = new ArrayList(); + tempSortList.add("score"); + tempSortList.add("round"); + tempSortList.add("win"); + tempSortList.add("pump"); + + order_sql = String.format(" ORDER BY %s %s ", tempSortList.get((sortType - 1) / 2), + (sortType % 2 == 1 ? "DESC" : "ASC")); + } + String sql = String.format( + "SELECT IFNULL(B.win, 0) AS win, IFNULL(B.ROUND, 0) AS round, IFNULL(B.score, 0) AS score, IFNULL(C.pump, 0) AS pump, A.uid, A.hp, A.lev, A.partnerLev " + + "FROM group_member AS A " + + "LEFT JOIN( SELECT SUM(win) AS win, SUM(ROUND) AS ROUND, SUM(score) AS score, uid FROM group_member_log WHERE groupId = %s AND TIME >= %s AND TIME < %s GROUP BY uid ) AS B ON A.uid = B.uid " + + "LEFT JOIN( SELECT IFNULL(SUM(hp), 0) AS pump, uid FROM group_hp_log WHERE gid = %s AND TIME >= %s AND TIME < %s AND reason = 7 GROUP BY uid ) AS C ON A.uid = C.uid " + + "WHERE A.groupId = %s AND round > 0 %s " + "GROUP BY A.uid %s" + "limit %s,%s", + groupId, beginTime, endTime, groupId, beginTime, endTime, groupId, qid_sql, order_sql, limit, num); + + log.info("查询sql:" + sql); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (arr.size() > 0) { + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + String strtmp = ""; + for (int i = 0; i < arr.size(); ++i) { + + ITObject obj = arr.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + if (acc != null) { + obj.putString("nick", acc.nick); + } else { + obj.putString("nick", StringUtil.Empty); + } + // + strtmp = String.format( + "SELECT IFNULL(SUM(hp), 0) AS reward_hp from group_hp_log where gid=%s and reason=7 and uid=%s and time >=%s AND time <%s", + groupId, acc.id, beginTime, endTime); + ITArray arrtmp = DataBase.use().executeQueryByTArray(strtmp); + if (arrtmp.size() > 0) { + obj.putDouble("`pump`", arrtmp.getTObject(0).getDouble("reward_hp")); + } else { + obj.putInt("pump", 0); + } + } + } finally { + jedis9.close(); + } + } + obj1.putTArray("members", arr); + obj1.putInt("limit", limit); + + return obj1; + } + + /** + * 获取战绩列表 + * + * @param platform + * @param groupId + * @param limit + * @param num + * @return + */ + public static ITObject getRecords(String platform, int groupId, int limit, int num, int qid, int uid, + int includeMembers, int timeType, int beginTime, int endTime) throws Exception { + + boolean find = true; + boolean mgr = true; + boolean tagIsPartner = false; + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + + GroupMemberBean mng = GroupCache.getMember(groupId, uid); + int _lev = mng.lev; + mgr = _lev < 3; + + if (qid > 0) { + + GroupMemberBean tag = GroupCache.getMember(groupId, qid); + if (tag != null) { + + int parentId = tag.parentId; + if (!mgr) { + + if (parentId == 0) { + + find = false; + } else { + + if (tag.partnerLev > 0) { + tagIsPartner = true; + } + List par_list = Utility.getMemberParents(jedis10, groupId, + includeMembers == 0 ? parentId : qid, true); + if (par_list == null || !par_list.contains(uid)) { + + find = false; + } + } + } + } else { + + find = false; + } + } + } finally { + jedis10.close(); + } + + ITArray militaryList = TArray.newInstance(); + if (find) { + + String where = StringUtil.Empty; + if (timeType == 0) { + + where = String.format("gid=%s and time>=%s and time<=%s", groupId, beginTime, endTime); + } else if (timeType == 1) { + + beginTime = DateUtils.getBeginMonth(); + where = String.format("gid=%s and time>=%s", groupId, beginTime); + } else if (timeType == 2) { + + beginTime = DateUtils.getBeginLastMonth(); + endTime = DateUtils.getBeginMonth(); + where = String.format("gid=%s and time>=%s and time<=%s", groupId, beginTime, endTime); + } else { + beginTime = DateUtils.getBeginDay() - 259200; + endTime = DateUtils.getEndDay(); + where = String.format("gid=%s and time>=%s and time<=%s", groupId, beginTime, endTime); + } + + if (qid == 0) { + if (!mgr) { + String p = Utility.getChildParentSql(groupId, uid, true); + where += String.format(" and (parentId in(%s) or uid = %s)", p, uid); + } + } else { + + if (includeMembers == 1) { + + String p; + if (tagIsPartner) { + p = Utility.getChildParentSql(groupId, qid, true); + where += String.format(" and (parentId in(%s) or uid = %s)", p, qid); + } else { + where += " and uid=" + qid; + } + } else { + where += " and uid=" + qid; + } + } + + String sql = String.format("select rec_key from room_rec_log where %s ORDER BY time desc limit %s,%s", + where, limit, num); + + ITArray list = DataBase.use().executeQueryByTArray(sql); + + if (list.size() > 0) { + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + for (int i = 0; i < list.size(); ++i) { + ITObject tem = list.getTObject(i); + String rec_key = tem.getString("rec_key"); + ITObject obj = Utility.getMilitaryList(jedis5, rec_key, platform); + if (obj == null) { + continue; + } + militaryList.addTObject(obj); + } + } finally { + jedis5.close(); + } + } + } + + ITObject obj1 = TObject.newInstance(); + obj1.putTArray("records", militaryList); + obj1.putInt("limit", limit); + return obj1; + } + + /** + * 根据房间ID查询战绩 + * + * @param platform + * @param groupId + * @param roomid + * @return + */ + public static ITArray findRecordByRoom(String platform, int groupId, String roomid, int uid) throws Exception { + if (StringUtil.isNotEmpty(roomid)) { + if (roomid.length() != 6) { + return null; + } + } + boolean find = false; + int time3last = DateUtils.getBeginDay() - 259200; + String sql = String.format("select rec_key,uid from room_rec_log where gid=%s and roomid='%s' and time>=%s", + groupId, roomid, time3last); + ITArray list = DataBase.use().executeQueryByTArray(sql); + if (list.size() == 0) + return null; + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean mng = GroupCache.getMember(groupId, uid); + int _lev = mng.lev; + boolean mgr = _lev < 3; + if (!mgr) { + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + int id = obj.getInt("uid"); + if (id == uid) { + find = true; + break; + } + GroupMemberBean tag = GroupCache.getMember(groupId, id); + if (tag == null) + continue; + int par = tag.parentId; + if (par == 0) + continue; + List par_list = Utility.getMemberParents(jedis10, groupId, par, true); + if (par_list != null && par_list.contains(uid)) { + find = true; + break; + } + } + } else { + find = true; + } + } finally { + jedis10.close(); + } + if (!find) + return null; + + ITArray militaryList = TArray.newInstance(); + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + for (int i = 0; i < list.size(); i++) { + String rec_key = list.getTObject(i).getString("rec_key"); + ITObject data = Utility.getMilitaryList(jedis5, rec_key, platform); + boolean flag = true; + for (int j = 0; j < militaryList.size(); j++) { + ITObject temp = militaryList.getTObject(j); + String temp_create_time = temp.getString("create_time"); + String create_time = data.getString("create_time"); + String temp_rec_key = temp.getString("military_id"); + + if (temp_rec_key.equals(rec_key) && create_time.equals(temp_create_time)) { + flag = false; + break; + } + } + + if (flag) { + militaryList.addTObject(data); + } + } + + return militaryList; + } finally { + jedis5.close(); + } + } + + /** + * + * @param groupId + * @param uid + * @param limit + * @param num + * @param type 1上分 2下分 3合伙人上分 4合伙人下分 + * @return + * @throws Exception + */ + public static final ITObject getHpLogMgr(int groupId, int uid, int limit, int num, int type, int qid, + String tagName) throws Exception { + GroupMemberBean mng = GroupCache.getMember(groupId, uid); + int beginDay = DateUtils.getBeginDay(); + int beginTime = beginDay - 9 * 24 * 3600; + if (mng.lev >= 3) { + beginTime = beginDay - 2 * 24 * 3600; + } + + long endTime = DateUtils.getEndDay(); + + int reason = MGRLOG_TYPE[type - 1]; + String mgr_sql = StringUtil.Empty; + String qid_sql = StringUtil.Empty; + + ITArray arr = null; + + if (type > 2) { + + mgr_sql = "and A.mgr_id=" + uid; + + if (StringUtil.isNotEmpty(tagName) || qid > 0) { + + if (qid > 0) { + + qid_sql = "and A.uid=" + qid; + + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format( + "SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + arr = DataBase.use().executeQueryByTArray(sql); + } + + if (StringUtil.isNotEmpty(tagName)) { + + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format("SELECT A.uid,A.mgr_id,A.hp,A.cur_hp,A.time " + "FROM group_hp_log as A " + + "RIGHT JOIN account as B " + "ON A.uid = B.id and B.nick like '%%%s%%' " + + "%s ORDER BY time desc " + "limit %s,%s", tagName, where_sql, limit, num); + + ITArray temp = DataBase.use().executeQueryByTArray(sql); + if (temp.size() > 0) { + if (arr == null) { + arr = temp; + } else { + + for (int i = 0; i < temp.size(); i++) { + ITObject mo = temp.getTObject(i); + if (qid > 0 && mo.getInt("uid") == qid) { + continue; + } + arr.addTObject(temp.getTObject(i)); + } + } + } + } + } else { + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format( + "SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + arr = DataBase.use().executeQueryByTArray(sql); + } + } else { + + if (StringUtil.isNotEmpty(tagName) || qid > 0) { + + if (qid > 0) { + qid_sql = "and (A.uid=" + qid; + qid_sql += " or A.mgr_id=" + qid + ")"; + + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format( + "SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + arr = DataBase.use().executeQueryByTArray(sql); + } + + if (StringUtil.isNotEmpty(tagName)) { + + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format("SELECT A.uid,A.mgr_id,A.hp,A.cur_hp,A.time " + "FROM group_hp_log as A " + + "RIGHT JOIN account as B " + + "ON (A.uid = B.id OR A.mgr_id = B.id) and B.nick like '%%%s%%' " + + "%s ORDER BY time desc " + "limit %s,%s", tagName, where_sql, limit, num); + + ITArray temp = DataBase.use().executeQueryByTArray(sql); + if (temp.size() > 0) { + if (arr == null) { + arr = temp; + } else { + + for (int i = 0; i < temp.size(); i++) { + + ITObject mo = temp.getTObject(i); + if (qid > 0 && mo.getInt("uid") == qid) { + continue; + } + arr.addTObject(temp.getTObject(i)); + } + } + } + + } + } else { + + String where_sql = String.format( + "WHERE A.gid = %s " + "and A.reason = %s " + "and A.time>=%s " + "and A.time <=%s %s %s", + groupId, reason, beginTime, endTime, mgr_sql, qid_sql); + + String sql = String.format( + "SELECT uid,mgr_id,hp,cur_hp,time FROM group_hp_log as A %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + arr = DataBase.use().executeQueryByTArray(sql); + } + + } + + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + + if (arr != null) { + + for (int i = 0; i < arr.size(); ++i) { + + ITObject obj = arr.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + obj.putString("t_nick", acc.nick); + acc = AccountCache.getAccount(obj.getInt("mgr_id")); + obj.putString("m_nick", acc.nick); + } + resData.putTArray("hp_logs", arr); + } + + return resData; + } + + /** + * 获取体力值管理统计数据 + * + * @param groupId + * @return + * @throws Exception + */ + public static final ITObject getHpLogMgrCount(int groupId) throws Exception { + int beginTime = DateUtils.getBeginDay() - 9 * 24 * 3600; + long upper_count = 0; + long sub_count = 0; + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + String str = null; + for (int i = 0; i < 10; ++i) { + String hp_mgr_upper_key = String.format("g%s:hp_mgr:upper:d%s", groupId, beginTime); + String hp_mgr_sub_key = String.format("g%s:hp_mgr:sub:d%s", groupId, beginTime); + str = jedis9.get(hp_mgr_upper_key); + if (StringUtil.isNotEmpty(str)) { + upper_count += Long.parseLong(str); + } + str = jedis9.get(hp_mgr_sub_key); + if (StringUtil.isNotEmpty(str)) { + sub_count += Long.parseLong(str); + } + beginTime += 24 * 3600; + } + String hp_cost_key = String.format("g%s:hp_cost:d%s", groupId, DateUtils.getBeginDay()); + long hp_cost_count = 0; + str = jedis9.get(hp_cost_key); + if (StringUtil.isNotEmpty(str)) { + hp_cost_count += Long.parseLong(str); + } + + hp_cost_key = String.format("g%s:hp_cost:d%s", groupId, DateUtils.getBeginLastday()); + long last_hp_cost_count = 0; + str = jedis9.get(hp_cost_key); + if (StringUtil.isNotEmpty(str)) { + last_hp_cost_count += Long.parseLong(str); + } + ITObject resData = TObject.newInstance(); + resData.putLong("hp_cost", hp_cost_count); + resData.putLong("last_hp_cost", last_hp_cost_count); + resData.putLong("hp_upper", upper_count); + resData.putLong("hp_sub", sub_count); + return resData; + } finally { + jedis9.close(); + } + } + + /** + * 获取体力值管理员详细信息 + * + * @param jedis9 + * @param groupId + * @param uid + * @param beginTime + * @param endTime + * @param mgr + * @return + */ + private static final ITObject _getHpLogMgrInfo(Jedis jedis9, int groupId, int uid, int beginTime, int endTime, + boolean mgr) { + long upper_count = 0; + long sub_count = 0; + AccountBean acc = AccountCache.getAccount(uid); + String str = null; + int tem = beginTime; + int tem_day = (endTime - beginTime) / 86400; + String hp_key = mgr ? "hp_mgr" : "hp_par"; + for (int k = 0; k < tem_day; ++k) { + String hp_mgr_upper_key = String.format("g%s:%s:upper:u%s:d%s", groupId, hp_key, uid, tem); + String hp_mgr_sub_key = String.format("g%s:%s:sub:u%s:d%s", groupId, hp_key, uid, tem); + str = jedis9.get(hp_mgr_upper_key); + if (StringUtil.isNotEmpty(str)) { + upper_count += Long.parseLong(str); + } + str = jedis9.get(hp_mgr_sub_key); + if (StringUtil.isNotEmpty(str)) { + sub_count += Long.parseLong(str); + } + + tem += 86400; + } + ITObject info = TObject.newInstance(); + info.putLong("hp_upper", upper_count); + info.putLong("hp_sub", sub_count); + info.putString("nick", acc.nick); + if (mgr) { + String gm_key = "gm_" + groupId + "_" + uid; + String lev_str = Redis.use("group1_db10").hget(gm_key, "lev"); + info.putInt("lev", StringUtil.isEmpty(lev_str) ? 2 : Integer.parseInt(lev_str)); + } + return info; + } + + /** + * 获取体力值管理员详细信息 + * + * @param groupId + * @param uid 操作人 + * @param beginTime + * @param endTime + * @param type 1 管理员 2合伙人 + * @return + * @throws Exception + */ + public static final ITArray getHpLogMgrInfo(int groupId, int uid, int beginTime, int endTime, int type) + throws Exception { + if (type == 1) { + String sql = String.format("SELECT uid FROM group_member WHERE groupId =%s AND lev <3", groupId); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + ITArray list = TArray.newInstance(); + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + ITObject info = _getHpLogMgrInfo(jedis9, groupId, obj.getInt("uid"), beginTime, endTime, type == 1); + list.addTObject(info); + } + + return list; + } finally { + jedis9.close(); + } + } else { + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + ITArray list = TArray.newInstance(); + ITObject info = _getHpLogMgrInfo(jedis9, groupId, uid, beginTime, endTime, type == 1); + list.addTObject(info); + return list; + } finally { + jedis9.close(); + } + } + + } + + /** + * 体力值抽水记录 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @param choose + * @return + */ + public static final ITObject getHpLogPumpInfo(int groupId, int uids, int limit, int num, int beginTime, int endTime) + throws Exception { + String where_sql = String.format("WHERE gid = %s and reason = %s and time>=%s and time <=%s", groupId, + ConsumeCode.HP_PUMP, beginTime, endTime); + + String sql = String.format("SELECT uid,hp,roomid,pid,time FROM group_hp_log %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + int uid = obj.getInt("uid"); + AccountBean acc = AccountCache.getAccount(uid); + obj.putString("nick", acc.nick); + } + int hp_cost = 0; + int hp_reward = 0; + int count = 0; + int valid_count = 0; + int reward_hpnum = 0; + + if (limit == 0) { + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + String hp_cost_key = String.format("g%s:hp_cost", groupId); + String hp_reward_key = String.format("g%s:hp_reward", groupId); + String total_round = String.format("g%s:round", groupId); + String valid_round = String.format("g%s:valid_room", groupId); + // String reward_hp = String.format("g{%s}:m%s:", groupId,uids); + hp_cost = _getCountValue(jedis9, hp_cost_key, beginTime, endTime); + hp_reward = _getCountValue(jedis9, hp_reward_key, beginTime, endTime); + count = _getCountValue(jedis9, total_round, beginTime, endTime); + valid_count = _getCountValue(jedis9, valid_round, beginTime, endTime); + // reward_hpnum = _getCountValue(jedis9,reward_hp + + // "reward_log",beginTime,endTime); + + } finally { + jedis9.close(); + } + } + + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + resData.putTArray("hp_logs", arr); + // 计算群主每日抽水 + GroupBean gb = GroupCache.getGroup(groupId); + String pumpwhere_sql = String.format( + " WHERE gid = %s and uid=%s and reason = %s and time>=%s and time <=%s AND info != '' ", groupId, + gb.owner, ConsumeCode.HP_PARTNER_REWARD, beginTime, endTime); + String pumpsql = String.format("SELECT ifnull(sum(hp),0) as hp FROM group_hp_log %s ", pumpwhere_sql); + + ITArray resultArray = DataBase.use().executeQueryByTArray(pumpsql); + if (resultArray.size() == 0) { + resData.putInt("pump", 0); + } else { + ITObject dbData = resultArray.getTObject(0); + Double pump = dbData.getDouble("hp"); + String xipaiwhere_sql = String.format( + " WHERE gid = %s and reason=%s and time>=%s and time <=%s AND info != '' ", groupId, + ConsumeCode.HP_XIPAI_PUMP, beginTime, endTime); + String xipaisql = String.format("SELECT ifnull(sum(hp),0) as hp FROM group_hp_log %s ", xipaiwhere_sql); + ITArray xipaiArray = DataBase.use().executeQueryByTArray(xipaisql); + + if (xipaiArray.size() == 0) { + resData.putDouble("pump", pump); + } else { + ITObject xipaiData = xipaiArray.getTObject(0); + resData.putDouble("pump", pump - xipaiData.getDouble("hp")); + + } + + } +// resData.putInt("pump", hp_cost); + + resData.putInt("gains", hp_cost - hp_reward); + resData.putInt("count", count); + resData.putInt("valid_count", valid_count); + + return resData; + } + + /** + * 体力值详情 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @param choose + * @return + */ + public static final ITObject getHpLogInfo(int groupId, int tagId, int limit, int num, int choose, int beginTime, + int endTime) throws Exception { + String reason_sql = StringUtil.Empty; + if ((choose & CHOOSE_UPPER) != 0) { + reason_sql += ConsumeCode.HP_MGR_UPPER + "," + ConsumeCode.HP_PARTNER_UPPER + ","; + reason_sql += ConsumeCode.HP_MGR_SUB + "," + ConsumeCode.HP_PARTNER_SUB + ","; + } + if ((choose & CHOOSE_SUB) != 0) { + reason_sql += ConsumeCode.HP_MGR_SUB + "," + ConsumeCode.HP_PARTNER_SUB + ","; + } + if ((choose & CHOOSE_PUMP) != 0) { + reason_sql += ConsumeCode.HP_PUMP + ","; + } + if ((choose & CHOOSE_RWARD) != 0) { + reason_sql += ConsumeCode.HP_PARTNER_REWARD + ","; + } + if ((choose & CHOOSE_CHAGE) != 0) { + reason_sql += ConsumeCode.HP_PUMP_TOTAL + ","; + } + if ((choose & CHOOSE_TRADE) != 0) { + reason_sql += ConsumeCode.HP_TRADE + ","; + } + if ((choose & CHOOSE_TAKE_REWARD) != 0) { + reason_sql += ConsumeCode.HP_TAKE_REWARD + ","; + } + if ((choose & CHOOSE_XIPAI) != 0) { + reason_sql += ConsumeCode.HP_PARTNER_XIPAI_REWARD + ","; + } +// reason_sql +=ConsumeCode.HP_CLEARING+ ","; + + if (StringUtil.isNotEmpty(reason_sql)) { + reason_sql = reason_sql.substring(0, reason_sql.length() - 1); + } else { + reason_sql = "0"; + } + + // int time = DateUtils.getBeginDay() - 2 * 24 * 3600; + + String where_sql = String.format("WHERE gid = %s and uid =%s and reason in(%s) and time > %s and time < %s", + groupId, tagId, reason_sql, beginTime, endTime); + String sql = String.format("SELECT pid,mgr_id,hp,reason,cur_hp,time,info,roomid " + "FROM group_hp_log %s " + + "ORDER BY time desc " + "limit %s,%s", where_sql, limit, num); + log.info("getHpLogInfo sql:" + sql); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + int mgr_id = obj.getInt("mgr_id"); + if (mgr_id > 0) { + AccountBean acc = AccountCache.getAccount(obj.getInt("mgr_id")); + obj.putString("m_nick", acc.nick); + } + } + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + resData.putTArray("hp_logs", arr); + return resData; + } + + /** + * 体力值详情 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @param choose + * @return + */ + public static final ITObject getHpLogDetailInfo(int groupId, int tagId, String roomId, int time) throws Exception { + String reason_sql = StringUtil.Empty; + reason_sql += ConsumeCode.HP_CLEARING + ","; + reason_sql += ConsumeCode.HP_PUMP + ","; + reason_sql += ConsumeCode.HP_XIPAI_PUMP + ","; + if (StringUtil.isNotEmpty(reason_sql)) { + reason_sql = reason_sql.substring(0, reason_sql.length() - 1); + } else { + reason_sql = "0"; + } + + String where_sql = String.format( + "WHERE gid = %s and uid =%s and reason in(%s) and roomId ='%s' and time >= %s and time <= %s and hp!=0", groupId, + tagId, reason_sql, roomId, time - 7200, time + 3600); + String sql = String.format( + "SELECT mgr_id,hp,reason,cur_hp,time,info,roomid " + "FROM group_hp_log %s " + "ORDER BY time desc", + where_sql); + try { + ITArray arr = DataBase.use().executeQueryByTArray(sql); + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + int mgr_id = obj.getInt("mgr_id"); + if (mgr_id > 0) { + AccountBean acc = AccountCache.getAccount(obj.getInt("mgr_id")); + obj.putString("m_nick", acc.nick); + } + } + ITObject resData = TObject.newInstance(); + resData.putTArray("hp_logs", arr); + return resData; + } catch (Exception e) { + log.info("sql error:" + sql); + log.error(e); + } + + ITObject resData = TObject.newInstance(); + return resData; + } + + private static final int _getCountValue(Jedis jedis9, String key, int beginTime, int endTime) { + String str = null; + int tem = beginTime; + int tem_day = (endTime - beginTime) / 86400; + int count = 0; + for (int k = 0; k < tem_day; ++k) { + String tem_key = String.format("%s:d%s", key, tem); + str = jedis9.get(tem_key); + if (StringUtil.isNotEmpty(str)) { + count += Integer.parseInt(str); + } + tem += 86400; + } + return count; + } + + private static final int _getValue(Jedis jedis9, String key) { + + int count = 0; + String str = jedis9.get(key); + if (StringUtil.isNotEmpty(str)) { + count = Integer.parseInt(str); + } + return count; + } + + private static final int _getCountNumValue(Jedis jedis9, String key, int beginTime, int endTime) { + String str = null; + int tem = beginTime; + int tem_day = (endTime - beginTime) / 86400; + int count = 0; + for (int k = 0; k < tem_day; ++k) { + String tem_key = String.format("%s:d%s", key, tem); + str = jedis9.get(tem_key); + if (StringUtil.isNotEmpty(str)) { + count++; + } + tem += 86400; + } + return count; + } + + private static final int _getNumValue(Jedis jedis9, String key) { + + int count = 0; + String str = jedis9.get(key); + if (StringUtil.isNotEmpty(str)) { + count++; + } + return count; + } + + /** + * 获取奖励日志 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @param beginTime + * @param endTime + * @return + * @throws Exception + */ + public static final ITObject getRewardLog(int groupId, int tagId, int limit, int num, int beginTime, int endTime) + throws Exception { + String where_sql = String.format( + "WHERE gid = %s and (reason = %s or reason = %s ) and time>=%s and time <=%s and uid=%s and hp != 0", + groupId, ConsumeCode.HP_PARTNER_REWARD, ConsumeCode.HP_PARTNER_XIPAI_REWARD, beginTime, endTime, tagId); + int total_num = 0; + int total_hp = 0; + if (limit == 0) { + String count_sql = String.format( + "SELECT IFNULL(SUM(round),0) AS num,IFNULL(SUM(hp),0) AS total_hp FROM group_hp_log %s", where_sql); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + total_num = obj.getDouble("num").intValue(); + total_hp = obj.getDouble("total_hp").intValue(); + } + } + + String sql = String.format( + "SELECT hp,pid,roomid,time,round,reason,info FROM group_hp_log %s ORDER BY time desc limit %s,%s", + where_sql, limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + resData.putTArray("reward_logs", arr); + resData.putInt("total_num", total_num); + resData.putInt("total_hp", total_hp); + return resData; + } + + /** + * 奖励统计 + * + * @param groupId + * @param pid + * @param beginTime + * @param endTime + * @return + */ + public static final ITObject getRewardLogCount(int groupId, int pid, int beginTime, int endTime) { + String p_key = pid > 0 ? (":p" + pid) : StringUtil.Empty; + String valid_key = String.format("g%s:valid_room%s", groupId, p_key); + String round_key = String.format("g%s:round%s", groupId, p_key); + String hp_cost_key = String.format("g%s:hp_cost%s", groupId, p_key); + String hp_reward_key = String.format("g%s:hp_reward%s", groupId, p_key); + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + int v_round = _getCountValue(jedis9, valid_key, beginTime, endTime); + int round = _getCountValue(jedis9, round_key, beginTime, endTime); + int hp_cost = _getCountValue(jedis9, hp_cost_key, beginTime, endTime); + int hp_reward = _getCountValue(jedis9, hp_reward_key, beginTime, endTime); + ITObject resData = TObject.newInstance(); + resData.putInt("v_round", v_round); + resData.putInt("round", round); + resData.putInt("hp_cost", hp_cost); + resData.putInt("gains", hp_cost - hp_reward); + return resData; + } finally { + jedis9.close(); + } + + } + + /** + * 体力值提取记录 + * + * @param groupId + * @param tagid + * @param limit + * @param num + * @param beginTime + * @param endTime + * @return + * @throws Exception + */ + public static final ITObject getHpLogTakeInfo(int groupId, int uid, int tagId, int limit, int num, int beginTime, + int endTime) throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + String where_sql = String.format("WHERE gid = %s and uid=%s and reason = %s and time>=%s and time <=%s", + groupId, tagId, ConsumeCode.HP_TAKE_REWARD, beginTime, endTime); + + String sql = String.format("SELECT hp,time FROM group_hp_log %s ORDER BY time desc limit %s,%s", where_sql, + limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + resData.putTArray("hp_logs", arr); + return resData; + } + + public static final ITObject getHpLogTakeBankInfo(int groupId, int uid, int tagId, int limit, int num, + int beginTime, int endTime) throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + String where_sql = String.format( + "WHERE gid = %s and uid=%s and (reason = %s or reason = %s) and time>=%s and time <=%s", groupId, tagId, + ConsumeCode.HP_TAKE_BANK, ConsumeCode.HP_SAVE_BANK, beginTime, endTime); + + String sql = String.format("SELECT hp,time FROM group_hp_log %s ORDER BY time desc limit %s,%s", where_sql, + limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + ITObject resData = TObject.newInstance(); + resData.putInt("limit", limit); + resData.putTArray("hp_logs", arr); + return resData; + } + + /** + * 获取消耗统计 + * + * @param groupId + * @return + */ + public static final ITArray getCostCount(int groupId, int uid, int beginTime, int endTime) { + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 10, 11); + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITArray arr = TArray.newInstance(); + try { + if (uid_bean.lev < 3) { + for (String pid : pids) { + + ITObject obj = TObject.newInstance(); + + String round_key = String.format("g%s:round:p%s", groupId, pid); + obj.putInt("round", _getCountValue(jedis9, round_key, beginTime, endTime) * 100); + + String valid_key = String.format("g%s:valid_room:p%s", groupId, pid); + obj.putInt("valid", _getCountValue(jedis9, valid_key, beginTime, endTime) * 100); + + String no_valid_key = String.format("g%s:no_valid_room:p%s", groupId, pid); + obj.putInt("no_valid", _getCountValue(jedis9, no_valid_key, beginTime, endTime) * 100); + + String diamo_cost_key = String.format("g%s:diamo_cost:p%s", groupId, pid); + obj.putInt("diamo_cost", _getCountValue(jedis9, diamo_cost_key, beginTime, endTime) * 100); + + obj.putInt("pid", Integer.parseInt(pid)); + + arr.addTObject(obj); + } + } else { + for (String pid : pids) { + + ITObject obj = TObject.newInstance(); + String round_key = String.format("g{%s}:m%s:all_count:p%s", groupId, uid, pid); + int all_round = _getCountValue(jedis9, round_key, beginTime, endTime); + obj.putInt("round", all_round); + + String valid_key = String.format("g{%s}:m%s:valid_round2:p%s", groupId, uid, pid); + int valid = _getCountValue(jedis9, valid_key, beginTime, endTime); + obj.putInt("valid", valid); + + int no_valid_key = all_round - valid; + obj.putInt("no_valid", no_valid_key); + + String diamo_cost_key = String.format("g{%s}:m%s:valid_diamo:p%s", groupId, uid, pid); + obj.putInt("diamo_cost", _getCountValue(jedis9, diamo_cost_key, beginTime, endTime)); + + obj.putInt("pid", Integer.parseInt(pid)); + + arr.addTObject(obj); + } + } + } finally { + jedis9.close(); + } + return arr; + } + + /** + * 获取局数统计 + * + * @param groupId + * @return + */ + public static final ITArray getRoundCount(int groupId, int pid) { + int bengin = DateUtils.getBeginDay() - 29 * 86400; + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITArray arr = TArray.newInstance(); + try { + String p_key = pid > 0 ? (":p" + pid) : StringUtil.Empty; + for (int i = 0; i < 30; ++i) { + String round_key = String.format("g%s:round%s:d%s", groupId, p_key, bengin); + String r_str = jedis9.get(round_key); + ITObject obj = TObject.newInstance(); + obj.putInt("time", bengin); + int r_num = 0; + if (StringUtil.isNotEmpty(r_str)) { + r_num = Integer.parseInt(r_str); + } + obj.putInt("num", r_num); + arr.addTObject(obj); + bengin += 86400; + } + } finally { + jedis9.close(); + } + return arr; + } + + /** + * 获取体力值消耗统计 + * + * @param groupId + * @return + */ + public static final ITArray getHpConsumeCount(int groupId, int uid) { + int bengin = DateUtils.getBeginDay() - 2 * 86400; + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITArray arr = TArray.newInstance(); + try { + String key = String.format("g%s:m%s:consume_hp", groupId, uid); + for (int i = 0; i < 3; ++i) { + String hp_key = String.format("%s:d%s", key, bengin); + String r_str = jedis9.get(hp_key); + ITObject obj = TObject.newInstance(); + obj.putInt("time", bengin); + int r_num = 0; + if (StringUtil.isNotEmpty(r_str)) { + r_num = Integer.parseInt(r_str); + } + obj.putInt("num", r_num); + arr.addTObject(obj); + bengin += 86400; + } + } finally { + jedis9.close(); + } + return arr; + } + + /** + * 获取体力值统计信息 + * + * @param groupId + * @return + * @throws Exception + */ + public static final ITObject getHpCountInfo(int groupId) throws Exception { + String sql = String.format("SELECT uid FROM group_member WHERE groupId=%s" + " AND partnerLev >0", groupId); + ITArray list = DataBase.use().executeQueryByTArray(sql); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + int _t_hp = 0; + try { + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + int parentId = obj.getInt("uid"); + String key = String.format("g{%s}:m%s:reward_hp", groupId, parentId); + String r_hp = jedis10.get(key); + if (StringUtil.isNotEmpty(r_hp)) { + _t_hp += Integer.parseInt(r_hp); + } + } + } finally { + jedis10.close(); + } + String where = String.format("FROM group_member WHERE groupId = %s", groupId); + String count_sql = String.format("SELECT (SELECT IFNULL(SUM(hp),0) %s AND hp >0) t_hp1," + + " (SELECT IFNULL(SUM(ABS(hp)),0) %s AND hp <0) t_hp2", where, where); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + ITObject obj1 = TObject.newInstance(); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + obj1.putLong("hp_num1", obj.getDouble("t_hp1").longValue()); + obj1.putLong("hp_num2", obj.getDouble("t_hp2").longValue()); + } else { + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + } + obj1.putLong("hp_num3", _t_hp); + return obj1; + } +} diff --git a/web_group/src/main/java/com/group/service/GroupPublisherService.java b/web_group/src/main/java/com/group/service/GroupPublisherService.java new file mode 100644 index 0000000..a01848d --- /dev/null +++ b/web_group/src/main/java/com/group/service/GroupPublisherService.java @@ -0,0 +1,117 @@ +package com.group.service; + +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_ADD_ROOM = "add_room"; + private static final String CMD_DEL_ROOM = "del_room"; + private static final String CMD_DEL_PLAY = "del_play"; + private static final String CMD_ADD_PLAY = "add_play"; + private static final String CMD_UPDATE_PLAY = "update_play"; + private static final String CMD_DEL_GROUP = "del_group"; + private static final String CMD_UPDATE_GROUP = "update_group"; + + private static final String CMD_UPDATE_JOINS = "update_joins"; + private static final String CMD_UPDATE_MAIL_TIP = "update_mail_tip"; +// private static final String CMD_UPDATE_MEMBER = "update_member"; + + public static void addRoomEvt(int groupId, String roomid) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putString("roomid", roomid); + data.putString("cmd", CMD_ADD_ROOM); + 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()); + } + + public static void delPlayEvt(int groupId, int pid) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putInt("pid", pid); + data.putString("cmd", CMD_DEL_PLAY); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void addPlayEvt(int groupId, int pid) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putInt("pid", pid); + data.putString("cmd", CMD_ADD_PLAY); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void updatePlayEvt(int groupId, int pid) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putInt("pid", pid); + data.putString("cmd", CMD_UPDATE_PLAY); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void delGroupEvt(int groupId) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putString("cmd", CMD_DEL_GROUP); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void updateGroupEvt(int groupId, String name, boolean ban,String notice,int option,int showNum) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putString("cmd", CMD_UPDATE_GROUP); + data.putString("name", name); + data.putBoolean("ban", ban); + data.putString("notice", notice); + data.putInt("option", option); + data.putInt("show_num", showNum); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void updateJoinsEvt(int groupId, int joins) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putInt("joins", joins); + data.putString("cmd", CMD_UPDATE_JOINS); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + public static void updateMailTipEvt(int groupId, int uid) { + ITObject data = TObject.newInstance(); + data.putInt("gid", groupId); + data.putInt("uid", uid); + data.putString("cmd", CMD_UPDATE_MAIL_TIP); + Redis.use("group1_db11").publish(CHANNEL_NAME, data.toJson()); + } + + /** + * 1 hp 2 等级 3 合伙人等级 + * + * @param groupId + * @param uid + * @param type + * @param value + */ + public static void updateMemberEvt(int groupId, int uid, int type, int value) { +// if (type == 1) { +// return; +// } +// 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()); + } +} diff --git a/web_group/src/main/java/com/group/service/GroupRoomService.java b/web_group/src/main/java/com/group/service/GroupRoomService.java new file mode 100644 index 0000000..c5dba49 --- /dev/null +++ b/web_group/src/main/java/com/group/service/GroupRoomService.java @@ -0,0 +1,1140 @@ +package com.group.service; + +import java.util.*; + +import com.data.bean.*; +import com.data.cache.AccountCache; +import com.data.cache.BaseCache; +import com.data.cache.GameCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupMemberCache; +import com.data.util.ErrorCode; +import com.data.util.EventType; +import com.data.util.Utility; +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.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.web.WebException; + +import jdk.nashorn.internal.objects.Global; +import redis.clients.jedis.Jedis; + +public class GroupRoomService { + private static final Logger log = Logger.getLogger(GroupRoomService.class); + + /** 解散时间 */ + private static final String[] DISMISS_TIME = { "30", "60", "90", "180" }; + /** 踢出时间 */ + private static final String[] KICK_TIME = { "30", "60", "120", "180" }; + + private static final String _getSvr(Jedis jedis0, GameBean gb) { + String svr = null; + Set gamesvrs = gb.svr_list; + Integer conns = null; + for (String str : gamesvrs) { + String currConns = jedis0.hget(str, "conns"); + if (conns == null && currConns != null + || (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) { + conns = Integer.parseInt(currConns); + svr = str; + } + } + return svr; + } + + private final static String createGroupRoom(String session, int groupId, int pid) throws Exception { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb == null) { + throw new WebException(ErrorCode.GROUP_PLAY_EXIST); + } + + int gameId = gpb.gameId; + GameBean gb = GameCache.getGame(gameId); + String svr = _getSvr(jedis0, gb); + if (svr == null) { + log.error("createGroupRoom gameId:" + gameId + " svr:" + svr); + throw new WebException(ErrorCode.NO_SERVICE); + } + + String grooms_key = GroupCache.genRoomsKey(groupId); + GroupBean group = GroupCache.getGroup(groupId); + ITObject configData = TObject.newFromJsonData(gpb.config); + int maxPlayers = gpb.maxPlayers; + + int opt = configData.getInt("opt"); + + String owner_session = AccountCache.genKey(group.owner); + Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers); + if (pay == null) { + log.warn("pay no set!"); + throw new WebException(ErrorCode._FAILED); + } + + if (pay > 0) { + ArrayList result_list = Utility.payDiamo(jedis0, owner_session, pay); + if (result_list == null) { + throw new WebException(ErrorCode._FAILED); + } + long result = result_list.get(0); + if (result != 0) { + log.error("createGroupRoom groupId:" + groupId + " pid:" + pid + " group.owner:" + group.owner + + " no diamo"); + throw new WebException(ErrorCode.NO_DIAMO); + } + long cur_diamo = result_list.get(1); + Utility.payDiamo(EventType.REDIS_EVENT_GROUP_ROOM, group.owner, gameId, pay, (int) cur_diamo, groupId, + pid); + } + + int dissolve_opt = group.dissolve_opt; + int kick_opt = group.kick_opt; + + String newRoomId = Redis.use("group1_db1").rpop("free_room"); + Redis.use("group1_db1").lpush("free_room", newRoomId); + String room_key = "room:" + newRoomId; + + long time = System.currentTimeMillis() / 1000; + Map roomMap = new HashMap(); + roomMap.put("id", newRoomId); + roomMap.put("owner", owner_session); + roomMap.put("svr", svr); + roomMap.put("AA", "0"); + roomMap.put("pay", pay + ""); + roomMap.put("agent", "1"); + roomMap.put("group", groupId + ""); + roomMap.put("gpid", pid + ""); + roomMap.put("payer", group.owner + ""); + roomMap.put("maxPlayers", maxPlayers + ""); + roomMap.put("times", gb.opt.get(opt) + ""); + roomMap.put("opt", opt + ""); + roomMap.put("status", "0"); + roomMap.put("hpOnOff", gpb.hpOnOff + ""); + roomMap.put("rewardType", gpb.rewardType + ""); + roomMap.put("rewardValueType", gpb.rewardValueType + ""); + roomMap.put("xipai_rewardType", gpb.xipai_rewardType + ""); + roomMap.put("xipai_rewardValueType", gpb.xipai_rewardValueType + ""); + roomMap.put("dismiss_time", DISMISS_TIME[dissolve_opt - 1]); + roomMap.put("kick_time", KICK_TIME[kick_opt - 1]); + roomMap.put("hp_times", gpb.hp_times + ""); + if (gpb.hpOnOff == 1) { + ITObject hpObj = TObject.newFromJsonData(gpb.hpConfig); + if (hpObj.getInt("limitInRoom") != null) { + roomMap.put("limitInRoom", hpObj.getInt("limitInRoom") + ""); + } + configData.putTObject("hpData", hpObj); + } + + configData.del("opt"); + configData.del("AA"); + roomMap.put("options", configData.toJson()); + roomMap.put("game", gameId + ""); + roomMap.put("open", "1"); + roomMap.put("round", "0"); + roomMap.put("create_time", time + ""); + roomMap.put("cache_ver", "1"); + jedis0.hmset(room_key, roomMap); + + /** + * pid open status 剩余空位 11 1 1 00 + */ + + String fake = jedis0.hget(room_key, "fake"); + if (StringUtil.isNotEmpty(fake)) { + log.info("create room:" + newRoomId + " session:" + session + " fake:" + fake + " pay:" + pay + + " players:" + jedis0.hget(room_key, "players")); + Redis.use().hset(room_key, "status", 3 + ""); + Redis.use().hincrBy(room_key, "cache_ver", 1); + Redis.use().expire(room_key, 20); + } else { + Redis.use("group1_db11").zadd(grooms_key, pid * 10000 + 1101, room_key); + GroupPublisherService.addRoomEvt(groupId, newRoomId); + } + return room_key; + } finally { + jedis0.close(); + } + + } + + /** + * 检测成员在不在房间里 + * + * @param groupId + * @param session + * @return + */ + public static final boolean checkRoom(int groupId, int uid) { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + String session = AccountCache.genKey(uid); + String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, uid); + if (StringUtil.isNotEmpty(oldRoom)) { + return true; + } + } finally { + jedis0.close(); + } + return false; + } + + public static final boolean checkRoom(String room_key, Jedis jedis0) { + RedisLock lock = new RedisLock(room_key, jedis0); + lock.lock(); + try { + String status = jedis0.hget(room_key, "status"); + if (StringUtil.isEmpty(status) || status.equals("2")) { + return false; + } + return true; + } finally { + lock.unlock(false); + } + } + + public static final boolean checkFakeRoom(String room_key, Jedis jedis0) { + RedisLock lock = new RedisLock(room_key, jedis0); + lock.lock(); + try { + String fake = jedis0.hget(room_key, "fake"); + if (!StringUtil.isEmpty(fake)) { + return true; + } + return false; + } finally { + lock.unlock(false); + } + } + + private static final ITObject publicJoinRoom(int groupId, String session, String room_key, String platform) + throws Exception { + + List x_room_list = Redis.use("group1_db0").hmget(room_key, "fake"); + String fake_json = x_room_list.get(0); + if (fake_json != null) { + log.error("session:" + session + " public join room:" + room_key + " fail, fake != null"); + throw new WebException(ErrorCode.ROOM_CLOSE); + } + + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + + RedisLock lock = null; + try { + String finalRoom = room_key; + + boolean enter_old = false; + int uid = AccountCache.getAccount(session).id; + String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, uid); + if (StringUtil.isNotEmpty(oldRoom)) { + String group = jedis0.hget(oldRoom, "group"); + if (StringUtil.isEmpty(group) || Integer.parseInt(group) != groupId) { + throw new WebException(ErrorCode.GROUP_NOT_CURGROUP_ROOM); + } + enter_old = true; + finalRoom = oldRoom; + } + + lock = new RedisLock(session, jedis0); + lock.lock(); + List room_list = jedis0.hmget(finalRoom, "hpOnOff", "hp_times", "limitInRoom", "status", "open", + "svr", "game", "gpid", "group", "maxPlayers", "AA", "opt", "players"); + String status = room_list.get(3); + if (StringUtil.isEmpty(status)) { + throw new WebException(ErrorCode.GROUP_ROOM_DEL); + } + int _status = Integer.parseInt(status); + + if (_status == 2 || _status == 3) { + Utility.delRoomBySession(jedis0, session, finalRoom); + throw new WebException(ErrorCode.GROUP_ROOM_DEL); + } + + String gm_key = GroupMemberCache.genKey(groupId, uid); + int hp_times = 1; + String group = room_list.get(8); + if (StringUtil.isNotEmpty(group)) { + String hp_times_str = room_list.get(1); + hp_times = Integer.parseInt(group) > 0 ? Integer.parseInt(hp_times_str) : 1; + } + int gameId = Integer.parseInt(room_list.get(6)); + int hpOnOff = Integer.parseInt(room_list.get(0)); + GameBean gb = GameCache.getGame(gameId); + String svr = room_list.get(5); + if (svr == null || !jedis0.exists(svr)) { + svr = _getSvr(jedis0, gb); + } + if (svr == null) { + log.error("publicJoinRoom room_key:" + room_key + " gm_key:" + gm_key + " svr:" + svr); + throw new WebException(ErrorCode.NO_SERVICE); + } + jedis0.hset(finalRoom, "svr", svr); + + int gpid = Integer.parseInt(room_list.get(7)); + GroupBean group_bean = GroupCache.getGroup(groupId); + + if (!enter_old) { + int _maxPlayers = Integer.parseInt(room_list.get(9)); + String _players = room_list.get(12); + if (StringUtil.isNotEmpty(_players)) { + ITArray arr = TArray.newFromJsonData(_players); + if (arr.size() >= _maxPlayers) { + boolean flag = true; + for (int i = 0; i < arr.size(); i++) { + int player_id = arr.getInt(i); + if (player_id == uid) { + flag = false; + } + } + + if (flag) { + log.info("publicJoinRoom enter group fail, room full:" + gm_key + " room_key:" + room_key); + throw new WebException(ErrorCode.ROOM_CLOSE); + } + } + } + + String open = room_list.get(4); + if ((StringUtil.isEmpty(open) || open.equals("0"))) { + log.info("publicJoinRoom enter group fail, room open close:" + gm_key + " room_key:" + room_key); + throw new WebException(ErrorCode.ROOM_CLOSE); + } + + int AA = Integer.parseInt(room_list.get(10)); + if (AA == 1) { + int maxPlayers = Integer.parseInt(room_list.get(9)); + int opt = Integer.parseInt(room_list.get(11)); + + Integer pay = gb.pay.get("pay" + opt + "_" + maxPlayers); + if (pay == null) { + log.warn("pay no set!"); + throw new WebException(ErrorCode._FAILED); + } + pay = (int) Math.ceil((double) pay / maxPlayers); + int result = Utility.checkRoomDiamo(jedis0, session, pay); + if (result != 0) { + log.error("publicJoinRoom groupId:" + groupId + " no diamo"); + throw new WebException(result); + } + } + + if (group_bean.ban == 1) { + throw new WebException(ErrorCode.GROUP_BAN); + } + + GroupPlayBean gpb = GroupCache.getPlay(groupId, gpid); + if (gpb == null || gpb.ban == 1) { + throw new WebException(ErrorCode.GROUP_BAN_PLAY); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + + RedisLock lock2 = new RedisLock(gm_key, jedis10); + try { + lock2.lock(); + List list = jedis10.hmget(gm_key, "ban", "hp"); + String ban = list.get(0); + if (StringUtil.isNotEmpty(ban) && ban.equals("1")) { + throw new WebException(ErrorCode.GROUP_MEMBER_BAN); + } + + String ban_key = "ban{" + groupId + "}:" + uid; + Set ban_set = Redis.use("group1_db11").smembers(ban_key); + if (ban_set.size() > 0) { + String players = room_list.get(12); + if (StringUtil.isNotEmpty(players)) { + ITArray arr = TArray.newFromJsonData(players); + for (int i = 0; i < arr.size(); ++i) { + String tem = arr.getInt(i) + ""; + if (ban_set.contains(tem)) { + throw new WebException(ErrorCode.GROUP_BAN_DESK); + } + } + } + } + + long uid_hp = Long.parseLong(jedis10.hget(gm_key, "hp")); + /*if (uid_hp > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); + }*/ + if (uid_hp <= 0) { + throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP); + } + + if (hpOnOff == 1) { + String hp = list.get(1); + String limitInRoom = room_list.get(2); + /*if (Long.parseLong(hp) > Integer.MAX_VALUE) { + throw new WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); + }*/ + + boolean pass = Redis.use("group1_db1").sismember("pass_games", gameId + ""); + if (!pass && StringUtil.isNotEmpty(limitInRoom)) { + if (Integer.parseInt(hp) < Integer.parseInt(limitInRoom)) { + throw new WebException(ErrorCode.GROUP_LIMIT_NO_HP); + } + } + } + jedis0.hset(session, "room", finalRoom); + + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + + List t_list = Utility.getMemberParents(jedis10, groupId, uid, true); + if (t_list != null) { + // 奖励还是佣金? + ITArray list1 = TArray.newInstance(); + String p_reward_key = GroupCache.genRewardKey(groupId, gpid); + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, gpid); + for (Integer par : t_list) { + Double val = jedis10.zscore(p_reward_key, par.toString()); + int r = 0; + if (val != null) { + r = val.intValue(); + } + int x = 0; + Double xipai_val = jedis10.zscore(p_xipai_reward_key, par.toString()); + + if (xipai_val != null) { + x = xipai_val.intValue(); + } + if (r > 0 || x > 0) { + ITObject obj = TObject.newInstance(); + obj.putInt("p", par); + if (r > 0) { + obj.putInt("r", r); + } + if (x > 0) { + obj.putInt("x", x); + } + list1.addTObject(obj); + } + } + + jedis0.hset(finalRoom, "prs_" + uid, list1.toJson()); + } + } finally { + //jedis10.close(); + lock2.unlock(); + } + } + + ITObject resData = TObject.newInstance(); + resData.putString("room_id", finalRoom.replace("room:", "")); + resData.putInt("hp_times", hp_times); + ITObject gameObj = gb.getTObject(); + resData.putTObject("game_info", gameObj); + resData.putInt("status", _status); + List server_ip = jedis0.hmget(svr, "ip", "port", "intranet"); + // resData.putString("server_ip", server_ip.get(0)); + resData.putString("server_ip", server_ip.get(2)); + resData.putString("server_port", server_ip.get(1)); + resData.putInt("groupId", groupId); + resData.putInt("pid", gpid); + resData.putInt("hpOnOff", hpOnOff); + resData.putBoolean("ban_chat1", group_bean.ban_chat1); + resData.putBoolean("ban_chat2", group_bean.ban_chat2); + String lev_str = Redis.use("group1_db10").hget(gm_key, "lev"); + int lev = 3; + if (StringUtil.isNotEmpty(lev_str)) { + lev = Integer.parseInt(lev_str); + } + resData.putInt("lev", lev); + return resData; + } finally { + if (lock != null) + lock.unlock(false); + jedis0.close(); + } + } + + /** + * 加入房间 + * + * @param groupId + * @param roomid + * @param session + * @param platform + * @return + * @throws Exception + */ + public static ITObject joinRoom(int groupId, String roomid, String session, String platform) throws Exception { + String grooms_key = GroupCache.genRoomsKey(groupId); + String room_key = "room:" + roomid; + Long tem = Redis.use("group1_db11").zrank(grooms_key, room_key); + if (tem == null) { + throw new WebException(ErrorCode.NO_ROOM_NUM); + } + + List room_list = Redis.use("group1_db0").hmget(room_key, "fake"); + String fake_json = room_list.get(0); + if (fake_json != null) { + throw new WebException(ErrorCode.ROOM_CLOSE); + } + AccountBean acc = AccountCache.getAccount(session); + List s_list = Redis.use("group1_db0").hmget(session, "regTime"); + String robotInfo = s_list.get(0); + if (StringUtil.isNotEmpty(robotInfo) && robotInfo.equals("9999")) { + log.error("robot:" + acc.id + " match room error"); + throw new WebException(ErrorCode.ROOM_CLOSE); + } + int uid = AccountCache.getAccount(session).id; + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + List t_list = Utility.getMemberParents(jedis10, groupId, uid, true); + + jedis10.close(); + + if (t_list != null) { + // 判断阀值 + for (Integer par : t_list) { + //以前的 + String gm_par_key = GroupMemberCache.genKey(groupId, par); + // log.error("par:" + par); + String autoscore1 = Redis.use("group1_db10").hget(gm_par_key, "group_black_max_value"); + //log.error("autoscore1:" + autoscore1); + Integer autoscore = 0; + if (!StringUtil.isEmpty(autoscore1)) { + autoscore = Integer.parseInt(autoscore1); + } + + if (autoscore > 0) { + ITObject totalHp = GroupService.getHpTotal(groupId, par, 30); + Long hp = totalHp.getLong("hp"); + log.error("autoscore:" + autoscore); + log.error("hp:" + hp); + + if (hp/100 < autoscore) { + throw new WebException(ErrorCode.GROUP_MEMBER_BAN); + } + } + } + } + /* + boolean xingyuhao = false; + if (Redis.use("group1_db1").sismember("gods", Integer.toString(uid))) { + xingyuhao = true; + } + + if (xingyuhao) { + boolean isSpecialGods = false; + + boolean superflag = false; + + { + String specail = Redis.use("group1_db1").hget("gods_special", Integer.toString(uid)); + if (StringUtil.isNotEmpty(specail)) { + isSpecialGods = true; + } + } + + String superid = Redis.use("group1_db1").hget("gods_super", Integer.toString(uid)); + if (StringUtil.isNotEmpty(superid)) { + superflag = true; + } + + { + List player_list = Redis.use("group1_db0").hmget(room_key, "players"); + + String players_json = player_list.get(0); + if (StringUtil.isNotEmpty(players_json)) { + ITArray players = TArray.newFromJsonData(players_json); + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + if (player_id == uid) + continue; + + String supersid = Redis.use("group1_db1").hget("gods_super", Integer.toString(player_id)); + if (StringUtil.isNotEmpty(supersid)) { + superflag = true; + } + + if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) { + boolean isPlayerSpecialGods = false; + String specail = Redis.use("group1_db1").hget("gods_special", Integer.toString(player_id)); + if (StringUtil.isNotEmpty(specail)) { + isPlayerSpecialGods = true; + } + + if (!isSpecialGods && isPlayerSpecialGods) { + + } else { + if (isSpecialGods && isPlayerSpecialGods) { + + } else { + if (superflag) { + + } else { + log.error("xingyun:" + acc.id + " can't join rooms:" + room_key + + " xingyun playerId:" + player_id); + throw new WebException(ErrorCode.GROUP_BAN_DESK); + } + + } + } + } + } + } + } + } + */ + try { + ITObject resData = publicJoinRoom(groupId, session, room_key, platform); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + jedis11.zremrangeByScore(grooms_key, 0, 0); + jedis11.close(); + return resData; + } catch (WebException e) { + if (e.getCode() == ErrorCode.GROUP_ROOM_DEL || e.getCode() == ErrorCode.NO_ROOM_NUM) { + Redis.use("group1_db11").zrem(grooms_key, room_key); + } + throw e; + } finally { + + } + } + + /** + * 匹配房间 + * + * @param groupId + * @param pid + * @param session + * @param platform + * @return + * @throws Exception + */ + public static ITObject matchRoom(int groupId, int pid, String session, String platform, boolean is_null) + throws Exception { + + int min_value = pid * 10000 + 1101; + int max_value = pid * 10000 + (is_null ? 1101 : 9999); + String grooms_key = GroupCache.genRoomsKey(groupId); + ITObject resData = null; + Set rooms = null; + Jedis jedis = Redis.use("group1_db11").getJedis(); + try { + + rooms = jedis.zrevrangeByScore(grooms_key, max_value, min_value); + + + Set delRooms = new HashSet(); + for (String room : rooms) { + List room_list = Redis.use("group1_db0").hmget(room, "fake"); + + String fake_json = room_list.get(0); + if (fake_json == null) { + continue; + } + + delRooms.add(room); + } + rooms.removeAll(delRooms); + }finally { + jedis.close(); + } + + boolean isWhite = false; + boolean isBlack = false; + boolean xingyuhao = false; + AccountBean acc = AccountCache.getAccount(session); + List s_list = Redis.use("group1_db0").hmget(session, "regTime"); + String robotInfo = s_list.get(0); + if (StringUtil.isNotEmpty(robotInfo) && robotInfo.equals("9999")) { + log.error("robot:" + acc.id + " match room error"); + throw new WebException(ErrorCode.ROOM_CLOSE); + } + int uid = acc.id; + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + List t_list = Utility.getMemberParents(jedis10, groupId, uid, true); + String gm_keyx = GroupMemberCache.genKey(groupId, uid); + String blackx = jedis10.hget(gm_keyx, "black"); + if (StringUtil.isNotEmpty(blackx) && blackx.equals("2")) { + isWhite = true; + } + if (StringUtil.isNotEmpty(blackx) && blackx.equals("1")) { + isBlack = true; + } + jedis10.close(); + + if (t_list != null) { + // 判断阀值 + for (Integer par : t_list) { + // get aoto_score + String gm_par_key = GroupMemberCache.genKey(groupId, par); + String autoscore1 = Redis.use("group1_db10").hget(gm_par_key, "group_black_max_value"); + Integer autoscore = 0; + if (!StringUtil.isEmpty(autoscore1)) { + autoscore = Integer.parseInt(autoscore1); + } + + if (autoscore > 0) { + ITObject totalHp = GroupService.getHpTotal(groupId, par, 30); + Long hp = totalHp.getLong("hp"); + if (hp/100 < autoscore) { + throw new WebException(ErrorCode.GROUP_MEMBER_BAN); + } + } + } + } + + +// if (Redis.use("group1_db1").sismember("gods", Integer.toString(uid))) { +// xingyuhao = true; +// } +// +// if (xingyuhao) { +// +// List blackRooms = new ArrayList<>(); +// List whiteRooms = new ArrayList<>(); +// List genralRooms = new ArrayList<>(); +// for (String room : rooms) { +// List room_list = Redis.use("group1_db0").hmget(room, "players"); +// +// String players_json = room_list.get(0); +// if (players_json == null) { +// continue; +// } +// +// ITArray players = TArray.newFromJsonData(players_json); +// +// boolean hasblack = false; +// boolean haswhite = false; +// for (int i = 0; i < players.size(); i++) { +// int player_id = players.getInt(i); +// if (player_id == uid) +// continue; +// if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) { +// haswhite = true; +// } +// String gm_key = GroupMemberCache.genKey(groupId, player_id); +// String black = Redis.use("group1_db10").hget(gm_key, "black"); +// if (StringUtil.isNotEmpty(black) && black.equals("2")) { +// haswhite = true; +// } +// if (StringUtil.isNotEmpty(black) && black.equals("1")) { +// hasblack = true; +// } +// } +// +// if (haswhite) { +// whiteRooms.add(room); +// } +// if (hasblack) { +// blackRooms.add(room); +// } +// if (haswhite == false && hasblack == false) { +// genralRooms.add(room); +// } +// } +// +// if (blackRooms.size() == 0) { +// blackRooms.addAll(genralRooms); +// // if (blackRooms.size() == 0) +// // { +// // blackRooms.addAll(whiteRooms); +// // } +// } +// +// if (blackRooms.size() > 0) { +// Collections.shuffle(blackRooms); +// +// for (String room : blackRooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } +// } else if (isWhite) { +// +// +// +// +// List blackRooms = new ArrayList<>(); +// List whiteRooms = new ArrayList<>(); +// List genralRooms = new ArrayList<>(); +// for (String room : rooms) { +// List room_list = Redis.use("group1_db0").hmget(room, "players"); +// +// String players_json = room_list.get(0); +// if (players_json == null) { +// continue; +// } +// +// ITArray players = TArray.newFromJsonData(players_json); +// +// boolean hasblack = false; +// boolean haswhite = false; +// for (int i = 0; i < players.size(); i++) { +// int player_id = players.getInt(i); +// if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) { +// haswhite = true; +// } +// String gm_key = GroupMemberCache.genKey(groupId, player_id); +// String black = Redis.use("group1_db10").hget(gm_key, "black"); +// if (StringUtil.isNotEmpty(black) && black.equals("2")) { +// haswhite = true; +// } +// if (StringUtil.isNotEmpty(black) && black.equals("1")) { +// hasblack = true; +// } +// } +// +// if (haswhite) { +// whiteRooms.add(room); +// } +// if (hasblack) { +// blackRooms.add(room); +// } +// if (hasblack == false && haswhite == false) { +// genralRooms.add(room); +// } +// } +// +// if (blackRooms.size() == 0) { +// blackRooms.addAll(genralRooms); +// if (blackRooms.size() == 0) { +// blackRooms.addAll(whiteRooms); +// } +// } +// +// if (blackRooms.size() > 0) { +// Collections.shuffle(blackRooms); +// +// for (String room : blackRooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } else { +// for (String room : rooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } +// } else if (isBlack) { +// +// List blackRooms = new ArrayList<>(); +// List whiteRooms = new ArrayList<>(); +// List genralRooms = new ArrayList<>(); +// for (String room : rooms) { +// +// List room_list = Redis.use("group1_db0").hmget(room, "players"); +// +// String players_json = room_list.get(0); +// if (players_json == null) { +// continue; +// } +// +// ITArray players = TArray.newFromJsonData(players_json); +// +// +// boolean hasblack = false; +// boolean haswhite = false; +// for (int i = 0; i < players.size(); i++) { +// int player_id = players.getInt(i); +// if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) { +// haswhite = true; +// } +// String gm_key = GroupMemberCache.genKey(groupId, player_id); +// String black = Redis.use("group1_db10").hget(gm_key, "black"); +// if (StringUtil.isNotEmpty(black) && black.equals("1")) { +// hasblack = true; +// } +// if (StringUtil.isNotEmpty(black) && black.equals("2")) { +// haswhite = true; +// } +// } +// +// if (haswhite) { +// whiteRooms.add(room); +// } +// if (hasblack) { +// blackRooms.add(room); +// } +// if (haswhite == false && hasblack == false) { +// genralRooms.add(room); +// } +// } +// +// if (whiteRooms.size() == 0) { +// whiteRooms.addAll(genralRooms); +// if (whiteRooms.size() == 0) { +// whiteRooms.addAll(blackRooms); +// } +// } +// +// if (whiteRooms.size() > 0) { +// +// Collections.shuffle(whiteRooms); +// +// for (String room : whiteRooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } else { +// +// for (String room : rooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } +// } else { +// +// List blackRooms = new ArrayList<>(); +// List whiteRooms = new ArrayList<>(); +// List genralRooms = new ArrayList<>(); +// for (String room : rooms) { +// List room_list = Redis.use("group1_db0").hmget(room, "players"); +// +// String players_json = room_list.get(0); +// if (players_json == null) { +// continue; +// } +// +// ITArray players = TArray.newFromJsonData(players_json); +// +// boolean hasblack = false; +// boolean haswhite = false; +// for (int i = 0; i < players.size(); i++) { +// int player_id = players.getInt(i); +// if (Redis.use("group1_db1").sismember("gods", Integer.toString(player_id))) { +// haswhite = true; +// } +// String gm_key = GroupMemberCache.genKey(groupId, player_id); +// String black = Redis.use("group1_db10").hget(gm_key, "black"); +// if (StringUtil.isNotEmpty(black) && black.equals("1")) { +// hasblack = true; +// } +// if (StringUtil.isNotEmpty(black) && black.equals("2")) { +// haswhite = true; +// } +// } +// +// if (haswhite) { +// whiteRooms.add(room); +// } +// if (hasblack) { +// blackRooms.add(room); +// } +// if (hasblack == false && haswhite == false) { +// genralRooms.add(room); +// } +// } +// +// if (genralRooms.size() == 0) { +// genralRooms.addAll(blackRooms); +// if (genralRooms.size() == 0) { +// genralRooms.addAll(whiteRooms); +// } +// } +// +// if (genralRooms.size() > 0) { +// Collections.shuffle(genralRooms); +// +// for (String room : genralRooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } else { +// for (String room : rooms) { +// try { +// resData = publicJoinRoom(groupId, session, room, platform); +// break; +// } catch (WebException e) { +// int code = e.getCode(); +// if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { +// Redis.use("group1_db11").zrem(grooms_key, room); +// } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN +// || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN +// || code == ErrorCode.GROUP_BAN_PLAY) { +// throw e; +// } +// } +// } +// } +// } + + for (String room : rooms) { + try { + resData = publicJoinRoom(groupId, session, room, platform); + log.info(String.format("match_room,room:%s",room)); + break; + } catch (WebException e) { + int code = e.getCode(); + if (code == ErrorCode.GROUP_ROOM_DEL || code == ErrorCode.NO_ROOM_NUM) { + Redis.use("group1_db11").zrem(grooms_key, room); + } else if (code == ErrorCode.NO_SERVICE || code == ErrorCode.GROUP_BAN + || code == ErrorCode.GROUP_LIMIT_NO_HP || code == ErrorCode.GROUP_MEMBER_BAN + || code == ErrorCode.GROUP_BAN_PLAY) { + throw e; + } + } + } + + if (resData == null) { + String key = createGroupRoom(session, groupId, pid); + resData = publicJoinRoom(groupId, session, key, platform); + } + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + try { + jedis11.zremrangeByScore(grooms_key, 0, 0); + } finally { + jedis11.close(); + } + return resData; + } + + /** + * 删除房间 + * + * @param groupId + * @param roomId + * @return + * @throws Exception + */ + public static final ITObject delRoom(int groupId, String roomId) throws Exception { + String tag_key = "room:" + roomId; + Jedis jedis0 = Redis.use("group1_db0").getJedis(); +// String svr = StringUtil.Empty; + + RedisLock lock = new RedisLock(tag_key, jedis0); + try { + lock.lock(); + List list = jedis0.hmget(tag_key, "AA", "payer", "pay", "group", "game", "status", "gpid", "fake", + "players"); + String status = list.get(5); + if (StringUtil.isEmpty(status)) { + throw new WebException(ErrorCode.NO_ROOM_NUM); + } + int _status = Integer.parseInt(status); + if (_status == 2 || _status == 3) { + throw new WebException(ErrorCode.GROUP_ROOM_DEL); + } + String group = list.get(3); + int _gid = 0; + if (StringUtil.isNotEmpty(group)) { + _gid = Integer.parseInt(group); + } + + String strGpid = list.get(6); + int _gpid = 0; + if (StringUtil.isNotEmpty(strGpid)) { + _gpid = Integer.parseInt(strGpid); + } + if (_gid != groupId) { + throw new WebException(ErrorCode.GROUP_NOT_CURGROUP_ROOM); + } + String strFake = list.get(7); + if (_status == 0) { + if (strFake == null) { + int gameId = Integer.parseInt(list.get(4)); + boolean pay_AA = Integer.parseInt(list.get(0)) == 1; + if (!pay_AA) { + int payer = Integer.parseInt(list.get(1)); + int pay = Integer.parseInt(list.get(2)); + Utility.payDiamo(EventType.REDIS_EVENT_BACK_PAY, payer, gameId, pay, groupId, _gpid); + } + } + } + if (strFake != null) { + try { + ITArray players = TArray.newFromJsonData(list.get(8)); + for (int i = 0; i < players.size(); i++) { + int player_id = players.getInt(i); + Redis.use("group1_db1").srem("used_robot", Integer.toString(player_id)); + // Redis.use("group1_db1").sadd("free_robot", Integer.toString(player_id)); + + } + } catch (Exception e) { + + } + } + jedis0.hset(tag_key, "status", "2"); + BaseCache.updateCacheVer(jedis0, tag_key); + GroupPublisherService.delRoomEvt(groupId, roomId); +// svr = jedis0.hget(tag_key, "svr"); +// +// List server_ip = Redis.use("group1_db0").hmget(svr, "ip", "port"); +// String ip = server_ip.get(0); +// if(StringUtil.isEmpty(ip)) { +// throw new WebException(ErrorCode.NO_SERVICE); +// } +// String port =server_ip.get(1); + ITObject obj = TObject.newInstance(); +// obj.putString("ip", ip); +// obj.putInt("port", Integer.parseInt(port)); + return obj; + } finally { + lock.unlock(); + } + + } +} diff --git a/web_group/src/main/java/com/group/service/GroupService.java b/web_group/src/main/java/com/group/service/GroupService.java new file mode 100644 index 0000000..f35e293 --- /dev/null +++ b/web_group/src/main/java/com/group/service/GroupService.java @@ -0,0 +1,5555 @@ +package com.group.service; + +import java.util.*; + +import javax.xml.bind.annotation.XmlElementDecl.GLOBAL; + +import com.data.bean.AccountBean; +import com.data.bean.GameBean; +import com.data.bean.GroupBean; +import com.data.bean.GroupMemberBean; +import com.data.bean.GroupPlayBean; +import com.data.cache.AccountCache; +import com.data.cache.BaseCache; +import com.data.cache.GameCache; +import com.data.cache.GroupCache; +import com.data.cache.GroupMemberCache; +import com.data.util.ConsumeCode; +import com.data.util.CountUtil; +import com.data.util.ErrorCode; +import com.data.util.Utility; +import com.group.MainServer; +import com.taurus.core.entity.*; +import com.taurus.core.plugin.database.DataBase; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.plugin.redis.RedisLock; +import com.taurus.core.util.DateUtils; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.web.WebException; + +import jdk.nashorn.internal.objects.Global; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.Pipeline; + +public class GroupService { + private final static Logger log; + + static { + log = Logger.getLogger(GroupService.class); + } + /** 普通圈子3000 */ + public static final int TYPE_1_NUM = 3000000; + /** 大联盟20000 */ + public static final int TYPE_2_NUM = 3000000; + + /** 删除玩家 */ + public static final int PERMISSION_DEL_MEMBER = 1; + /** 添加玩家 */ + public static final int PERMISSION_ADD_MEMBER = 2; + /** 增减体力值 */ + public static final int PERMISSION_HP_OPT = 4; + /** 禁止娱乐 */ + public static final int PERMISSION_BAN = 8; + /** 禁止同桌 */ + public static final int PERMISSION_BAN_DESKMATE = 16; + + private static ITObject getGroupData(int uid, int groupId, Jedis jedis11, Jedis jedis10) { + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) + return null; + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + if (gmb == null) { + return null; + } + if (uid == gb.owner) { + Redis.use("group1_db1").sadd("robot_group", Integer.toString(groupId)); + } + ITObject obj = TObject.newInstance(); + obj.putInt("id", groupId); + obj.putString("name", gb.name); + int owner = gb.owner; + if (gmb.lev == 1) { + obj.putInt("owner", owner); + } else { + obj.putInt("owner", 0); + } + + obj.putInt("type", gb.type); + obj.putInt("parentId", gmb.parentId); + obj.putInt("pay_type", gb.pay_type); + obj.putInt("member_num", gb.gms); + obj.putInt("option", gb.option); + obj.putInt("show_num", gb.show_num); + String grooms_key = GroupCache.genRoomsKey(groupId); + Set rooms = jedis11.zrangeByScore(grooms_key, 100000, 2000000); + obj.putInt("room_num", rooms.size()); + obj.putInt("top_time", gmb.top_time); + AccountBean acc = AccountCache.getAccount(owner); + if (acc != null) { + obj.putString("o_nick", acc.nick); + obj.putString("o_portrait", acc.portrait); + } else { + obj.putString("o_nick", StringUtil.Empty); + obj.putString("o_portrait", StringUtil.Empty); + } + // Redis.use("group1_db1").hset("alllook",uid+"","1"); + String fp = Redis.use("group1_db1").hget("alllook", uid + ""); + if (fp != null) { + obj.putInt("lev", 1); + } else { + obj.putInt("lev", gmb.lev); + } + + return obj; + } + + /** + * 获取圈子列表 + * + * @param uid + * @return + * @throws Exception + */ + public static final ITArray getGroups(int uid) throws Exception { + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + ITArray list = TArray.newInstance(); + String key = GroupCache.genGroupsKey(uid); + Set groups = jedis11.zrevrange(key, 0, -1); + for (String tem : groups) { + ITObject obj = getGroupData(uid, Integer.parseInt(tem), jedis11, jedis10); + if (obj == null) { + jedis11.zrem(key, tem); + continue; + } + list.addTObject(obj); + } + + return list; + } finally { + jedis11.close(); + jedis10.close(); + } + } + + /** + * 获取圈子预览 + * + * @param uid + * @return + * @throws Exception + */ + public static final ITObject getPreview(int uid) throws Exception { + String key = GroupCache.genGroupsKey(uid); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + try { + Set groups = jedis11.zrevrange(key, 0, -1); + ITObject obj = TObject.newInstance(); + for (String tem : groups) { + int groupId = Integer.parseInt(tem); + + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) { + continue; + } + obj.putInt("id", gb.id); + obj.putString("name", gb.name); + obj.putInt("type", gb.type); + obj.putInt("member_num", gb.gms); + String grooms_key = GroupCache.genRoomsKey(groupId); + Set rooms = jedis11.zrangeByScore(grooms_key, 100000, 1000000); + obj.putInt("room_num", rooms.size()); + obj.putBoolean("is_group", true); + return obj; + } + obj.putBoolean("is_group", false); + return obj; + } finally { + jedis11.close(); + } + + } + + private static final Map groupToRedis(String groupId, String name, int owner, int type, + int pay_type) { + Map redis_map = new HashMap<>(); + redis_map.put("id", groupId); + redis_map.put("name", name); + redis_map.put("owner", owner + ""); + redis_map.put("type", type + ""); + redis_map.put("pay_type", pay_type + ""); + redis_map.put("opt", "1"); + redis_map.put("ban", "0"); + redis_map.put("dissolve_opt", "1"); + redis_map.put("kick_opt", "1"); + redis_map.put("ban_apply", "0"); + redis_map.put("create_time", System.currentTimeMillis() / 1000 + ""); + redis_map.put("gms", "1"); + redis_map.put("option", "0"); + return redis_map; + } + + private static final Map memberToRedis(String groupId, int uid, int lev, int partnerLev, + int parentId, long time) { + Map redis_map = new HashMap<>(); + redis_map.put("groupId", groupId); + redis_map.put("uid", uid + ""); + redis_map.put("lev", lev + ""); + redis_map.put("opt", "1"); + redis_map.put("hp", "0"); + redis_map.put("ban", "0"); + redis_map.put("join_time", time + ""); + redis_map.put("top_time", "0"); + redis_map.put("partnerLev", partnerLev + ""); + redis_map.put("parentId", parentId + ""); + redis_map.put("hp_opt", "1"); + redis_map.put("permission", "0"); + return redis_map; + } + + private static final Map payToRedis(int groupId, int pid, int gameId, String name, int deskId, + String config, String hpData, int hpOnOff, int hp_times, int reward, int rewardType, int rewardValueType, + int xipai_reward, int xipai_rewardType, int xipai_rewardValueType, int robot_room) { + Map redis_map = new HashMap<>(); + redis_map.put("groupId", groupId + ""); + redis_map.put("id", pid + ""); + redis_map.put("name", name); + redis_map.put("deskId", deskId + ""); + redis_map.put("gameId", gameId + ""); + redis_map.put("config", config); + redis_map.put("hpData", hpData); + redis_map.put("hpOnOff", hpOnOff + ""); + redis_map.put("reward", reward + ""); + redis_map.put("rewardType", rewardType + ""); + redis_map.put("rewardValueType", rewardValueType + ""); + redis_map.put("xipai_reward", xipai_reward + ""); + redis_map.put("xipai_rewardType", xipai_rewardType + ""); + redis_map.put("xipai_rewardValueType", xipai_rewardValueType + ""); + redis_map.put("hp_times", hp_times + ""); + redis_map.put("ban", "0"); + redis_map.put("robot_room", robot_room + ""); + return redis_map; + } + +// private static final String DEF_PROMOTION_DATA = "[{\"num\":0,\"val\":0}]"; + + /** + * 创建圈子 + * + * @param name + * @param owner + * @param type 1普通圈子 2大联盟 + * @param pay_type 1 房主支付 2AA支付 + * @return + * @throws Exception + */ + public static final ITObject createGroup(String name, int owner, int type, int pay_type, int num) throws Exception { + log.info("createGroup name:" + name + " owner:" + owner + " type:" + type + " pay_type:" + pay_type + " num:" + + num); + + String groupId = null; + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + try { + if (num > 0) { + groupId = num + ""; + if (!jedis1.sismember("lh_ids", groupId)) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + } else { + groupId = jedis1.rpop("free_group"); + if (jedis1.sismember("lh_ids", groupId)) { + throw new WebException(ErrorCode._FAILED); + } + } + + String sql = String.format("SELECT id FROM groups WHERE owner=%s", owner); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (arr.size() > 0) { + if (num <= 0) { + jedis1.lpush("free_group", groupId); + } + throw new WebException(ErrorCode.GROUP_TYPE2_ONLY_1); + } + + } finally { + jedis1.close(); + } + + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + int gid = Integer.parseInt(groupId); + String key = GroupCache.genKey(Integer.parseInt(groupId)); + RedisLock lock = null; + try { + lock = new RedisLock(key, jedis11); + lock.lock(); + + String sql = String.format("{call sp_create_group(%s,'%s',%s,%s,%s)}", groupId, name, owner, type, + pay_type); + Utility.evtdb(gid, 2, sql); + + Map redis_map = groupToRedis(groupId, name, owner, type, pay_type); + jedis11.hmset(key, redis_map); + BaseCache.updateCacheVer(jedis11, key); + long time = System.currentTimeMillis() / 1000; + redis_map = memberToRedis(groupId, owner, 1, 0, 0, time); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + String gm_key = GroupMemberCache.genKey(Integer.parseInt(groupId), owner); + jedis10.hmset(gm_key, redis_map); + BaseCache.updateCacheVer(jedis10, gm_key); + } finally { + jedis10.close(); + } + + ITObject info = TObject.newInstance(); + info.putInt("id", gid); + info.putString("name", name); + String gpids_key = GroupCache.genPidsKey(gid); + Pipeline pipeline = jedis11.pipelined(); + pipeline.del(gpids_key); + for (int i = 10; i < 210; ++i) { + pipeline.zadd(gpids_key, time, i + ""); + time++; + } + pipeline.sync(); + + String gs_key = GroupCache.genGroupsKey(owner); + jedis11.zadd(gs_key, 0, groupId); + return info; + + } catch (Exception ex) { + Redis.use("group1_db1").lpush("free_group", groupId); + if (ex instanceof WebException) { + throw ex; + } else { + log.error(ex); + } + + } finally { + if (lock != null) { + lock.unlock(); + } + } + return null; + } + + /** + * 删除圈子 + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final void delGroup(int groupId, int uid) throws Exception { + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String key = GroupCache.genKey(groupId); + + RedisLock lock = new RedisLock(key, jedis11); + try { + lock.lock(); + String opt = jedis11.hget(key, "opt"); + if (StringUtil.isEmpty(opt) || Integer.parseInt(opt) != 1) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + String grooms_key = GroupCache.genRoomsKey(groupId); + jedis11.zremrangeByScore(grooms_key, 0, 0); + Set rooms = jedis11.zrangeByScore(grooms_key, 100000, 1000000); + if (rooms.size() > 0) { + throw new WebException(ErrorCode.GROUP_EXIST_ROOMS); + } + + jedis11.hset(key, "opt", "2"); + GroupPublisherService.delGroupEvt(groupId); + jedis11.expire(key, 30); + String gpids_key = GroupCache.genPidsKey(groupId); + String gs_key = GroupCache.genGroupsKey(uid); + jedis11.del(gpids_key); + jedis11.zrem(gs_key, groupId + ""); + Set play_list = jedis11.keys("g{" + groupId + "}:*"); + Pipeline pipeline = jedis11.pipelined(); + for (String p_key : play_list) { + pipeline.expire(p_key, 30); + } + pipeline.sync(); + Set members = jedis10.keys("g{" + groupId + "}:*"); + pipeline = jedis10.pipelined(); + for (String m_key : members) { + pipeline.expire(m_key, 30); + } + pipeline.sync(); + + String sql = String.format("{call sp_del_group(%s)}", groupId); + Utility.evtdb(groupId, 2, sql); + } finally { + lock.unlock(); + jedis10.close(); + } + } + + /** + * 退出圈子 + * + * @param groupId + * @param uid + * @throws Exception + */ + public static final void exitGroup(int groupId, int uid) throws Exception { + GroupBean gb = GroupCache.getGroup(groupId); + if (gb.exit_opt == 1) { + throw new WebException(ErrorCode.GROUP_TYPE2_NOT_EXIT); + } + + if ((gb.option & 2) == 0) { + throw new WebException(ErrorCode.GROUP_TYPE2_NOT_EXIT); + } + + delMember(groupId, gb.owner, uid); + } + + /** + * 申请加入牌友圈 + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final int applyGroup(int groupId, int uid) throws Exception { + String joins_key = GroupCache.genJoinsKey(groupId); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + RedisLock lock = new RedisLock(joins_key, jedis11); + try { + lock.lock(); + GroupBean gb = GroupCache.getGroup(groupId); + if (gb == null) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + if (gb.ban_apply == 2) { + return ErrorCode.GROUP_BAN_APPLY; + } + int type = gb.type; + int gms = gb.gms; + if (type == 1 && gms >= TYPE_1_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + if (type == 2 && gms >= TYPE_2_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + String tag_key = GroupMemberCache.genKey(groupId, uid); + String member_opt = Redis.use("group1_db10").hget(tag_key, "opt"); + if (StringUtil.isNotEmpty(member_opt) && member_opt.equals("1")) { + return ErrorCode.GROUP_MEMBER_EXIST; + } + if (jedis11.sismember(joins_key, uid + "")) { + return ErrorCode.GROUP_JOIN_EXIST; + } + jedis11.sadd(joins_key, uid + ""); + int joins = jedis11.scard(joins_key).intValue(); + GroupPublisherService.updateJoinsEvt(groupId, joins); + } finally { + lock.unlock(); + } + return 0; + } + + /** + * 验证加入牌友圈 + * + * @param groupId + * @param uid + * @param tagId + * @param allow + * @return + * @throws Exception + */ + public static final int verifyJoinGroup(int groupId, int uid, int tagId, boolean allow) throws Exception { + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String member_key = GroupMemberCache.genKey(groupId, tagId); + RedisLock lock1 = new RedisLock(member_key, jedis10); + String joins_key = GroupCache.genJoinsKey(groupId); + RedisLock lock = new RedisLock(joins_key, jedis11); + try { + lock.lock(); + lock1.lock(); + long len = jedis11.srem(joins_key, tagId + ""); + String member_opt = jedis10.hget(member_key, "opt"); + if (StringUtil.isNotEmpty(member_opt) && member_opt.equals("1")) { + return ErrorCode.GROUP_MEMBER_EXIST; + } + String g_key = GroupCache.genKey(groupId); + List list = jedis11.hmget(g_key, "type", "gms"); + int type = Integer.parseInt(list.get(0)); + int gms = Integer.parseInt(list.get(1)); + if (type == 1 && gms >= TYPE_1_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + if (type == 2 && gms >= TYPE_2_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + if (len > 0 && allow) { + long time = System.currentTimeMillis() / 1000; + String sql = String.format( + "INSERT INTO group_member(uid,groupId,join_time,parentId) VALUES(%s,%s,%s,%s)", tagId, groupId, + time, 0); + Utility.evtdb(groupId, 1, sql); + Map redis_map = memberToRedis(groupId + "", tagId, 3, 0, 0, time); + jedis10.hmset(member_key, redis_map); + BaseCache.updateCacheVer(jedis10, member_key); + jedis11.hincrBy(g_key, "gms", 1); + BaseCache.updateCacheVer(jedis11, g_key); + String key = GroupCache.genGroupsKey(tagId); + jedis11.zadd(key, 0, groupId + ""); + } + int joins = jedis11.scard(joins_key).intValue(); + GroupPublisherService.updateJoinsEvt(groupId, joins); + return 0; + } finally { + lock.unlock(); + lock1.unlock(); + } + } + + private static String getSvr(Jedis jedis11) { + Set svr_list = jedis11.zrange("mgr_group", 0, -1); + if (svr_list.size() > 0) { + for (String str : svr_list) { + if (jedis11.exists(str)) { + return str; + } + } + } + return null; + } + + /** + * 进入圈子 + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final ITObject enterGroup(int groupId, int uid) throws Exception { + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + + try { + String svr = getSvr(jedis11); + if (StringUtil.isEmpty(svr)) { + log.error("enterGroup fail groupId:" + groupId + " svr:" + svr + " uid:" + uid); + throw new WebException(ErrorCode.NO_SERVICE); + } + String group_key = GroupCache.genKey(groupId); + + String host = jedis11.hget(svr, "host"); + ITObject data = TObject.newInstance(); + data.putString("host", host); + String notice = Redis.use("group1_db11").hget(group_key, "notice"); + data.putString("notice", StringUtil.isEmpty(notice) ? StringUtil.Empty : notice); + String hide_action = Redis.use("group1_db11").hget(group_key, "hide_action"); + data.putInt("hide_action", StringUtil.isEmpty(hide_action) ? 0 : Integer.parseInt(hide_action)); +// // 同步redis跟mysql的hp +// String sql = String.format("select hp from group_member where groupId = %s and uid=%s", groupId, uid); +// ITArray tmplist = DataBase.use().executeQueryByTArray(sql); +// if (tmplist.size() > 0) { +// int hp = tmplist.getTObject(0).getInt("hp"); +// jedis10.hset("g{" + groupId + "}:m" + uid, "hp", hp + ""); +// } + return data; + } finally { + jedis11.close(); + jedis10.close(); + } + } + + /** + * 获得玩家信息 + * + * @param uid + * @return + * @throws Exception + */ + public static final ITObject getPlayerInfo(int uid) throws Exception { + AccountBean acc = AccountCache.getAccount(uid); + if (acc == null) { + return null; + } + + ITObject obj = TObject.newInstance(); + obj.putInt("uid", uid); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + return obj; + } + + /** + * 添加成员 + * + * @param groupId + * @param uid + * @param tagId + * @return + * @throws Exception + */ + public static final int addMember(int groupId, int uid, int tagId) throws Exception { + log.info("addMember uid:" + uid + " tagId:" + tagId); + GroupBean gb = GroupCache.getGroup(groupId); + String g_key = gb.redis_key; + int type = gb.type; + int gms = gb.gms; + if (type == 1 && gms >= TYPE_1_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + if (type == 2 && gms >= TYPE_2_NUM) { + return ErrorCode.GROUP_MEMBER_IS_FULL; + } + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(tag_key, jedis10); + RedisLock lock1 = null; + try { + lock.lock(); + String session_key = AccountCache.genKey(tagId); + List s_list = Redis.use("group1_db0").hmget(session_key, "id", "invitation"); + if (StringUtil.isEmpty(s_list.get(0))) { + return ErrorCode._FAILED; + } + int invitation = 0; + if (StringUtil.isNotEmpty(s_list.get(1))) { + invitation = Integer.parseInt(s_list.get(1)); + } + if (invitation == 0) { + return ErrorCode.GROUP_CLOSE_INVITATION; + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + lock1 = new RedisLock(mng_key, jedis10); + lock1.lock(); + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + + if (mng_bean == null) { + return ErrorCode.GROUP_NOT_MEMBER; + } + + int mgn_lev = mng_bean.lev; + int mgn_partnerLev = mng_bean.partnerLev; + if (mgn_lev == 3 && mgn_partnerLev == 0) { + return ErrorCode.GROUP_NOT_PARTNER; + } + if (mgn_lev == 2) { + if ((mng_bean.permission & PERMISSION_ADD_MEMBER) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + String member_opt = jedis10.hget(tag_key, "opt"); + boolean exits = StringUtil.isNotEmpty(member_opt) && member_opt.equals("1"); + if (exits) { + return ErrorCode.GROUP_MEMBER_EXIST; + } + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + if (!exits) { + String joins_key = GroupCache.genJoinsKey(groupId); + log.info("addMember joins_key:" + joins_key); + if (jedis11.sismember(joins_key, tagId + "")) { + jedis11.srem(joins_key, tagId + ""); + int joins = jedis11.scard(joins_key).intValue(); + log.info("addMember joins:" + joins); + GroupPublisherService.updateJoinsEvt(groupId, joins); + } + } + + try { + int mgn_uid = mgn_lev == 3 ? uid : 0; + String sql = String.format("{call sp_add_member(%s,%s,%s)}", groupId, mgn_uid, tagId); + log.info("addMember addsql:" + sql); + Utility.evtdb(groupId, 2, sql); + + long time = System.currentTimeMillis() / 1000; + log.info("addMember time:" + time); + Map redis_map = memberToRedis(groupId + "", tagId, 3, 0, mgn_uid, time); + + redis_map.put("queueid", mng_bean.queueid + ""); + // redis_map.put("seeid",mng_bean.seeid+""); + + jedis10.hmset(tag_key, redis_map); + BaseCache.updateCacheVer(jedis10, tag_key); + jedis11.hincrBy(g_key, "gms", 1); + BaseCache.updateCacheVer(jedis11, g_key); + String key = GroupCache.genGroupsKey(tagId); + jedis11.zadd(key, 0, groupId + ""); + + String group_ban = jedis10.hget(mng_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + sql = String.format("update group_member set ban = %s where uid = %s AND groupId = %s", group_ban, + tagId, groupId); + Utility.evtdb(groupId, 1, sql); + + jedis10.hset(tag_key, "ban", group_ban); + jedis10.hset(tag_key, "group_ban", group_ban); + BaseCache.updateCacheVer(jedis10, tag_key); + } + + String sql2 = String.format("update account set is_bangding =1 where id = %s", tagId); + Utility.evtdb(groupId, 1, sql2); + + } finally { + jedis11.close(); + } + return 0; + } finally { + log.info("lock1 time:" + lock1); + if (lock1 != null) { + lock1.unlock(false); + } + log.info("lock time:" + lock); + lock.unlock(); + } + } + + public static final ITObject cancelParent(int groupId, int uid, int tagId) throws Exception { + log.info("setParent uid:" + uid + " tagId:" + tagId); + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(tag_key, jedis10); + RedisLock lock1 = null; + try { + lock.lock(); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + lock1 = new RedisLock(mng_key, jedis10); + lock1.lock(); + GroupMemberBean mng = GroupCache.getMember(groupId, uid); + if (mng == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int mgn_lev = mng.lev; + int mgn_partner = mng.partnerLev; + + int member_lev = tag_bean.lev; + if (member_lev < 3) { + throw new WebException(ErrorCode.GROUP_TAG_ISMGR); + } + + int member_parentId = tag_bean.parentId; + if (member_parentId > 0 && uid != member_parentId) { + throw new WebException(ErrorCode.GROUP_MEMBER_EXIST_PARTENER); + } + GroupBean gb = GroupCache.getGroup(groupId); + int tag_partner_lev = 0; + int parent = uid; + + String sql = String.format( + "update group_member set parentId = %s,partnerLev=%s " + "WHERE uid = %s and groupId = %s", parent, + tag_partner_lev, tagId, groupId); + Utility.evtdb(groupId, 1, sql); + GroupPublisherService.updateMemberEvt(groupId, tagId, 3, tag_partner_lev); + jedis10.hset(tag_key, "parentId", parent + ""); + jedis10.hset(tag_key, "partnerLev", tag_partner_lev + ""); + BaseCache.updateCacheVer(jedis10, tag_key); + if (mgn_lev == 3) { + List list = Utility.getMemberParents(jedis10, groupId, uid, true); + for (Integer par : list) { + String pl_key = GroupCache.genParListKey(groupId, par); + jedis10.del(pl_key); + } + } + + ITObject resData = TObject.newInstance(); + resData.putInt("parentId", parent); + resData.putInt("partnerLev", tag_partner_lev); + + return resData; + } finally { + + } + } + + /** + * 设置合伙人 + * + * @param groupId + * @param uid + * @param tagId + * @return + * @throws Exception + */ + public static final ITObject setParent(int groupId, int uid, int tagId) throws Exception { + log.info("setParent uid:" + uid + " tagId:" + tagId); + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(tag_key, jedis10); + RedisLock lock1 = null; + try { + lock.lock(); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + lock1 = new RedisLock(mng_key, jedis10); + lock1.lock(); + GroupMemberBean mng = GroupCache.getMember(groupId, uid); + if (mng == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int mgn_lev = mng.lev; + int mgn_partner = mng.partnerLev; + if (mgn_lev == 3 && mgn_partner == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + + int member_lev = tag_bean.lev; + if (member_lev < 3) { + throw new WebException(ErrorCode.GROUP_TAG_ISMGR); + } + int member_partner = tag_bean.partnerLev; + if (member_partner > 0) { + throw new WebException(ErrorCode.GROUP_ALREADY_PARTNER); + } + int member_parentId = tag_bean.parentId; + if (member_parentId > 0 && uid != member_parentId) { + throw new WebException(ErrorCode.GROUP_MEMBER_EXIST_PARTENER); + } + GroupBean gb = GroupCache.getGroup(groupId); + int tag_partner_lev = 1; + int parent = uid; + if (mgn_lev < 3) { + parent = gb.owner; + } else { + tag_partner_lev = (mgn_partner + 1); + } + + String sql = String.format( + "update group_member set parentId = %s,partnerLev=%s " + "WHERE uid = %s and groupId = %s", parent, + tag_partner_lev, tagId, groupId); + Utility.evtdb(groupId, 1, sql); + GroupPublisherService.updateMemberEvt(groupId, tagId, 3, tag_partner_lev); + jedis10.hset(tag_key, "parentId", parent + ""); + jedis10.hset(tag_key, "partnerLev", tag_partner_lev + ""); + BaseCache.updateCacheVer(jedis10, tag_key); + if (mgn_lev == 3) { + List list = Utility.getMemberParents(jedis10, groupId, uid, true); + for (Integer par : list) { + String pl_key = GroupCache.genParListKey(groupId, par); + jedis10.sadd(pl_key, tagId + ""); + } + } + // int member_hp = Integer.parseInt(jedis10.hget(tag_key, "hp")); + // String ph_key = String.format("g{%s}:par_hp:%s", groupId,tagId); + // jedis10.incrBy(ph_key, member_hp); + ITObject resData = TObject.newInstance(); + resData.putInt("parentId", parent); + resData.putInt("partnerLev", tag_partner_lev); + + return resData; + + } finally { + if (lock1 != null) { + lock1.unlock(false); + } + lock.unlock(); + + } + } + + /** + * 设置备注值 + * + * @param groupId + * @param uid + * @param tagId + * @param score + * @return + * @throws Exception + */ + public static final void updateMemberScore(int groupId, int uid, int tagId, int score) throws Exception { + log.info("updateMemberScore uid:" + uid + " tagId:" + tagId + " score:" + score); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + if (mng_bean.lev >= 3) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, false); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + jedis10.hset(tag_bean.redis_key, "score", score + ""); + BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, tagId)); + } finally { + jedis10.close(); + } + } + + public static final void updateMemberDiaokong(int groupId, int uid, int tagId, int diaokongid) throws Exception { + + // 判断uid是否存在 + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + Jedis jedis1b = Redis.use("group1_db1").getJedis(); + try { + String diaokong = jedis1b.hget("gods_value", Integer.toString(tagId)); + if (StringUtil.isNotEmpty(diaokong)) { + jedis1b.hset("gods_value", Integer.toString(tagId), Integer.toString(diaokongid)); + } else { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } finally { + jedis1b.close(); + } + } + + /** + * 设置备注值 + * + * @param groupId + * @param uid + * @param tagId + * @param queueid + * @return + * @throws Exception + */ + public static final void updateMemberQueue(int groupId, int uid, int tagId, int queueid) throws Exception { + log.info("updateMemberQueue uid:" + uid + " tagId:" + tagId + " queue:" + queueid); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + /* + * try { if (mng_bean.lev >= 3) { List par_list = + * Utility.getMemberParents(jedis10, groupId, tagId, false); if (par_list == + * null || !par_list.contains(uid)) { throw new + * WebException(ErrorCode.GROUP_NOT_PERMISSION); } } + * + * jedis10.hset(tag_bean.redis_key, "queueid", queueid + ""); + * BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, tagId)); } + * finally { jedis10.close(); } + */ + + String gm_key = GroupMemberCache.genKey(groupId, tagId); + // Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + + jedis10.hset(tag_bean.redis_key, "queueid", queueid + ""); + BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, tagId)); + + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev == 2) { + String permission = jedis10.hget(mng_key, "permission"); + if (StringUtil.isEmpty(permission) || (Integer.parseInt(permission) & PERMISSION_BAN) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } else if (mgn_lev >= 3) { + if (uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + // log.info("uid:" + uid + " ban_member:" + tagId + " par_list:" + par_list); + } + } + + String group_ban = jedis10.hget(mng_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + throw new WebException(ErrorCode.GROUP_MEMBER_BAN); + } + } finally { + lock1.unlock(false); + } + + // log.info("uid:" + uid + " ban_member:" + tagId + " optType:" + optType + " + // ban:" + ban); + + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + // String _ban = ban + ""; + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + gm_key = GroupMemberCache.genKey(groupId, tagId); + // jedis10.hset(gm_key, "ban", _ban); + // jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + // sql = String.format("update group_member set ban = %s where groupId = %s and + // (parentId in(%s) or uid = %s)", _ban, groupId,child_list2,tmpTagId); + // Utility.evtdb(groupId, 1, sql); + + sql = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + + gm_key = GroupMemberCache.genKey(groupId, childId); + jedis10.hset(gm_key, "queueid", queueid + ""); + // jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key); + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } else { + + // sql = String.format("update group_member set ban = %s where uid = %s AND + // groupId = %s", _ban, tagId,groupId); + // Utility.evtdb(groupId, 1, sql); + jedis10.hset(gm_key, "queueid", queueid + ""); + BaseCache.updateCacheVer(jedis10, gm_key); + } + } finally { + lock.unlock(); + } + } + + /** + * 设置权限看值 + * + * @param groupId + * @param uid + * @param tagId + * @param seeid + * @return + * @throws Exception + */ + public static final void updateMemberSee(int groupId, int uid, int tagId, int seeid) throws Exception { + log.info("updateMemberSee uid:" + uid + " tagId:" + tagId + " seeid:" + seeid); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + if (mng_bean.lev >= 3) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, false); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + jedis10.hset(tag_bean.redis_key, "seeid", seeid + ""); + BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, tagId)); + } finally { + jedis10.close(); + } + } + + /** + * 设置体力值 + * + * @param groupId + * @param uid + * @param tagId + * @param hp + * @return + * @throws Exception + */ + public static final ITObject updateMemberHp(int groupId, int uid, int tagId, int hp, boolean self, int otherId) + throws Exception { + + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(tag_key, jedis10); + try { + lock.lock(); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + // 正在游戏不允许下分操作 + if (hp < 0) { + if (GroupRoomService.checkRoom(groupId, uid)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + if (GroupRoomService.checkRoom(groupId, tagId)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + } + + if (hp > 0) { + int pre_hp = Integer.parseInt(jedis10.hget(tag_key, "hp")); + + if ((long) pre_hp + (long) hp > Integer.MAX_VALUE) { + throw new WebException(ErrorCode._FAILED); + } + } + + int mgn_partner = mng_bean.partnerLev; + int mgn_lev = mng_bean.lev; + if (tag_bean.lev == 1) { + if (uid != tagId) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } else if (tag_bean.lev == 2) { + if (mgn_lev != 1) { + if (uid != tagId) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + + if (mgn_lev == 3 && mgn_partner == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + if (mgn_lev == 2) { + if ((mng_bean.permission & PERMISSION_HP_OPT) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + if (self == false && mgn_lev != 1 && uid == tagId) { + throw new WebException(ErrorCode._FAILED); + } + + if (mgn_lev == 3) { + if (!self) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, false); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } else { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + String lua = MainServer.lua_map.get("mgr"); + Object obj = jedis10.evalsha(lua, Arrays.asList(mng_bean.redis_key, tag_key), + Arrays.asList(hp + "", mgn_lev + "")); + if (obj == null) { + throw new WebException(ErrorCode._FAILED); + } + if (obj instanceof Long) { + Long code = (Long) obj; + if (code == 3) { + throw new WebException(ErrorCode.GROUP_TAG_MGR_HP); + } else if (code == 4) { + throw new WebException(ErrorCode.GROUP_TAG_NO_HP); + } + } else { + ArrayList arr = (ArrayList) obj; + ITObject resData = TObject.newInstance(); + int mhp = arr.get(0).intValue(); + int thp = arr.get(1).intValue(); + resData.putInt("mhp", (int) mhp); + resData.putInt("hp", (int) thp); + + String sql = String.format("{call sp_update_hp_mgr2(%s,%s,%s,%s,%s,%s,%s,%s)}", groupId, uid, hp, mhp, + thp, tagId, mgn_lev, otherId); + Utility.evtdb(groupId, 2, sql); + + if (!self) + log.info("updateMemberHp uid:" + uid + " tagId:" + tagId + " hp:" + hp / 1000); + + // ------------------------邮件 ------------------- + ITObject mail_data = TObject.newInstance(); + mail_data.putInt("mgr_id", uid); + AccountBean acc = AccountCache.getAccount(uid); + mail_data.putString("nick", acc.nick); + mail_data.putString("headurl", acc.portrait); + mail_data.putInt("hp", hp); + mail_data.putInt("type", 1); + int time = (int) (System.currentTimeMillis() / 1000); + mail_data.putInt("time", time); + String mail_key = GroupCache.genMailKey(groupId, tagId); + jedis10.zadd(mail_key, time, mail_data.toJson()); + String mail_tip_key = GroupCache.genMailTipKey(groupId); + jedis10.zadd(mail_tip_key, 1, tagId + ""); + GroupPublisherService.updateMailTipEvt(groupId, tagId); + // ----------------------------------------------- + + String c_tem = hp > 0 ? "upper" : "sub"; + if (mgn_lev < 3) { + String hp_mgr_key = String.format("g%s:hp_mgr:%s", groupId, c_tem); + String hp_mgr_id_key = String.format("g%s:hp_mgr:%s:u%s", groupId, c_tem, uid); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + hp = Math.abs(hp); + CountUtil.countLogByDay(hp_mgr_key, hp, jedis9); + CountUtil.countLogByDay(hp_mgr_id_key, hp, jedis9); + } finally { + jedis9.close(); + } + } else { + String hp_par_id_key = String.format("g%s:hp_par:%s:u%s", groupId, c_tem, uid); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + hp = Math.abs(hp); + CountUtil.countLogByDay(hp_par_id_key, hp, jedis9); + } finally { + jedis9.close(); + } + } + return resData; + } + return null; + } finally { + lock.unlock(); + + } + } + + /** + * 获取奖励数据 + * + * @param groupId + * @param uid + * @return + */ + public static final ITObject getTakeInfo(int groupId, int uid, int tagId) throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + String rhp_key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + String r_hp = Redis.use("group1_db10").get(rhp_key); + int _r_hp = 0; + if (StringUtil.isNotEmpty(r_hp)) { + _r_hp = Integer.parseInt(r_hp); + } + + long day_rewad = 0; + long day_rewad_1 = 0; + long day_rewad_2 = 0; +// int all_day_reward = 0; + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + String key = String.format("g%s:hp_reward:m%s", groupId, tagId); + day_rewad = CountUtil.getCountLogByDay(key, jedis9); + String day_key_1 = key + ":d" + (DateUtils.getBeginDay() - 3600 * 24); + day_rewad_1 = CountUtil.getCountLog(day_key_1, 0, jedis9); + String day_key_2 = key + ":d" + (DateUtils.getBeginDay() - 3600 * 48); + day_rewad_2 = CountUtil.getCountLog(day_key_2, 0, jedis9); + } finally { + jedis9.close(); + } + ITObject resData = TObject.newInstance(); + resData.putLong("total_hp", _r_hp); + // resData.putInt("bank_hp", _b_hp); + resData.putLong("day_rewad", day_rewad); + resData.putLong("day_rewad_1", day_rewad_1); + resData.putLong("day_rewad_2", day_rewad_2); + return resData; + } + + public static final ITObject getBankInfo(int groupId, int uid, int tagId) throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + String mng_key = GroupMemberCache.genKey(groupId, tagId); + // String rhp_key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + // String r_hp = Redis.use("group1_db10").get(rhp_key); + String r_hp = Redis.use("group1_db10").hget(mng_key, "hp"); + long _r_hp = 0; + if (StringUtil.isNotEmpty(r_hp)) { + _r_hp = Long.parseLong(r_hp); + } + String b_hp = Redis.use("group1_db10").hget(mng_key, "bank_hp"); + long _b_hp = 0; + if (StringUtil.isNotEmpty(b_hp)) { + _b_hp = Long.parseLong(b_hp); + } + + int day_rewad = 0; + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + String key = String.format("g%s:hp_reward:m%s", groupId, tagId); + day_rewad = CountUtil.getCountLogByDay(key, jedis9); + } finally { + jedis9.close(); + } + ITObject resData = TObject.newInstance(); + resData.putLong("total_hp", _r_hp); + resData.putLong("bank_hp", _b_hp); + // resData.putInt("day_rewad", day_rewad); + return resData; + } + + /** + * 提取体力值 + * + * @param groupId + * @param uid + * @param hp + * @return + * @throws Exception + */ + public static final ITObject takeHp(int groupId, int uid, int tagId, long hp) throws Exception { + log.info("takeHp uid:" + uid + " tagId:" + tagId + " hp:" + hp / 1000); + if (hp <= 0) { + throw new WebException(ErrorCode._FAILED); + } + + /* + * if (hp > Integer.MAX_VALUE) { throw new + * WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); } + */ + + String mng_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(mng_key, jedis10); + try { + lock.lock(); + + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, tagId); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + String key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + String r_hp = jedis10.get(key); + if (StringUtil.isEmpty(r_hp)) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + if (Long.parseLong(r_hp) < hp) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + long tag_hp = Long.parseLong(jedis10.hget(mng_key, "hp")); + /* + * if (tag_hp + hp > Integer.MAX_VALUE) { throw new + * WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); } + */ + + if (GroupRoomService.checkRoom(groupId, tagId)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + + String lua = MainServer.lua_map.get("take_hp"); + Object obj = jedis10.evalsha(lua, Arrays.asList(key, mng_key), Arrays.asList((int) hp + "")); + if (obj == null) { + throw new WebException(ErrorCode._FAILED); + } + if (obj instanceof Long) { + Long code = (Long) obj; + if (code == 3) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + } else { + ArrayList arr = (ArrayList) obj; + int _r_hp = arr.get(0).intValue(); + int mhp = arr.get(1).intValue(); + String sql = String.format("{call sp_take_reward_hp(%s,%s,%s,%s)}", groupId, tagId, (int) hp, mhp); + Utility.evtdb(groupId, 2, sql); + sql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", _r_hp, + tagId, groupId); + Utility.evtdb(groupId, 1, sql); + ITObject resData = TObject.newInstance(); + resData.putInt("hp", mhp); + resData.putLong("r_hp", _r_hp); + return resData; + } + return null; + } finally { + lock.unlock(); + + } + } + + /** + * 提取体力值 + * + * @param groupId + * @param uid + * @param tagId + * @return + * @throws Exception + */ + public static final void groupTakeHp(int groupId, int uid, int tagId) throws Exception { + log.info("groupTakeHp uid:" + uid + " tagId:" + tagId); + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev != 1) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } finally { + lock1.unlock(false); + } + + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + String key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + String r_hp = jedis10.get(key); + if (!StringUtil.isEmpty(r_hp)) { + try { + long allRewardHp = Long.parseLong(r_hp); + GroupService.takeHp(groupId, uid, tagId, allRewardHp); + } catch (Exception e) { + + } + } + + String tag_gm_key = GroupMemberCache.genKey(groupId, tagId); + String b_hp = jedis10.hget(tag_gm_key, "bank_hp"); + if (!StringUtil.isEmpty(b_hp)) { + try { + long allBankHp = Long.parseLong(b_hp); + GroupService.takeBankHp(groupId, uid, tagId, allBankHp); + } catch (Exception e) { + + } + } + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + sql = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + + String child_key = String.format("g{%s}:m%s:reward_hp", groupId, childId); + String child_hp = jedis10.get(child_key); + if (!StringUtil.isEmpty(child_hp)) { + try { + long allRewardHp = Long.parseLong(child_hp); + GroupService.takeHp(groupId, uid, childId, allRewardHp); + } catch (Exception e) { + + } + } + + String child_tag_gm_key = GroupMemberCache.genKey(groupId, childId); + String child_b_hp = jedis10.hget(child_tag_gm_key, "bank_hp"); + if (!StringUtil.isEmpty(child_b_hp)) { + try { + long allBankHp = Long.parseLong(child_b_hp); + GroupService.takeBankHp(groupId, uid, childId, allBankHp); + } catch (Exception e) { + + } + } + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } else { + String key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + String r_hp = jedis10.get(key); + if (!StringUtil.isEmpty(r_hp)) { + try { + long allRewardHp = Long.parseLong(r_hp); + GroupService.takeHp(groupId, uid, tagId, allRewardHp); + } catch (Exception e) { + + } + } + + String tag_gm_key = GroupMemberCache.genKey(groupId, tagId); + String b_hp = jedis10.hget(tag_gm_key, "bank_hp"); + if (!StringUtil.isEmpty(b_hp)) { + try { + long allBankHp = Long.parseLong(b_hp); + GroupService.takeBankHp(groupId, uid, tagId, allBankHp); + } catch (Exception e) { + + } + } + } + } finally { + lock.unlock(); + } + } + + public static final ITObject takeBankHp(int groupId, int uid, int tagId, long hp) throws Exception { + log.info("takeBankHp uid:" + uid + " tagId:" + tagId + " hp:" + hp / 1000); + if (hp <= 0) { + throw new WebException(ErrorCode._FAILED); + } + /* + * if (hp > Integer.MAX_VALUE) { throw new + * WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); } + */ + String mng_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(mng_key, jedis10); + try { + lock.lock(); + + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, tagId); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + String r_hp = jedis10.hget(mng_key, "bank_hp"); + if (StringUtil.isEmpty(r_hp)) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + if (Long.parseLong(r_hp) < hp) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + long tag_hp = Long.parseLong(jedis10.hget(mng_key, "hp")); + /* + * if (tag_hp + hp > Integer.MAX_VALUE) { throw new + * WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); } + */ + + if (GroupRoomService.checkRoom(groupId, tagId)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + + String lua = MainServer.lua_map.get("bank_hp"); + Object obj = jedis10.evalsha(lua, Arrays.asList(mng_key, mng_key, "bank_hp"), + Arrays.asList((int) hp + "", "0")); + if (obj == null) { + throw new WebException(ErrorCode._FAILED); + } + if (obj instanceof Long) { + Long code = (Long) obj; + if (code == 3) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + } else { + ArrayList arr = (ArrayList) obj; + int mhp = arr.get(0).intValue(); + int b_hp = arr.get(1).intValue(); + String sql = String.format("{call sp_bank_hp(%s,%s,%s,%s)}", groupId, tagId, -(int) hp, mhp); + Utility.evtdb(groupId, 2, sql); + sql = String.format("update group_member set bank_hp = %s where uid = %s AND groupId = %s", b_hp, tagId, + groupId); + Utility.evtdb(groupId, 1, sql); + ITObject resData = TObject.newInstance(); + resData.putInt("hp", mhp); + resData.putLong("b_hp", b_hp); + return resData; + } + return null; + } finally { + lock.unlock(); + } + } + + public static final ITObject saveBankHp(int groupId, int uid, int tagId, long hp) throws Exception { + log.info("saveBankHp uid:" + uid + " tagId:" + tagId + " hp:" + hp / 1000); + if (hp <= 0) { + throw new WebException(ErrorCode._FAILED); + } + + /* + * if (hp > Integer.MAX_VALUE) { throw new + * WebException(ErrorCode.GROUP_PARTNER_HP_THAN_LIMIET); } + */ + + String mng_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(mng_key, jedis10); + try { + lock.lock(); + + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, tagId); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + String cur_hp = jedis10.hget(mng_key, "hp"); + if (StringUtil.isEmpty(cur_hp)) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + if (Long.parseLong(cur_hp) < hp) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + + if (GroupRoomService.checkRoom(groupId, tagId)) { + throw new WebException(ErrorCode.GROUP_DONOT_SUB_HP); + } + + String lua = MainServer.lua_map.get("bank_hp"); + Object obj = jedis10.evalsha(lua, Arrays.asList(mng_key, mng_key, "bank_hp"), Arrays.asList(hp + "", "1")); + if (obj == null) { + throw new WebException(ErrorCode._FAILED); + } + if (obj instanceof Long) { + Long code = (Long) obj; + if (code == 3) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_HP); + } + } else { + ArrayList arr = (ArrayList) obj; + long mhp = arr.get(0).longValue(); + long b_hp = arr.get(1).longValue(); + String sql = String.format("{call sp_bank_hp(%s,%s,%s,%s)}", groupId, tagId, hp, mhp); + Utility.evtdb(groupId, 2, sql); + + sql = String.format("update group_member set bank_hp = %s where uid = %s AND groupId = %s", b_hp, tagId, + groupId); + Utility.evtdb(groupId, 1, sql); + + ITObject resData = TObject.newInstance(); + resData.putLong("hp", mhp); + resData.putLong("b_hp", b_hp); + return resData; + } + return null; + } finally { + lock.unlock(); + } + } + + /** + * 删除成员 + * + * @param groupId + * @param uid + * @param tagId + * @return + * @throws Exception + */ + public static final void delMember(int groupId, int uid, int tagId) throws Exception { + log.info("delMember uid:" + uid + " tagId" + tagId); + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + + int dellev = 3; + RedisLock lock = null; + try { + lock = new RedisLock(tag_key, jedis10); + lock.lock(); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tagId); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + dellev = tag_bean.lev; + + GroupMemberBean mgn = GroupCache.getMember(groupId, uid); + + if (mgn == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int mgn_lev = mgn.lev; + int mgn_partner = mgn.partnerLev; + if (mgn_lev == 3 && mgn_partner == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + + if (mgn_lev == 2) { + if ((mgn.permission & PERMISSION_DEL_MEMBER) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + long hp = Long.parseLong(jedis10.hget(tag_key, "hp")); + if (hp != 0) { + throw new WebException(ErrorCode.GROUP_HP_NOT_0); + } + + int tag_lev = tag_bean.lev; + if (mgn_lev < 3 && tag_lev <= mgn_lev) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + if (mgn_lev == 3 && mgn_partner > 0) { + + GroupBean gb = GroupCache.getGroup(groupId); + if ((gb.option & 1) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + + int parentId = tag_bean.parentId; + if (uid != parentId) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + boolean checkRoom = GroupRoomService.checkRoom(groupId, tagId); + if (checkRoom) { + throw new WebException(ErrorCode.GROUP_MEMBER_ROOM_EXIST); + } + int tag_partner = tag_bean.partnerLev; + String rhp_key = String.format("g{%s}:m%s:reward_hp", groupId, tagId); + String r_hp = jedis10.get(rhp_key); + if (StringUtil.isNotEmpty(r_hp) && Long.parseLong(r_hp) > 0) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_TAKE); + } + + String b_hp = jedis10.hget(tag_key, "bank_hp"); + if (StringUtil.isNotEmpty(b_hp) && Long.parseLong(b_hp) > 0) { + throw new WebException(ErrorCode.GROUP_REWARD_NO_TAKE); + } + + String sql = String.format("select count(1) count from group_member where groupId =%s and parentId=%s ", + groupId, tagId); + ITArray resultList = DataBase.use().executeQueryByTArray(sql); + long count = resultList.getTObject(0).getLong("count"); + if (count > 0) { + throw new WebException(ErrorCode.GROUP_PARTNER_MEMBERS); + } + + String recSql = String.format( + "select count(1) count from room_rec_log where gid =%s and uid=%s and time>%s", groupId, tagId, + System.currentTimeMillis() / 1000 - 259200); + ITArray recList = DataBase.use().executeQueryByTArray(recSql); + long recCount = recList.getTObject(0).getLong("count"); + if (recCount > 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + + List list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (list != null) { + for (Integer par : list) { + if (tag_partner > 0) { + String pl_key = GroupCache.genParListKey(groupId, par); + if (par == tagId) { + jedis10.del(pl_key); + } else { + jedis10.srem(pl_key, tagId + ""); + } + } + String mlk = GroupCache.genMemberListKey(groupId, par); + if (par == tagId) { + jedis10.del(mlk); + } else { + jedis10.srem(mlk, tagId + ""); + } + } + } + + jedis10.hset(tag_key, "opt", "2"); + BaseCache.updateCacheVer(jedis10, tag_key); + jedis10.expire(rhp_key, 10); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + try { + String g_key = GroupCache.genKey(groupId); + jedis11.hincrBy(g_key, "gms", -1); + BaseCache.updateCacheVer(jedis11, g_key); + String key = GroupCache.genGroupsKey(tagId); + jedis11.zrem(key, groupId + ""); + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = jedis11.zrangeByScore(gp_key, 10, 11); + for (String pid : pids) { + String p_reward_key = GroupCache.genRewardKey(groupId, Integer.parseInt(pid)); + jedis10.zrem(p_reward_key, tagId + ""); + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, Integer.parseInt(pid)); + jedis10.zrem(p_xipai_reward_key, tagId + ""); + } + } finally { + jedis11.close(); + } + sql = String.format("{call sp_del_member(%s,%s)}", groupId, tagId); + Utility.evtdb(groupId, 2, sql); + + delMemberLog(groupId, uid, tagId, dellev); + + } finally { + if (lock != null) { + lock.unlock(); + } + } + } + + public static final void delMemberLog(int groupId, int uid, int tagId, int lev) throws Exception { + AccountBean acc = AccountCache.getAccount(uid); + int opid = acc.id; + String opnick = acc.nick; + + AccountBean delacc = AccountCache.getAccount(tagId); + int delid = delacc.id; + String delnick = delacc.nick; + String delPortrait = delacc.portrait; + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITObject obj = new TObject(); + try { + GroupLogService.getMemberData(jedis9, delid, obj, groupId, 1, 0, 0, true, true); + + int total_round = obj.getInt("total_round"); + long curTimee = System.currentTimeMillis() / 1000; + + // GroupMemberBean mgr_gmb = GroupCache.getMember(groupId, delid); + String groupName = "队员"; + // if (mgr_gmb != null) { + if (lev < 3) { + groupName = "队长"; + } else { + groupName = "队员"; + } + // } + + ITObject userData = TObject.newInstance(); + userData.putInt("id", delid); + userData.putUtfString("nick", delnick); + userData.putInt("round", total_round); + userData.putUtfString("group", groupName); + userData.putInt("opid", opid); + userData.putUtfString("opnick", opnick); + userData.putLong("deltime", curTimee); + userData.putUtfString("portrait", delPortrait); + + String str = userData.toJson(); + + String gm_key = "kicklog_" + groupId + "_" + uid; + jedis9.lpush(gm_key, str); + + } finally { + jedis9.close(); + } + + } + + public static final ITArray getKickLog(int groupId, int id, int limit, int num) throws Exception { + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + ITArray kickLogList = TArray.newInstance(); + + try { + String gm_key = "kicklog_" + groupId + "_" + id; + List logs = jedis9.lrange(gm_key, limit, limit + num); + + int i = 0; + + for (String _log : logs) { + ITObject kickLog = TObject.newFromJsonData(_log); + kickLogList.addTObject(kickLog); + + } + } finally { + jedis9.close(); + } + + return kickLogList; + } + + /** + * 申请加入列表 + * + * @param groupId + * @return + * @throws Exception + */ + public static final ITArray getGroupJoins(int groupId) throws Exception { + String joins_key = GroupCache.genJoinsKey(groupId); + + Set uids = Redis.use("group1_db11").smembers(joins_key); + ITArray array = TArray.newInstance(); + for (String tem : uids) { + AccountBean acc = AccountCache.getAccount(Integer.parseInt(tem)); + ITObject obj = TObject.newInstance(); + obj.putInt("id", acc.id); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + array.addTObject(obj); + } + return array; + } + + /** + * 获取整线体力值 + * + * @param groupId + * @param uid + * @param tagId + * @return + * @throws Exception + */ + public static final ITObject getPersonHpTotal(int groupId, int uid, int tagId) throws Exception { + String mng_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(mng_key, jedis10); + try { + lock.lock(); + + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + return getHpTotal(groupId, tagId, 30); + } finally { + lock.unlock(); + } + } + + public static final boolean checkParentsHpTotal(int groupId, int pid, int cacheTime) throws Exception { + + return false; + } + + /** + * 获取整线体力值 + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final ITObject getHpTotal(int groupId, int uid, int cacheTime) throws Exception { + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + if (gmb == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + if (gmb.partnerLev == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + + return getAllHpCache(groupId, uid, cacheTime); + /* + * long allHp = 0; long allOtherHp = 0; HashSet childrenList = + * getMemberAllChildren(groupId, uid); for(Integer tagId : childrenList) { + * String gm_key1 = GroupMemberCache.genKey(groupId, tagId); String strHp = + * Redis.use("group1_db10").hget(gm_key1, "hp"); if + * (StringUtil.isNotEmpty(strHp)) { try { allHp += Integer.parseInt(strHp); } + * catch (Exception e) { } } + * + * String temKey = String.format("g{%s}:m%s:reward_hp", groupId, tagId); String + * strtempValue = Redis.use("group1_db10").get(temKey); if + * (StringUtil.isNotEmpty(strtempValue)) { try { allOtherHp += + * Integer.parseInt(strtempValue); } catch (Exception e) { } } + * + * String mng_key = GroupMemberCache.genKey(groupId, tagId); String r_hp = + * Redis.use("group1_db10").hget(mng_key, "bank_hp"); if + * (StringUtil.isNotEmpty(r_hp)) { try { allOtherHp += Integer.parseInt(r_hp); } + * catch (Exception e) { } } } + * + * ITObject obj1 = TObject.newInstance(); obj1.putLong("hp", allHp + + * allOtherHp); obj1.putLong("total_member", childrenList.size()); return obj1; + */ + } + + /** + * 获取成员列表 + * + * @param groupId + * @param uid + * @param limit + * @param num 1 多到少 2少到多 + * @return + * @throws Exception + */ + public static final ITObject getMembers(int groupId, int uid, int limit, int num) throws Exception { + ITObject obj1 = TObject.newInstance(); + + String sql = "SELECT uid,hp,join_time,lev,parentId,partnerLev,ban "; + // String order_sql = "ORDER BY hp DESC,join_time ASC"; + String order_sql = "ORDER BY lev ASC, join_time DESC"; + + GroupBean gb = GroupCache.getGroup(groupId); + + GroupMemberBean mgr_gmb = GroupCache.getMember(groupId, uid); + + boolean mgr = mgr_gmb.lev < 3; + + String where = "FROM group_member WHERE groupId = " + groupId; + String count_where = where; + if (!mgr) { +// String p = Utility.getChildParentSql(groupId, uid, true); + if (limit > 0) { + limit = limit - 1; + } + count_where += String.format(" AND (parentId=%s or uid=%s)", uid, uid); + where += String.format(" and partnerLev=0 AND parentId=%s", uid, uid); + } + String limit_sql = String.format("limit %s,%s", limit, num); + sql = String.format("%s %s %s %s", sql, where, order_sql, limit_sql); + if (limit == 0) { + String count_sql = String.format("SELECT (SELECT COUNT(1) %s) num,(SELECT IFNULL(SUM(hp),0) %s) t_hp1", + count_where, count_where); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + obj1.putLong("member_num", obj.getLong("num")); + obj1.putLong("hp_num1", obj.getDouble("t_hp1").longValue()); + obj1.putLong("hp_num2", 0); + } else { + obj1.putLong("member_num", 0); + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + } + } + + ITArray arr = TArray.newInstance(); + if (!mgr && limit == 0) { + ITObject obj = TObject.newInstance(); + obj.putInt("uid", uid); + obj.putInt("join_time", mgr_gmb.join_time); + obj.putInt("last_time", mgr_gmb.last_time); + obj.putInt("permission", mgr_gmb.permission); + obj.putInt("parentId", mgr_gmb.parentId); + AccountBean acc = AccountCache.getAccount(uid); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + + if (mgr_gmb.parentId > 0) { + AccountBean parent_acc = AccountCache.getAccount(mgr_gmb.parentId); + if (parent_acc != null) { + obj.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", mgr_gmb.parentId); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + obj.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + obj.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + obj.putString("parentId_nick", StringUtil.Empty); + } + + obj.putInt("partnerLev", mgr_gmb.partnerLev); + obj.putInt("ban", mgr_gmb.ban); + + obj.putInt("lev", 3); + + String ugm_key = GroupMemberCache.genKey(groupId, uid); + String hp = Redis.use("group1_db10").hget(ugm_key, "hp"); + obj.putLong("hp", Long.parseLong(hp)); + + arr.addTObject(obj); + } + ITArray arr1 = DataBase.use().executeQueryByTArray(sql); + if (arr1.size() > 0) { + for (int i = 0; i < arr1.size(); ++i) { + ITObject obj = arr1.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + if (acc != null) { + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + } else { + obj.putString("nick", StringUtil.Empty); + obj.putString("portrait", StringUtil.Empty); + } + + if (obj.getInt("parentId") > 0) { + AccountBean parent_acc = AccountCache.getAccount(obj.getInt("parentId")); + if (parent_acc != null) { + obj.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", obj.getInt("parentId")); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + obj.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + obj.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + if (mgr_gmb.lev == 1 && uid != obj.getInt("uid")) { + AccountBean uid_acc = AccountCache.getAccount(uid); + obj.putInt("parentId", uid); + obj.putString("parentId_nick", uid_acc.nick); + } else { + obj.putString("parentId_nick", StringUtil.Empty); + } + } + + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb == null) { + arr1.del(i); + i--; + continue; + } + obj.putInt("last_time", gmb.last_time); + obj.putInt("permission", gmb.permission); + obj.putInt("score", gmb.score); + + String ugm_key = GroupMemberCache.genKey(groupId, acc.id); + String group_ban = Redis.use("group1_db10").hget(ugm_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + obj.putInt("group_ban", 1); + } else { + obj.putInt("group_ban", 0); + } + + arr.addTObject(obj); + } + } + obj1.putTArray("members", arr); + obj1.putInt("limit", limit); + return obj1; + } + + /** + * 获取合伙人所有下级成员 + * + * @param groupId + * @param tagId + * @return + */ + public static HashSet getMemberAllChildren(int groupId, int tagId) { + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + if (isPartner) { + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + sql = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } + } catch (Exception e) { + + } finally { + lock.unlock(); + } + + return hashSet; + } + + public static String getMemberAllChildren2(int groupId, int tagId) { + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + String list = ""; + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + if (isPartner) { + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + sql = String.format( + "select uid,partnerLev from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + int partnerLev = tem.getInt("partnerLev"); + + if (hashSet.contains(childId)) + continue; + + hashSet.add(childId); + + if (partnerLev > 0) + arrayList.add(childId); + } + } + } + } + } + } catch (Exception e) { + + } finally { + } + + list += "" + tagId; + hashSet.remove(tagId); + for (Integer iid : hashSet) { + list += "," + iid; + } + return list; + } + + public static String getMemberAllChildren3(int groupId, int tagId) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + String list = ""; + try { + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql = ""; + if (isPartner) { + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + while (!arrayList.isEmpty()) { + String strParentId = "" + arrayList.get(0); + for (int i = 1; i < arrayList.size(); i++) { + strParentId += "," + arrayList.get(i); + } + arrayList.clear(); + + sql = String.format( + "select uid,partnerLev from group_member where groupId = %s and (parentId in(%s))", groupId, + strParentId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + int partnerLev = tem.getInt("partnerLev"); + + if (hashSet.contains(childId)) + continue; + + hashSet.add(childId); + + if (partnerLev > 0) + arrayList.add(childId); + } + } + } + } + } catch (Exception e) { + + } finally { + } + + list += "" + tagId; + hashSet.remove(tagId); + for (Integer iid : hashSet) { + list += "," + iid; + } + return list; + } + + public static final ITObject getAllplay(int groupId, int uid) throws Exception { + ITArray games = new TArray(); + ITArray togames = new TArray(); + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + ITObject obj1 = TObject.newInstance(); + try { + Set list = jedis1.zrevrangeByScore("online_games", 1000, 1); + for (String game : list) { + int gameId = Integer.parseInt(game); + GameBean gb = GameCache.getGame(gameId); + if (gb == null) + continue; + ITObject gameObj = gb.getTObject(); + + for (Map.Entry entry : gb.pay.entrySet()) { + gameObj.putInt(entry.getKey(), entry.getValue()); + } + games.addTObject(gameObj); + } + + String gm_key = GroupMemberCache.genKey(groupId, uid); + String gameids = jedis10.hget(gm_key, "games"); + if (StringUtil.isNotEmpty(gameids)) { + String[] tmp = gameids.split(","); + for (String gtmp : tmp) { + togames.addString(gtmp); + } + + } + obj1.putTArray("togames", togames); + } finally { + jedis1.close(); + jedis10.close(); + } + + obj1.putTArray("games", games); + return obj1; + } + + public static final void setBanplay(int groupId, int uid, String bans) throws Exception { + GroupMemberBean tag_bean = GroupCache.getMember(groupId, uid); + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String gm_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + + jedis10.hset(tag_bean.redis_key, "games", bans); + BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, uid)); + + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + if (gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + // String _ban = ban + ""; + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(uid); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(uid); + + gm_key = GroupMemberCache.genKey(groupId, uid); + BaseCache.updateCacheVer(jedis10, gm_key); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + sql = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + gm_key = GroupMemberCache.genKey(groupId, childId); + jedis10.hset(gm_key, "games", bans); + BaseCache.updateCacheVer(jedis10, gm_key); + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } else { + jedis10.hset(gm_key, "games", bans); + BaseCache.updateCacheVer(jedis10, gm_key); + } + } finally { + lock.unlock(); + } + + } + + /** + * + * @param groupId + * @param uid 查询用户id + * @param tagId 目标id + * @param online + * @param type + * @param limit + * @param num + * @return + * @throws Exception + */ + public static final ITObject getMembers_child(int groupId, int uid, int tagId, int online, int type, int limit, + int num) throws Exception { + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + ITObject obj1 = TObject.newInstance(); + + String sql = "SELECT uid,hp,join_time,lev,parentId,partnerLev,ban "; + String order_sql = "ORDER BY lev ASC,partnerLev DESC,hp DESC,uid ASC"; + + String where = "FROM group_member WHERE groupId = " + groupId; + + long allOtherHp = 0; + long allNum = 0; + + if (limit > 0) { + limit = limit - 1; + } + where += String.format(" AND parentId=%s", tagId); + + String limit_sql = String.format("limit %s,%s", limit, num); + sql = String.format("%s %s %s %s", sql, where, order_sql, limit_sql); + log.info("sql:" + sql); + + ITArray arr = TArray.newInstance(); + + ITArray arr1 = DataBase.use().executeQueryByTArray(sql); + if (arr1.size() > 0) { + for (int i = 0; i < arr1.size(); ++i) { + ITObject obj = arr1.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + if (acc == null) { + continue; + } + if (limit == 0 && acc.id == tagId) { + continue; + } + if (acc != null) { + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + } else { + obj.putString("nick", StringUtil.Empty); + obj.putString("portrait", StringUtil.Empty); + } + + if (obj.getInt("parentId") > 0) { + AccountBean parent_acc = AccountCache.getAccount(obj.getInt("parentId")); + if (parent_acc != null) { + obj.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", obj.getInt("parentId")); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + obj.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + obj.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + + if (obj.getInt("lev") <= 2 && tagId != obj.getInt("uid")) { + AccountBean uid_acc = AccountCache.getAccount(tagId); + obj.putInt("parentId", tagId); + obj.putString("parentId_nick", uid_acc.nick); + + log.info("litte mgr uid:" + obj.getInt("uid")); + } else if (obj.getInt("lev") == 3 && tagId != obj.getInt("uid")) { + AccountBean uid_acc = AccountCache.getAccount(tagId); + obj.putInt("parentId", tagId); + obj.putString("parentId_nick", uid_acc.nick); + + log.info("aa litte mgr uid:" + obj.getInt("uid")); + } + + } + + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb == null) { + arr1.del(i); + i--; + continue; + } + obj.putInt("last_time", gmb.last_time); + obj.putInt("permission", gmb.permission); + obj.putInt("score", gmb.score); + obj.putInt("queueid", gmb.queueid); + obj.putInt("seeid", gmb.seeid); + + // --调控 + Jedis jedis1b = Redis.use("group1_db1").getJedis(); + try { + String diaokongid = jedis1b.hget("gods_value", Integer.toString(acc.id)); + if (StringUtil.isNotEmpty(diaokongid)) { + obj.putInt("diaokongid", Integer.parseInt(diaokongid)); + } else { + obj.putInt("diaokongid", -1); + } + } finally { + jedis1b.close(); + } + + String ugm_key = GroupMemberCache.genKey(groupId, acc.id); + String group_ban = Redis.use("group1_db10").hget(ugm_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + obj.putInt("group_ban", 1); + } else { + obj.putInt("group_ban", 0); + } + + obj.putInt("online", 1); + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + int endtime = DateUtils.getBeginDay() + 86400; + int begintime = endtime - 86400 * 30; + GroupLogService.getMemberData(jedis9, acc.id, obj, groupId, 0, begintime, endtime, false, false); + } finally { + jedis9.close(); + } + + arr.addTObject(obj); + } + } + + log.info("arr = " + arr); + + obj1.putLong("otherHp", allOtherHp); + obj1.putLong("member_num", 0); + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + obj1.putTArray("members", arr); + obj1.putInt("limit", limit); + + return obj1; + } + + /** + * 获取成员列表 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @param minus_only + * @param type 1 多到少 2少到多 + * @return + * @throws Exception + */ + public static final ITObject getMembers_1(int groupId, int uid, int tagId, int online, int type, int limit, int num) + throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10.close(); + } + + ITObject obj1 = TObject.newInstance(); + + String sql = "SELECT uid,hp,join_time,lev,parentId,partnerLev,ban "; + String order_sql = "ORDER BY lev ASC,partnerLev DESC,hp DESC,uid ASC"; +// String order_sql = "ORDER BY lev ASC,partnerLev DESC,hp DESC"; + + GroupBean gb = GroupCache.getGroup(groupId); + + GroupMemberBean mgr_gmb = GroupCache.getMember(groupId, tagId); + + boolean mgr = mgr_gmb.lev < 3; + + String where = "FROM group_member WHERE groupId = " + groupId; + long allOtherHp = 0; + long allNum = 0; + if (!mgr) { +// String p = Utility.getChildParentSql(groupId, uid, true); + if (limit > 0) { + limit = limit - 1; + } + where += String.format(" AND parentId=%s", tagId); + } else { + if (type == 1) { + GroupBean groupBean = GroupCache.getGroup(groupId); + + where += String.format(" AND (parentId=%s OR parentId = 0)", groupBean.owner); + } + } + + String limit_sql = String.format("limit %s,%s", limit, num); + sql = String.format("%s %s %s %s", sql, where, order_sql, limit_sql); + + ITArray arr = TArray.newInstance(); + if (limit == 0) { + ITObject obj = TObject.newInstance(); + obj.putInt("uid", tagId); + obj.putInt("join_time", mgr_gmb.join_time); + obj.putInt("last_time", mgr_gmb.last_time); + obj.putInt("permission", mgr_gmb.permission); + obj.putInt("parentId", mgr_gmb.parentId); + AccountBean acc = AccountCache.getAccount(tagId); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + obj.putInt("online", 1); + + if (mgr_gmb.parentId > 0) { + AccountBean parent_acc = AccountCache.getAccount(mgr_gmb.parentId); + if (parent_acc != null) { + obj.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", mgr_gmb.parentId); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + obj.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + obj.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + obj.putString("parentId_nick", StringUtil.Empty); + } + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + int endtime = DateUtils.getBeginDay() + 86400; + int begintime = endtime - 86400 * 30; + GroupLogService.getMemberData(jedis9, acc.id, obj, groupId, 0, begintime, endtime, false, false); + } finally { + jedis9.close(); + } + + obj.putInt("partnerLev", mgr_gmb.partnerLev); + obj.putInt("ban", mgr_gmb.ban); + + obj.putInt("lev", mgr_gmb.lev); + + String ugm_key = GroupMemberCache.genKey(groupId, tagId); + String hp = Redis.use("group1_db10").hget(ugm_key, "hp"); + obj.putLong("hp", Long.parseLong(hp)); + + arr.addTObject(obj); + } + ITArray arr1 = DataBase.use().executeQueryByTArray(sql); + if (arr1.size() > 0) { + for (int i = 0; i < arr1.size(); ++i) { + ITObject obj = arr1.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + if (acc == null) { + continue; + } + if (limit == 0 && acc.id == tagId) { + continue; + } + if (acc != null) { + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + } else { + obj.putString("nick", StringUtil.Empty); + obj.putString("portrait", StringUtil.Empty); + } + + if (obj.getInt("parentId") > 0) { + AccountBean parent_acc = AccountCache.getAccount(obj.getInt("parentId")); + if (parent_acc != null) { + obj.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", obj.getInt("parentId")); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + obj.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + obj.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + if (mgr_gmb.lev < 3) { + if (obj.getInt("lev") <= 2 && tagId != obj.getInt("uid")) { + AccountBean uid_acc = AccountCache.getAccount(tagId); + obj.putInt("parentId", tagId); + obj.putString("parentId_nick", uid_acc.nick); + + log.info("litte mgr uid:" + obj.getInt("uid")); + } else if (obj.getInt("lev") == 3 && tagId != obj.getInt("uid")) { + AccountBean uid_acc = AccountCache.getAccount(tagId); + obj.putInt("parentId", tagId); + obj.putString("parentId_nick", uid_acc.nick); + + log.info("aa litte mgr uid:" + obj.getInt("uid")); + } + } + } + + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb == null) { + arr1.del(i); + i--; + continue; + } + obj.putInt("last_time", gmb.last_time); + obj.putInt("permission", gmb.permission); + obj.putInt("score", gmb.score); + obj.putInt("queueid", gmb.queueid); + obj.putInt("seeid", gmb.seeid); + + // --调控 + Jedis jedis1b = Redis.use("group1_db1").getJedis(); + try { + String diaokongid = jedis1b.hget("gods_value", Integer.toString(acc.id)); + if (StringUtil.isNotEmpty(diaokongid)) { + obj.putInt("diaokongid", Integer.parseInt(diaokongid)); + } else { + obj.putInt("diaokongid", -1); + } + } finally { + jedis1b.close(); + } + + String ugm_key = GroupMemberCache.genKey(groupId, acc.id); + String hp = Redis.use("group1_db10").hget(ugm_key, "hp"); + obj.putLong("hp", Long.parseLong(hp)); + + String group_ban = Redis.use("group1_db10").hget(ugm_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + obj.putInt("group_ban", 1); + } else { + obj.putInt("group_ban", 0); + } + + obj.putInt("online", 1); + + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + int endtime = DateUtils.getBeginDay() + 86400; + int begintime = endtime - 86400 * 30; + GroupLogService.getMemberData(jedis9, acc.id, obj, groupId, 0, begintime, endtime, false, false); + } finally { + jedis9.close(); + } + + arr.addTObject(obj); + } + } + + // log.info("arr = "+ arr); + + obj1.putLong("otherHp", allOtherHp); + obj1.putLong("member_num", 0); + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + obj1.putTArray("members", arr); + obj1.putInt("limit", limit); + + return obj1; + } + + public static final ITObject getAllHpCache(int groupId, int uid, int cache_time) throws Exception { + String gm_key = GroupMemberCache.genKey(groupId, uid); + + String all_temp_hp_key = gm_key + ":all_temp_hp"; + String all_temp_member_key = gm_key + ":all_temp_total_member"; + String all_temp_hp = Redis.use("group1_db10").get(all_temp_hp_key); + String all_temp_member = Redis.use("group1_db10").get(all_temp_member_key); + ITObject obj1 = TObject.newInstance(); + if (all_temp_hp == null || StringUtil.isEmpty(all_temp_hp) || all_temp_member == null + || StringUtil.isEmpty(all_temp_member)) { + obj1.putLong("hp", 0); + obj1.putLong("total_member", 0); + + /* + * String child_sql = + * String.format("{? = call selectPartnerChildHpByParentId(%s,%s)}", uid, + * groupId); String child_key = + * String.format("selectPartnerChildHpByParentId(%s,%s)", uid, groupId); ITArray + * temparr = new TArray(); try { temparr = DataBase.use().executeCall(child_sql, + * true); }catch (Exception e) { e.printStackTrace(); } + * + * if (temparr.size() > 0) { TDataWrapper data = temparr.get(0); TObject map = + * (TObject)data.getObject(); String key_value = map.getString(child_key); + * String[] split = key_value.split(","); if (split.length == 2) { long _allHp = + * Long.parseLong(split[0]); long _allNum = Long.parseLong(split[1]); + * + * obj1.putLong("hp", _allHp); obj1.putLong("total_member", _allNum); + * + * Redis.use("group1_db10").set(all_temp_hp_key, ""+_allHp); + * Redis.use("group1_db10").expire(all_temp_hp_key, cache_time); + * Redis.use("group1_db10").set(all_temp_member_key, ""+_allNum); + * Redis.use("group1_db10").expire(all_temp_member_key, cache_time); } } + */ + + String sql = "SELECT uid "; + String where = "FROM group_member WHERE groupId = " + groupId; + String count_where = where; + String childSql = getMemberAllChildren3(groupId, uid); + count_where = String.format(" %s and uid in (%s)", where, childSql); + String count_sql = String.format( + "SELECT (SELECT COUNT(1) %s) num,(SELECT IFNULL(SUM(hp+bank_hp+reward_hp),0) %s) t_hp1", + count_where, count_where); + log.info("lingmeng getAllHp count_sql"); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + +// long _allHp = obj.getDouble("t_hp1").longValue(); + long _allNum = obj.getLong("num"); +// g{618028}:m179357 +// obj1.putLong("hp", _allHp); + String uidKey = "g{" + groupId + "}:m" + uid; + long _allHp = obj.getDouble("t_hp1").longValue(); + + obj1.putLong("hp", _allHp); + obj1.putLong("total_member", _allNum); + Redis.use("group1_db10").set(all_temp_hp_key, "" + _allHp); + Redis.use("group1_db10").expire(all_temp_hp_key, cache_time); + Redis.use("group1_db10").set(all_temp_member_key, "" + _allNum); + Redis.use("group1_db10").expire(all_temp_member_key, cache_time); + } else { + obj1.putLong("hp", 0); + obj1.putLong("total_member", 0); + } + } else { + + obj1.putLong("hp", Long.parseLong(all_temp_hp)); + obj1.putLong("total_member", Long.parseLong(all_temp_member)); + } + + return obj1; + } + + /** + * 获取成员列表 + * + * @param groupId + * @param uid + * @param limit + * @param num + * @param minus_only + * @param type 1 多到少 2少到多 + * @return + * @throws Exception + */ + public static final ITObject getMemberCount(int groupId, int uid) throws Exception { + ITObject obj1 = TObject.newInstance(); + + String sql = "SELECT uid "; + + GroupMemberBean mgr_gmb = GroupCache.getMember(groupId, uid); + + boolean mgr = mgr_gmb.lev < 3; + + String where = "FROM group_member WHERE groupId = " + groupId; + String count_where = where; + long allOtherHp = 0; + long allHp = 0; + if (!mgr) { + obj1.putLong("member_num", 0); + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + + ITObject obj2 = getAllHpCache(groupId, uid, 30); + obj1.putLong("member_num", obj2.getLong("total_member")); + obj1.putLong("hp_num1", obj2.getLong("hp")); + obj1.putLong("hp_num2", 0); + + /* + * HashSet childrenList = getMemberAllChildren(groupId, uid); + * for(Integer tagId : childrenList) { String gm_key1 = + * GroupMemberCache.genKey(groupId, tagId); String strHp = + * Redis.use("group1_db10").hget(gm_key1, "hp"); if + * (StringUtil.isNotEmpty(strHp)) { try { allHp += Integer.parseInt(strHp); } + * catch (Exception e) { } } + * + * String temKey = String.format("g{%s}:m%s:reward_hp", groupId, tagId); String + * strtempValue = Redis.use("group1_db10").get(temKey); if + * (StringUtil.isNotEmpty(strtempValue)) { try { allOtherHp += + * Integer.parseInt(strtempValue); } catch (Exception e) { } } + * + * String mng_key = GroupMemberCache.genKey(groupId, tagId); String r_hp = + * Redis.use("group1_db10").hget(mng_key, "bank_hp"); if + * (StringUtil.isNotEmpty(r_hp)) { try { allOtherHp += Integer.parseInt(r_hp); } + * catch (Exception e) { } } } obj1.putLong("member_num", childrenList.size()); + * obj1.putLong("hp_num1", allHp); obj1.putLong("hp_num2", 0); + */ + } else { + /* + * sql = String.format("%s %s", sql, where); String count_sql = String. + * format("SELECT (SELECT COUNT(1) %s) num,(SELECT IFNULL(SUM(hp+reward_hp+bank_hp),0) %s) t_hp1" + * , count_where, count_where); ITArray arr = + * DataBase.use().executeQueryByTArray(count_sql); if (arr.size() > 0) { + * ITObject obj = arr.getTObject(0); allHp = obj.getDouble("t_hp1").longValue(); + * obj1.putLong("member_num", obj.getLong("num")); obj1.putLong("hp_num1", + * obj.getDouble("t_hp1").longValue()); obj1.putLong("hp_num2", 0); } else { + * obj1.putLong("member_num", 0); obj1.putLong("hp_num1", 0); + * obj1.putLong("hp_num2", 0); } + */ + sql = String.format("%s %s", sql, where); + String count_sql = String.format( + "SELECT (SELECT COUNT(1) %s) num,(SELECT IFNULL(SUM(hp+bank_hp+reward_hp),0) %s) t_hp1", + count_where, count_where); + ITArray arr = DataBase.use().executeQueryByTArray(count_sql); + if (arr.size() > 0) { + ITObject obj = arr.getTObject(0); + allHp = obj.getDouble("t_hp1").longValue(); + obj1.putLong("member_num", obj.getLong("num")); + obj1.putLong("hp_num1", obj.getDouble("t_hp1").longValue()); + obj1.putLong("hp_num2", 0); + } else { + obj1.putLong("member_num", 0); + obj1.putLong("hp_num1", 0); + obj1.putLong("hp_num2", 0); + } + /* + * ITArray arr1 = DataBase.use().executeQueryByTArray(sql); if (arr1.size() > 0) + * { for (int i = 0; i < arr1.size(); ++i) { ITObject obj = arr1.getTObject(i); + * int tagId = obj.getInt("uid"); + * + * String temKey = String.format("g{%s}:m%s:reward_hp", groupId, tagId); String + * strtempValue = Redis.use("group1_db10").get(temKey); if + * (StringUtil.isNotEmpty(strtempValue)) { try { allOtherHp += + * Integer.parseInt(strtempValue); } catch (Exception e) { } } + * + * + * String mng_key = GroupMemberCache.genKey(groupId, tagId); String r_hp = + * Redis.use("group1_db10").hget(mng_key, "bank_hp"); if + * (StringUtil.isNotEmpty(r_hp)) { try { allOtherHp += Integer.parseInt(r_hp); } + * catch (Exception e) { } } } } + */ + } + + // log.info("arr = "+ arr); + + obj1.putLong("otherHp", allOtherHp); + + if (mgr_gmb.lev == 1) { + log.info("otherHp = " + allOtherHp); + log.info("allHp = " + allHp); + } + + return obj1; + } + + /** + * 查询成员 + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final ITObject findMember(int groupId, int uid, int queryId, String tagName) throws Exception { + + ITObject obj = TObject.newInstance(); + ITArray array = TArray.newInstance(); + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + List memberParents = Utility.getMemberParents(jedis10, groupId, queryId, true); + + String ugm_key = GroupMemberCache.genKey(groupId, uid); + String lev = jedis10.hget(ugm_key, "lev"); + int _lev = StringUtil.isNotEmpty(lev) ? Integer.parseInt(lev) : 3; + + String gm_key = GroupMemberCache.genKey(groupId, queryId); + Map map = null; + + while (queryId > 0) { + + map = jedis10.hgetAll(gm_key); + if (map.size() == 0 || Integer.parseInt(map.get("opt")) == 2) { + break; + } + + int parentId = Integer.parseInt(map.get("parentId")); + if (_lev == 3) { + + if (parentId == 0) { + break; + } + + if (!memberParents.contains(uid)) { + break; + } + } + + ITObject temp = TObject.newInstance(); + temp.putInt("uid", queryId); + temp.putLong("hp", Long.parseLong(map.get("hp"))); + temp.putInt("join_time", Integer.parseInt(map.get("join_time"))); + temp.putInt("lev", Integer.parseInt(map.get("lev"))); + temp.putInt("parentId", Integer.parseInt(map.get("parentId"))); + temp.putInt("queueid", Integer.parseInt(map.get("queueid") == null ? "0" : map.get("queueid"))); + temp.putInt("seeid", Integer.parseInt(map.get("seeid") == null ? "0" : map.get("seeid"))); + if (Integer.parseInt(map.get("parentId")) > 0) { + AccountBean parent_acc = AccountCache.getAccount(Integer.parseInt(map.get("parentId"))); + if (parent_acc != null) { + temp.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", + Integer.parseInt(map.get("parentId"))); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + temp.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + temp.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + if (_lev == 1 && uid != queryId) { + AccountBean uid_acc = AccountCache.getAccount(uid); + temp.putInt("parentId", uid); + temp.putString("parentId_nick", uid_acc.nick); + } else { + temp.putString("parentId_nick", StringUtil.Empty); + } + } + + temp.putInt("partnerLev", Integer.parseInt(map.get("partnerLev"))); + temp.putInt("ban", Integer.parseInt(map.get("ban"))); + + String group_ban = Redis.use("group1_db10").hget(gm_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + temp.putInt("group_ban", 1); + } else { + temp.putInt("group_ban", 0); + } + AccountBean acc = AccountCache.getAccount(queryId); + temp.putString("nick", acc.nick); + temp.putString("portrait", acc.portrait); + String last_time = map.get("last_time"); + + temp.putInt("last_time", StringUtil.isNotEmpty(last_time) ? Integer.parseInt(last_time) : 0); + String permission = map.get("permission"); + temp.putInt("permission", StringUtil.isNotEmpty(permission) ? Integer.parseInt(permission) : 0); + temp.putInt("queueid", Integer.parseInt(map.get("queueid") == null ? "0" : map.get("queueid"))); + temp.putInt("seeid", Integer.parseInt(map.get("seeid") == null ? "0" : map.get("seeid"))); + // --调控 + Jedis jedis1b = Redis.use("group1_db1").getJedis(); + try { + String diaokongid = jedis1b.hget("gods_value", Integer.toString(acc.id)); + if (StringUtil.isNotEmpty(diaokongid)) { + temp.putInt("diaokongid", Integer.parseInt(diaokongid)); + } else { + temp.putInt("diaokongid", -1); + } + } finally { + jedis1b.close(); + } + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + int endtime = DateUtils.getBeginDay() + 86400; + int begintime = endtime - 86400 * 30; + GroupLogService.getMemberData(jedis9, acc.id, temp, groupId, 0, begintime, endtime, false, false); + } finally { + jedis9.close(); + } + + array.addTObject(temp); + break; + } + + if (StringUtil.isNotEmpty(tagName)) { + + String sql = String.format("select id from account as a " + "right join group_member as b " + + "on a.id = b.uid and b.groupId =%s " + "where nick like '%%%s%%'", groupId, tagName); + + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (arr.size() > 0) { + + for (int i = 0; i < arr.size(); i++) { + + int tag = arr.getTObject(i).getInt("id"); + + if (queryId > 0 && tag == queryId) { + continue; + } + + gm_key = GroupMemberCache.genKey(groupId, tag); + + map = jedis10.hgetAll(gm_key); + if (map.size() == 0 || Integer.parseInt(map.get("opt")) == 2) { + continue; + } + + int parentId = Integer.parseInt(map.get("parentId")); + if (_lev == 3) { + + if (parentId == 0) { + continue; + } + + if (parentId != uid) { + continue; + } + } + + ITObject temp = TObject.newInstance(); + temp.putInt("uid", tag); + temp.putInt("hp", Integer.parseInt(map.get("hp"))); + temp.putInt("join_time", Integer.parseInt(map.get("join_time"))); + temp.putInt("lev", Integer.parseInt(map.get("lev"))); + temp.putInt("parentId", Integer.parseInt(map.get("parentId"))); + temp.putInt("queueid", Integer.parseInt(map.get("queueid") == null ? "0" : map.get("queueid"))); + temp.putInt("seeid", Integer.parseInt(map.get("seeid") == null ? "0" : map.get("seeid"))); + + Jedis jedis1b = Redis.use("group1_db1").getJedis(); + try { + String diaokongid = jedis1b.hget("gods_value", Integer.toString(tag)); + if (StringUtil.isNotEmpty(diaokongid)) { + temp.putInt("diaokongid", Integer.parseInt(diaokongid)); + } else { + temp.putInt("diaokongid", -1); + } + } finally { + jedis1b.close(); + } + + if (Integer.parseInt(map.get("parentId")) > 0) { + AccountBean parent_acc = AccountCache.getAccount(Integer.parseInt(map.get("parentId"))); + if (parent_acc != null) { + temp.putString("parentId_nick", parent_acc.nick); + } else { + String sql2 = String.format("SELECT nick FROM account WHERE id ='%d'", + Integer.parseInt(map.get("parentId"))); + ITArray resultArray = DataBase.use().executeQueryByTArray(sql2); + if (resultArray.size() == 0) { + temp.putString("parentId_nick", StringUtil.Empty); + } else { + ITObject userData = resultArray.getTObject(0); + temp.putString("parentId_nick", userData.getUtfString("nick")); + } + } + } else { + if (_lev == 1 && uid != tag) { + AccountBean uid_acc = AccountCache.getAccount(uid); + temp.putInt("parentId", uid); + temp.putString("parentId_nick", uid_acc.nick); + } else { + temp.putString("parentId_nick", StringUtil.Empty); + } + } + + temp.putInt("partnerLev", Integer.parseInt(map.get("partnerLev"))); + temp.putInt("ban", Integer.parseInt(map.get("ban"))); + temp.putInt("queueid", Integer.parseInt(map.get("queueid") == null ? "0" : map.get("queueid"))); + temp.putInt("seeid", Integer.parseInt(map.get("seeid") == null ? "0" : map.get("seeid"))); + AccountBean acc = AccountCache.getAccount(tag); + temp.putString("nick", acc.nick); + temp.putString("portrait", acc.portrait); + String last_time = map.get("last_time"); + temp.putInt("last_time", StringUtil.isNotEmpty(last_time) ? Integer.parseInt(last_time) : 0); + String permission = map.get("permission"); + temp.putInt("permission", StringUtil.isNotEmpty(permission) ? Integer.parseInt(permission) : 0); + + // --调控 + Jedis jedis1bb = Redis.use("group1_db1").getJedis(); + try { + String diaokongid = jedis1bb.hget("gods_value", Integer.toString(acc.id)); + if (StringUtil.isNotEmpty(diaokongid)) { + temp.putInt("diaokongid", Integer.parseInt(diaokongid)); + } else { + temp.putInt("diaokongid", -1); + } + } finally { + jedis1bb.close(); + } + + array.addTObject(temp); + } + } + } + } finally { + jedis10.close(); + } + + obj.putTArray("members", array); + return obj; + } + + /** + * + * @param groupId + * @param uid + * @return + * @throws Exception + */ + public static final ITObject findMember1(int groupId, int uid) throws Exception { + String gm_key = GroupMemberCache.genKey(groupId, uid); + Map map = Redis.use("group1_db10").hgetAll(gm_key); + if (map.size() == 0 || Integer.parseInt(map.get("opt")) == 2) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + ITObject obj = TObject.newInstance(); + obj.putInt("uid", uid); + obj.putLong("hp", Long.parseLong(map.get("hp"))); + AccountBean acc = AccountCache.getAccount(uid); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + return obj; + } + + /** + * 获取成员上级列表 + * + * @param groupId + * @param uid + * @return + */ + public static final ITArray getMemberParents(int groupId, int uid) { + ITArray list = TArray.newInstance(); + List t_list = Utility.getMemberParents(groupId, uid); + if (t_list != null) { + for (Integer n : t_list) { + list.addInt(n); + } + } + return list; + } + + /** + * + * @param groupId + * @param uid + * @return + */ + public static final int getParents(int groupId, int uid) { + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + if (gmb == null) { + return 0; + } + return gmb.parentId; + } + + /** + * 获取合伙人列表 + * + * @param groupId + * @param page + * @return + * @throws Exception + */ + public static final ITObject getPartners(int groupId, int uid, int limit, int num, int qid) throws Exception { + ITObject obj1 = TObject.newInstance(); + String qid_sql = StringUtil.Empty; + GroupMemberBean gmb = GroupCache.getMember(groupId, uid); + boolean self = qid == 0 || qid == uid; + ITArray arr1 = TArray.newInstance(); + if (self && gmb.lev == 3 && limit == 0) { + ITObject obj = TObject.newInstance(); + obj.putInt("uid", uid); + AccountBean acc = AccountCache.getAccount(uid); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + obj.putInt("partnerLev", gmb.partnerLev); + arr1.addTObject(obj); + } + if (qid != uid) { + if (qid > 0) { + qid_sql = "AND uid=" + qid; + } + String sql = String.format( + "SELECT uid,partnerLev FROM group_member where groupId =%s and parentId=%s %s and partnerLev>0 limit %s,%s", + groupId, uid, qid_sql, limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (arr.size() > 0) { + for (int i = 0; i < arr.size(); ++i) { + ITObject obj = arr.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + arr1.addTObject(obj); + } + } + } + + obj1.putTArray("members", arr1); + obj1.putInt("limit", limit); + return obj1; + } + + /** + * 获取指定合伙人奖励数据 + * + * @param groupId + * @param parentId + * @param tagId + * @param partnerLev + * @return + */ + public static final void getRewards(int groupId, int parentId, int tagId, int partnerLev, ITObject resData) { + + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 11, 11); + if (pids.size() == 0) { + return; + } + + boolean isShowXiPai = false; + GroupBean gb = GroupCache.getGroup(groupId); + if (gb != null) { + if (gb.owner == parentId) { + isShowXiPai = true; + } + } + + ITArray arr = TArray.newInstance(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, parentId); + if (uid_bean == null) { + return; + } + + if (uid_bean.lev >= 3 && parentId != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(parentId)) { + return; + } + } + + for (String str : pids) { + int pid = Integer.parseInt(str); + GroupPlayBean gpb = GroupCache.getPlay(groupId, pid); + if (gpb == null) + continue; + + int cur_value = 0; + int max_value = 0; + + int xipai_cur_value = 0; + int xipai_max_value = 0; + + String p_reward_key = GroupCache.genRewardKey(groupId, pid); + Double tem = jedis10.zscore(p_reward_key, tagId + ""); + cur_value = tem == null ? 0 : tem.intValue(); + if (partnerLev == 1) { + max_value = gpb.reward; + } else { + tem = jedis10.zscore(p_reward_key, parentId + ""); + max_value = tem == null ? 0 : tem.intValue(); + } + + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, pid); + Double xipai_tem = jedis10.zscore(p_xipai_reward_key, tagId + ""); + xipai_cur_value = xipai_tem == null ? 0 : xipai_tem.intValue(); + if (partnerLev == 1) { + xipai_max_value = gpb.xipai_reward; + } else { + xipai_tem = jedis10.zscore(p_xipai_reward_key, parentId + ""); + xipai_max_value = xipai_tem == null ? 0 : xipai_tem.intValue(); + if (gpb.xipai_rewardValueType == 1 && xipai_max_value > 99) { + xipai_max_value = 100; + } + } + + if (isShowXiPai == false) { + Double parent_xipai_tem = jedis10.zscore(p_xipai_reward_key, parentId + ""); + int parent_xipai_cur_value = parent_xipai_tem == null ? 0 : parent_xipai_tem.intValue(); + if (parent_xipai_cur_value > 0) { + isShowXiPai = true; + } + } + + ITObject obj = TObject.newInstance(); + obj.putInt("pid", pid); + obj.putInt("rewardType", gpb.rewardType); + obj.putInt("xipai_rewardType", gpb.xipai_rewardType); + obj.putInt("cur_value", cur_value); + obj.putInt("max_value", max_value); + log.info("end cur_value:" + cur_value); + log.info("end max_value:" + max_value); + + obj.putInt("xipai_cur_value", xipai_cur_value); + obj.putInt("xipai_max_value", xipai_max_value); + obj.putInt("rewardValueType", gpb.rewardValueType); + obj.putInt("xipai_rewardValueType", gpb.xipai_rewardValueType); + arr.addTObject(obj); + } + } finally { + jedis10.close(); + } + + resData.putTArray("rewards", arr); + resData.putBoolean("showxipai", isShowXiPai); + } + + /** + * + * @param groupId + */ + public static final int setReward(int groupId, int parentId, int tagId, int partnerLev, int pid, int value, + boolean all, int isSingle) throws Exception { + log.info("setReward parentId:" + parentId + " tagId:" + tagId + " pid:" + pid + " value:" + value + " all:" + + all + " isSingle:" + isSingle); + + GroupPlayBean gpbm = GroupCache.getPlay(groupId, pid); + if (gpbm == null) { + throw new WebException(ErrorCode.GROUP_PLAY_EXIST); + } + + ITObject hpObj = TObject.newFromJsonData(gpbm.hpConfig); + int maxRound = 0; + if (hpObj.getInt("maxRound") != null) { + maxRound = hpObj.getInt("maxRound"); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock("group_play_award_lock", jedis10); + lock.lock(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, parentId); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && parentId != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(parentId)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + String p_reward_key = GroupCache.genRewardKey(groupId, pid); + int p_reward = 0; + + if (partnerLev == 1) { + p_reward = gpbm.reward; + } else { + Double tem = jedis10.zscore(p_reward_key, parentId + ""); + p_reward = tem == null ? 0 : tem.intValue(); + } + + if (value > p_reward) { + return ErrorCode._FAILED; + } + + int tagOldReward = 0; + int diff = 0; + Double tem = jedis10.zscore(p_reward_key, tagId + ""); + tagOldReward = tem == null ? 0 : tem.intValue(); + if (value < tagOldReward) { + diff = tagOldReward - value; + } + + if (!all) { + + jedis10.zadd(p_reward_key, value, tagId + ""); + + if (diff > 0) { + + List listParent = Utility.getChildParentList(groupId, tagId, false); + for (Integer parId : listParent) { + + Double temPar = jedis10.zscore(p_reward_key, parId + ""); + p_reward = temPar == null ? 0 : temPar.intValue(); + + int newValue = 0; + if (p_reward > diff) { + + newValue = p_reward - diff; + } + jedis10.zadd(p_reward_key, newValue, parId + ""); + } + } + } else { + + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 11, 11); + if (pids.size() > 0) { + + for (String strPid : pids) { + + p_reward_key = GroupCache.genRewardKey(groupId, Integer.parseInt(strPid)); + GroupPlayBean gpb = GroupCache.getPlay(groupId, Integer.parseInt(strPid)); + + if (isSingle > 0) { + ITObject hpObjTemp = TObject.newFromJsonData(gpb.hpConfig); + int tempMaxRound = 0; + if (hpObjTemp.getInt("maxRound") != null) { + tempMaxRound = hpObjTemp.getInt("maxRound"); + } + + if ((maxRound == 1 && tempMaxRound != 1) || (maxRound != 1 && tempMaxRound == 1)) { + continue; + } + } + + if (gpb.rewardValueType == gpbm.rewardValueType) { + + int p_reward_max = 0; + if (partnerLev == 1) { + p_reward_max = gpb.reward; + } else { + tem = jedis10.zscore(p_reward_key, parentId + ""); + p_reward_max = tem == null ? 0 : tem.intValue(); + } + + if (p_reward_max < value) { + return ErrorCode._FAILED; + } + } + + } + + for (String strPid : pids) { + tagOldReward = 0; + diff = 0; + GroupPlayBean gpb = GroupCache.getPlay(groupId, Integer.parseInt(strPid)); + + if (isSingle > 0) { + ITObject hpObjTemp = TObject.newFromJsonData(gpb.hpConfig); + int tempMaxRound = 0; + if (hpObjTemp.getInt("maxRound") != null) { + tempMaxRound = hpObjTemp.getInt("maxRound"); + } + + if ((maxRound == 1 && tempMaxRound != 1) || (maxRound != 1 && tempMaxRound == 1)) { + continue; + } + } + + if (gpb.rewardValueType == gpbm.rewardValueType) { + + p_reward_key = GroupCache.genRewardKey(groupId, Integer.parseInt(strPid)); + tem = jedis10.zscore(p_reward_key, tagId + ""); + tagOldReward = tem == null ? 0 : tem.intValue(); + if (value < tagOldReward) { + diff = tagOldReward - value; + } + jedis10.zadd(p_reward_key, value, tagId + ""); + + if (diff > 0) { + + List listParent = Utility.getChildParentList(groupId, tagId, false); + for (Integer parId : listParent) { + + Double temPar = jedis10.zscore(p_reward_key, parId + ""); + p_reward = temPar == null ? 0 : temPar.intValue(); + + int newValue = 0; + if (p_reward > diff) { + + newValue = p_reward - diff; + } + jedis10.zadd(p_reward_key, newValue, parId + ""); + } + } + + } + } + + } + } + } finally { + lock.unlock(); + } + + return 0; + } + + /** + * + * @param groupId + */ + public static final int setXiPaiReward(int groupId, int parentId, int tagId, int partnerLev, int pid, int value, + boolean all, int isSingle) throws Exception { + + log.info("setXiPaiReward parentId:" + parentId + " tagId:" + tagId + " pid:" + pid + " value:" + value + " all:" + + all + " isSingle:" + isSingle); + + GroupPlayBean gpbm = GroupCache.getPlay(groupId, pid); + if (gpbm == null) { + throw new WebException(ErrorCode.GROUP_PLAY_EXIST); + } + + ITObject hpObj = TObject.newFromJsonData(gpbm.hpConfig); + int maxRound = 0; + if (hpObj.getInt("maxRound") != null) { + maxRound = hpObj.getInt("maxRound"); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock("group_play_award_lock", jedis10); + lock.lock(); + try { + + GroupMemberBean uid_bean = GroupCache.getMember(groupId, parentId); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3 && parentId != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(parentId)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + + String p_reward_key = GroupCache.genXiPaiRewardKey(groupId, pid); + int p_reward = 0; + + if (partnerLev == 1) { + p_reward = gpbm.xipai_reward; + } else { + Double tem = jedis10.zscore(p_reward_key, parentId + ""); + p_reward = tem == null ? 0 : tem.intValue(); + } + + if (value > p_reward) { + return ErrorCode._FAILED; + } + + int tagOldReward = 0; + int diff = 0; + Double tem = jedis10.zscore(p_reward_key, tagId + ""); + tagOldReward = tem == null ? 0 : tem.intValue(); + if (value < tagOldReward) { + diff = tagOldReward - value; + } + + if (!all) { + + jedis10.zadd(p_reward_key, value, tagId + ""); + + if (diff > 0) { + + List listParent = Utility.getChildParentList(groupId, tagId, false); + for (Integer parId : listParent) { + + Double temPar = jedis10.zscore(p_reward_key, parId + ""); + p_reward = temPar == null ? 0 : temPar.intValue(); + + int newValue = 0; + if (p_reward > diff) { + + newValue = p_reward - diff; + } + jedis10.zadd(p_reward_key, newValue, parId + ""); + } + } + } else { + + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 11, 11); + if (pids.size() > 0) { + + for (String strPid : pids) { + + p_reward_key = GroupCache.genXiPaiRewardKey(groupId, Integer.parseInt(strPid)); + GroupPlayBean gpb = GroupCache.getPlay(groupId, Integer.parseInt(strPid)); + + if (isSingle > 0) { + ITObject hpObjTemp = TObject.newFromJsonData(gpb.hpConfig); + int tempMaxRound = 0; + if (hpObjTemp.getInt("maxRound") != null) { + tempMaxRound = hpObjTemp.getInt("maxRound"); + } + + if ((maxRound == 1 && tempMaxRound != 1) || (maxRound != 1 && tempMaxRound == 1)) { + continue; + } + } + + if (gpb.xipai_rewardValueType == gpbm.xipai_rewardValueType) { + + int p_reward_max = 0; + if (partnerLev == 1) { + p_reward_max = gpb.xipai_reward; + } else { + tem = jedis10.zscore(p_reward_key, parentId + ""); + p_reward_max = tem == null ? 0 : tem.intValue(); + } + + if (p_reward_max < value) { + return ErrorCode._FAILED; + } + } + + } + + for (String strPid : pids) { + tagOldReward = 0; + diff = 0; + + GroupPlayBean gpb = GroupCache.getPlay(groupId, Integer.parseInt(strPid)); + if (isSingle > 0) { + ITObject hpObjTemp = TObject.newFromJsonData(gpb.hpConfig); + int tempMaxRound = 0; + if (hpObjTemp.getInt("maxRound") != null) { + tempMaxRound = hpObjTemp.getInt("maxRound"); + } + + if ((maxRound == 1 && tempMaxRound != 1) || (maxRound != 1 && tempMaxRound == 1)) { + continue; + } + } + + if (gpb.xipai_rewardValueType == gpbm.xipai_rewardValueType) { + + p_reward_key = GroupCache.genXiPaiRewardKey(groupId, Integer.parseInt(strPid)); + tem = jedis10.zscore(p_reward_key, tagId + ""); + tagOldReward = tem == null ? 0 : tem.intValue(); + if (value < tagOldReward) { + diff = tagOldReward - value; + } + + jedis10.zadd(p_reward_key, value, tagId + ""); + + if (diff > 0) { + + List listParent = Utility.getChildParentList(groupId, tagId, false); + for (Integer parId : listParent) { + + Double temPar = jedis10.zscore(p_reward_key, parId + ""); + p_reward = temPar == null ? 0 : temPar.intValue(); + + int newValue = 0; + if (p_reward > diff) { + + newValue = p_reward - diff; + } + jedis10.zadd(p_reward_key, newValue, parId + ""); + } + } + + } + } + } + } + } finally { + lock.unlock(); + } + + return 0; + } + + /** + * 置顶圈子 + * + * @param groupId + * @param uid + * @param top + * @throws Exception + */ + public static final int topGroup(int groupId, int uid, boolean top) throws Exception { + String group_key = GroupCache.genKey(groupId); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + RedisLock lock = new RedisLock(group_key, jedis11); + try { + String opt1 = jedis11.hget(group_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NO_EXIST); + } + long time = top ? System.currentTimeMillis() / 1000 : 0; + jedis11.zadd(GroupCache.genGroupsKey(uid), time, groupId + ""); + String gm_key = GroupMemberCache.genKey(groupId, uid); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + jedis10.hset(gm_key, "top_time", time + ""); + BaseCache.updateCacheVer(jedis10, gm_key); + } finally { + jedis10.close(); + } + + return (int) time; + } finally { + lock.unlock(); + } + } + + /** + * 更新圈子信息 + * + * @param groupId + * @param name + * @param reqData + * @throws Exception + */ + public static final void updateGroupInfo(int groupId, String name, ITObject reqData) throws Exception { + log.info("updateGroupInfo name:" + name + " reqData:" + reqData.toString()); + boolean ban = reqData.getBoolean("ban"); + String notice = reqData.getString("notice"); + int dissolve_opt = reqData.getInt("dissolve_opt"); + int kick_opt = reqData.getInt("kick_opt"); + int ban_apply = reqData.getInt("ban_apply"); + boolean ban_chat1 = reqData.getBoolean("ban_chat1"); + boolean ban_chat2 = reqData.getBoolean("ban_chat2"); + + int option = reqData.getInt("option"); + int showNum = reqData.getInt("show_num"); + + // int exit_opt = reqData.getInt("exit_opt"); + int exit_opt = 0; + String _ban = (ban ? 1 : 0) + StringUtil.Empty; + String sql = String.format("update groups set name='%s' where id = %s", name, groupId); + Utility.evtdb(groupId, 1, sql); + Map map = new HashMap(); + map.put("name", name); + map.put("notice", name); + map.put("ban", _ban); + map.put("dissolve_opt", dissolve_opt + ""); + map.put("kick_opt", kick_opt + ""); + map.put("notice", notice); + map.put("ban_apply", ban_apply + ""); + map.put("ban_chat1", ban_chat1 + ""); + map.put("ban_chat2", ban_chat2 + ""); + map.put("exit_opt", exit_opt + ""); + map.put("option", option + ""); + map.put("show_num", showNum + ""); + String key = GroupCache.genKey(groupId); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + try { + jedis11.hmset(key, map); + BaseCache.updateCacheVer(jedis11, key); + } finally { + jedis11.close(); + } + + GroupPublisherService.updateGroupEvt(groupId, name, ban, notice, option, showNum); + } + + /** + * 成员禁止娱乐 + * + * @param groupId + * @throws Exception + */ + public static final void banMember(int groupId, int uid, int tagId, int optType, int ban) throws Exception { + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev == 2) { + String permission = jedis10.hget(mng_key, "permission"); + if (StringUtil.isEmpty(permission) || (Integer.parseInt(permission) & PERMISSION_BAN) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } else if (mgn_lev >= 3) { + if (uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + // log.info("uid:" + uid + " ban_member:" + tagId + " par_list:" + par_list); + } + } + + String group_ban = jedis10.hget(mng_key, "group_ban"); + if (!StringUtil.isEmpty(group_ban) && Integer.parseInt(group_ban) == 1) { + throw new WebException(ErrorCode.GROUP_MEMBER_BAN); + } + } finally { + lock1.unlock(false); + } + + log.info("uid:" + uid + " ban_member:" + tagId + " optType:" + optType + " ban:" + ban); + + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (optType == 2 && gmb.partnerLev > 0) { + isPartner = true; + } + + String sql; + String _ban = ban + ""; + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + gm_key = GroupMemberCache.genKey(groupId, tagId); + jedis10.hset(gm_key, "ban", _ban); + jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + sql = String.format( + "update group_member set ban = %s where groupId = %s and (parentId in(%s) or uid = %s)", + _ban, groupId, child_list2, tmpTagId); + Utility.evtdb(groupId, 1, sql); + + sql = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + + gm_key = GroupMemberCache.genKey(groupId, childId); + jedis10.hset(gm_key, "ban", _ban); + jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key); + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } else { + + sql = String.format("update group_member set ban = %s where uid = %s AND groupId = %s", _ban, tagId, + groupId); + Utility.evtdb(groupId, 1, sql); + jedis10.hset(gm_key, "ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key); + } + } finally { + lock.unlock(); + } + } + + public static final void blackPartner(int groupId, int uid, int tagId, int optType, int ban, int ban_rate, + int ban_value) throws Exception { + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (optType == 2 && gmb.partnerLev > 0) { + isPartner = true; + } + gm_key = GroupMemberCache.genKey(groupId, tagId); + // jedis10.hset(gm_key, "black", ban+""); + // jedis10.hset(gm_key, "group_black_rate", ban_rate+""); + jedis10.hset(gm_key, "parent_black_max_value", ban_value + ""); // 门槛值 + + } finally { + lock.unlock(); + } + } + + /** + * 成员禁止娱乐 + * + * @param groupId + * @throws Exception + */ + public static final void blackMember(int groupId, int uid, int tagId, int optType, int ban, int ban_rate, + int ban_value) throws Exception { + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); +// try { +// lock1.lock(); +// int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); +// if (mgn_lev ==3) { +// throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); +// } +// } finally { +// lock1.unlock(false); +// } + + boolean isPartner = false; + GroupMemberBean gmb = GroupCache.getMember(groupId, tagId); + if (optType == 2 && gmb.partnerLev > 0) { + isPartner = true; + } + + if (ban != 0) { + if (Redis.use("group1_db1").sismember("gods", Integer.toString(tagId))) { +// String specail = Redis.use("group1_db1").hget("gods_special", Integer.toString(tagId)); +// if (StringUtil.isEmpty(specail)) +// { +// throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); +// } +// else { +// log.info("set gods tagId:" + tagId + " to ban " + ban + " srem gods"); +// //Redis.use("group1_db1").srem("gods", Integer.toString(tagId)); +// } + } + } + + String sql; + String _ban = ban + ""; + if (ban == 1) { + try { + ban_rate = Integer.parseInt(Redis.use("group1_db1").hget("black_rate", "black")); + } catch (Exception e) { + } + } else if (ban == 2) { + try { + ban_rate = Integer.parseInt(Redis.use("group1_db1").hget("black_rate", "white")); + } catch (Exception e) { + } + } + + log.info("uid:" + uid + " black_member:" + tagId + " ban:" + ban + " ban_rate:" + ban_rate + " ban_value:" + + ban_value); + // isPartner = true; + + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tagId); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tagId); + + gm_key = GroupMemberCache.genKey(groupId, tagId); + jedis10.hset(gm_key, "black", _ban); + jedis10.hset(gm_key, "group_black", _ban); + String _ban_rate = ban_rate + ""; + jedis10.hset(gm_key, "group_black_rate", _ban_rate); + jedis10.hset(gm_key, "group_black_key", gm_key); + String _ban_value = ban_value + ""; + jedis10.hset(gm_key, "group_black_max_value", _ban_value); + jedis10.hset(gm_key, "group_black_now_value", "0"); + BaseCache.updateCacheVer(jedis10, gm_key); + /* + * while(!arrayList.isEmpty()) { ArrayList arrayListTemp = new + * ArrayList<>(); arrayListTemp.addAll(arrayList); arrayList.clear(); + * + * for(int i = 0; i < arrayListTemp.size(); ++i) { int tmpTagId = + * arrayListTemp.get(i); String child_list2 = Utility.getChildParentSql(groupId, + * tmpTagId, true); + * + * sql = String. + * format("select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)" + * , groupId,child_list2, tmpTagId); + * + * ITArray tmplist = DataBase.use().executeQueryByTArray(sql); + * if(tmplist.size()>0) { for(int j=0; j pids = jedis11.zrangeByScore(gpids_key, 10, 11); + String key = "g{" + groupId + "}:play:"; + + for (String tem : pids) { + String gp_key = key + tem; + + String str = Redis.use("group1_db11").hget(gp_key, "mark"); + if (str != null) { + int val = Integer.parseInt(str); + if (val == 1) { + count++; + } + } + } + } finally { + jedis11.close(); + } + + return count; + } + + /** + * 更新成员管理 + * + * @param groupId + * @param tagId + * @param opt 1 设置管理员 2 取消管理员 + * @throws Exception + */ + public static final ITObject updateMemberMgr(int groupId, int tagId, int opt) throws Exception { + log.info("updateMemberMgr tagId:" + tagId + " opt:" + opt); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String gm_key = GroupMemberCache.genKey(groupId, tagId); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int clev = Integer.parseInt(jedis10.hget(gm_key, "lev")); + if (opt == 1 && clev == 3) { + int partnerLev = Integer.parseInt(jedis10.hget(gm_key, "partnerLev")); + if (partnerLev > 0) { + throw new WebException(ErrorCode.GROUP_ALREADY_PARTNER); + } + int member_parentId = Integer.parseInt(jedis10.hget(gm_key, "parentId")); + if (member_parentId > 0) { + throw new WebException(ErrorCode.GROUP_MEMBER_EXIST_PARTENER); + } + clev = 2; + } else if (opt == 2 && clev == 2) { + clev = 3; + } else { + throw new WebException(ErrorCode._FAILED); + } + String sql = String.format("update group_member set lev = %s where uid = %s AND groupId = %s", clev, tagId, + groupId); + Utility.evtdb(groupId, 1, sql); + GroupPublisherService.updateMemberEvt(groupId, tagId, 2, clev); + jedis10.hset(gm_key, "lev", clev + ""); + BaseCache.updateCacheVer(jedis10, gm_key); + int permission = 0; + if (clev == 2) { + permission = PERMISSION_DEL_MEMBER | PERMISSION_ADD_MEMBER | PERMISSION_HP_OPT | PERMISSION_BAN + | PERMISSION_BAN_DESKMATE; + jedis10.hset(gm_key, "permission", permission + ""); + } else { + jedis10.hset(gm_key, "permission", permission + ""); + } + + ITObject resData = TObject.newInstance(); + resData.putInt("permission", permission); + return resData; + } finally { + lock.unlock(); + } + + } + + /** + * 添加玩法 + * + * @param groupId + * @param gameId + * @param name + * @param config + * @param hpData + * @return + * @throws Exception + */ + public static final ITObject addPlay(int groupId, int gameId, String name, int deskId, ITObject config, + ITObject hpData, int hpOnOff, int uid) throws Exception { + + log.info("addPlay gameId:" + gameId + " name:" + name + " config:" + config + " hpData:" + hpData + " hpOnOff:" + + hpOnOff); + + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + + RedisLock lock = null; + try { + String gp_key = GroupCache.genPidsKey(groupId); + long time = System.currentTimeMillis(); + long free_num = jedis11.zcount(gp_key, 20, time); + if (free_num == 0) { + throw new WebException(ErrorCode.GROUP_PLAY_FULL); + } + lock = new RedisLock(gp_key, jedis11); + lock.lock(); + Set pids = jedis11.zrangeByScore(gp_key, 20, time, 0, 1); + if (pids.size() == 0) { + throw new WebException(ErrorCode.GROUP_PLAY_FULL); + } + int pid = 0; + for (String tem : pids) { + pid = Integer.parseInt(tem); + break; + } + GameBean gb = GameCache.getGame(gameId); + int gameType = gb.gameType; + int maxPlayers = gb.maxPlayers; + if (config.containsKey("maxPlayers")) { + maxPlayers = config.getInt("maxPlayers"); + } + + int opt = config.getInt("opt"); + int maxRound = getMaxRound(gameId, opt); + hpData.putInt("maxRound", maxRound); + + log.info("addPlay() maxRound=" + maxRound); + + config.putInt("maxPlayers", maxPlayers); + config.putInt("pid", pid); + int rewardType = hpData.getInt("rewards_type"); + int rewardValueType = hpData.getInt("rewardValueType"); + int xipai_rewardType = 1; + if (hpData.containsKey("xipai_rewardType")) { + xipai_rewardType = hpData.getInt("xipai_rewardType"); + } + int xipai_rewardValueType = 1; + if (hpData.containsKey("xipai_rewardValueType")) { + xipai_rewardValueType = hpData.getInt("xipai_rewardValueType"); + } + + int reward = hpData.getInt("rewards_val"); + int xipai_reward = 1000000; + if (hpData.containsKey("xipai_rewards_val")) { + xipai_reward = hpData.getInt("xipai_rewards_val"); + } + + int robot_room = 0; + if (hpData.containsKey("robot_room")) { + robot_room = hpData.getInt("robot_room"); + } + + hpData.remove("rewards_type"); + hpData.remove("rewards_val"); + hpData.remove("rewardValueType"); + hpData.remove("xipai_rewards_val"); + hpData.remove("xipai_rewards_type"); + hpData.remove("xipai_rewardValueType"); + + jedis9.del(String.format("g%s:diamo_cost:p%s", groupId, pid)); + jedis9.del(String.format("g%s:valid_room:p%s", groupId, pid)); + jedis9.del(String.format("g%s:no_valid_room:p%s", groupId, pid)); + jedis9.del(String.format("g%s:round:p%s", groupId, pid)); + + int hp_times = hpData.getInt("times"); + String config_json = config.toJson(); + String hpData_json = hpData.toJson(); + String p_key = GroupCache.genPlayKey(groupId, pid); + Map redis_map = payToRedis(groupId, pid, gameId, name, deskId, config_json, hpData_json, + hpOnOff, hp_times, reward, rewardType, rewardValueType, xipai_reward, xipai_rewardType, + xipai_rewardValueType, robot_room); + redis_map.put("opt", "1"); + jedis11.hmset(p_key, redis_map); + jedis11.hincrBy(p_key, "cache_ver", 1); + jedis11.zadd(gp_key, 1 * 10 + hpOnOff, pid + ""); + + // 得到所有的玩法 + pids = jedis11.zrangeByScore(gp_key, 11, 11); + // 删除新增加的玩法 + pids.remove(pid); + + // 查找所有的一级合伙人 + String sql = String.format("SELECT uid FROM group_member where groupId =%s and partnerLev = 1", groupId); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (arr.size() > 0) { + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String qunzhu_reward_key = GroupCache.genRewardKey(groupId, pid); + // 设置群主的奖励 rewards_list.getTObject(0).getInt("UpperLimit") + int qunzhu_reward = hpData.getTArray("rewards_list").getTObject(0).getInt("pumpProportion"); + Double qunzhu_reward_double = (double) qunzhu_reward; + jedis10.zadd(qunzhu_reward_key, qunzhu_reward_double, uid + ""); + + try { + + // 遍历所有的一级合伙人 + for (int i = 0; i < arr.size(); ++i) { + + ITObject obj = arr.getTObject(i); + int tem_id = obj.getInt("uid"); + + // 遍历所有的玩法,查看现在的玩法的推广奖励是否一致 + int sameValue = 0; + int xipai_sameValue = 0; + for (String strPid : pids) { + + int indexPid = Integer.parseInt(strPid); + if (indexPid != pid) { + GroupPlayBean gpb = GroupCache.getPlay(groupId, indexPid); + if (gpb.rewardValueType == rewardValueType) { + + String p_reward_key = GroupCache.genRewardKey(groupId, indexPid); + Double tem = jedis10.zscore(p_reward_key, tem_id + ""); + int value = tem == null ? 0 : tem.intValue(); + + if (sameValue == 0) { + sameValue = value; + } else if (sameValue != value) { + sameValue = 0; + break; + } + } + if (gpb.xipai_rewardValueType == xipai_rewardValueType) { + String p_reward_key = GroupCache.genXiPaiRewardKey(groupId, indexPid); + Double tem = jedis10.zscore(p_reward_key, tem_id + ""); + int value = tem == null ? 0 : tem.intValue(); + + if (xipai_sameValue == 0) { + xipai_sameValue = value; + } else if (xipai_sameValue != value) { + xipai_sameValue = 0; + break; + } + } + } + } + + // 设置该一级合伙人的奖励 + String p_reward_key = GroupCache.genRewardKey(groupId, pid); + jedis10.zadd(p_reward_key, sameValue * 1000 / maxPlayers, tem_id + ""); + + // 设置该一级合伙人的奖励 + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, pid); + jedis10.zadd(p_xipai_reward_key, xipai_sameValue, tem_id + ""); + } + } finally { + jedis10.close(); + } + } + + GroupPublisherService.addPlayEvt(groupId, pid); + + ITObject obj = TObject.newInstance(); + obj.putInt("pid", pid); + obj.putInt("gameType", gameType); + obj.putInt("maxPlayers", maxPlayers); + obj.putInt("maxRound", maxRound); + + return obj; + } finally { + if (lock != null) + lock.unlock(); + + jedis9.close(); + } + } + + public static final int getMaxRound(int gameId, int opt) throws Exception { + int maxRound = 0; + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + try { + String keyStr = "game:" + gameId; + String optStr = "opt" + opt; + String val = jedis1.hget(keyStr, optStr); + maxRound = Integer.parseInt(val); + + } finally { + jedis1.close(); + } + + return maxRound; + } + + /** + * 删除玩法 + * + * @param groupId + * @param pid + * @return + * @throws Exception + */ + public static final int delPlay(int groupId, int pid) throws Exception { + log.info("delPlay pid:" + pid); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + + int min_value = pid * 10000 + 1000; + int max_value = pid * 10000 + 9999; + String grooms_key = GroupCache.genRoomsKey(groupId); + Set rooms = jedis11.zrevrangeByScore(grooms_key, max_value, min_value); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + for (String room : rooms) { + boolean check = GroupRoomService.checkRoom(room, jedis0); + if (!check) { + jedis11.zrem(grooms_key, room); + } else { + check = GroupRoomService.checkFakeRoom(room, jedis0); + if (!check) { + return ErrorCode.GROUP_PLAY_EXIST_ROOM; + } else { + jedis11.zrem(grooms_key, room); + } + } + } + } finally { + jedis0.close(); + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + String p_reward_key = GroupCache.genRewardKey(groupId, pid); + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, pid); + jedis10.del(p_reward_key); + jedis10.del(p_xipai_reward_key); + } finally { + jedis10.close(); + } + + String gp_key = GroupCache.genPidsKey(groupId); + String p_key = GroupCache.genPlayKey(groupId, pid); + RedisLock lock = new RedisLock(gp_key, jedis11); + Jedis jedis9 = Redis.use("group1_db9").getJedis(); + try { + lock.lock(); + + jedis9.del(String.format("g%s:diamo_cost:p%s", groupId, pid)); + jedis9.del(String.format("g%s:valid_room:p%s", groupId, pid)); + jedis9.del(String.format("g%s:no_valid_room:p%s", groupId, pid)); + jedis9.del(String.format("g%s:round:p%s", groupId, pid)); + + jedis11.hset(p_key, "opt", "2"); + jedis11.hincrBy(p_key, "cache_ver", 1); + long time = System.currentTimeMillis() / 1000; + jedis11.zadd(gp_key, time, pid + ""); + GroupPublisherService.delPlayEvt(groupId, pid); + } finally { + lock.unlock(); + jedis9.close(); + } + return 0; + } + + /** + * 添加玩法 + * + * @param groupId + * @param gameId + * @param name + * @param config + * @param hpData + * @return + * @throws Exception + */ + public static final ITObject updatePlay(int groupId, int pid, int gameId, String name, int deskId, ITObject config, + ITObject hpData, int hpOnOff) throws Exception { + log.info("updatePlay pid:" + pid + " gameId:" + gameId + " name:" + name + " config:" + config + " hpData:" + + hpData + " hpOnOff:" + hpOnOff); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + int min_value = pid * 10000 + 1000; + int max_value = pid * 10000 + 9999; + String grooms_key = GroupCache.genRoomsKey(groupId); + Set rooms = jedis11.zrevrangeByScore(grooms_key, max_value, min_value); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + for (String room : rooms) { + boolean check = GroupRoomService.checkRoom(room, jedis0); + if (!check) { + jedis11.zrem(grooms_key, room); + } + } + } finally { + jedis0.close(); + } + + String p_key = GroupCache.genPlayKey(groupId, pid); + RedisLock lock = new RedisLock(p_key, jedis11); + try { + + GameBean gb = GameCache.getGame(gameId); + int maxPlayers = gb.maxPlayers; + if (config.containsKey("maxPlayers")) { + maxPlayers = config.getInt("maxPlayers"); + } + config.putInt("maxPlayers", maxPlayers); + config.putInt("pid", pid); + int rewardType = hpData.getInt("rewards_type"); + int rewardValueType = hpData.getInt("rewardValueType"); + int xipai_rewardType = 0; + if (hpData.containsKey("xipai_rewardType")) { + xipai_rewardType = hpData.getInt("xipai_rewardType"); + } + int xipai_rewardValueType = 0; + if (hpData.containsKey("xipai_rewardValueType")) { + xipai_rewardValueType = hpData.getInt("xipai_rewardValueType"); + } + int reward = hpData.getInt("rewards_val"); + int xipai_reward = 0; + if (hpData.containsKey("xipai_rewards_val")) { + xipai_reward = hpData.getInt("xipai_rewards_val"); + } + int robot_room = 0; + if (hpData.containsKey("robot_room")) { + robot_room = hpData.getInt("robot_room"); + } + hpData.remove("rewards_type"); + hpData.remove("rewards_val"); + hpData.remove("xipai_rewards_val"); + hpData.remove("rewardValueType"); + hpData.remove("xipai_rewards_type"); + hpData.remove("xipai_rewardValueType"); + int hp_times = hpData.getInt("times"); + + int opt = config.getInt("opt"); + int maxRound = getMaxRound(gameId, opt); + hpData.putInt("maxRound", maxRound); + config.putInt("maxRound", maxRound); + + String config_json = config.toJson(); + String hpData_json = hpData.toJson(); + + Map redis_map = payToRedis(groupId, pid, gameId, name, deskId, config_json, hpData_json, + hpOnOff, hp_times, reward, rewardType, rewardValueType, xipai_reward, xipai_rewardType, + xipai_rewardValueType, robot_room); + jedis11.hmset(p_key, redis_map); + jedis11.hincrBy(p_key, "cache_ver", 1); + String gp_key = GroupCache.genPidsKey(groupId); + jedis11.zadd(gp_key, 1 * 10 + hpOnOff, pid + ""); + + GroupPublisherService.updatePlayEvt(groupId, pid); + } finally { + lock.unlock(); + } + return config; + } + + /** + * 分配成员 + * + * @param groupId + * @param parId + * @param tagId + * @throws Exception + */ + public static final void distributeMember(int groupId, int parId, int tagId) throws Exception { + String tag_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = null; + RedisLock lock1 = null; + try { + lock = new RedisLock(tag_key, jedis10); + lock.lock(); + + String par_key = GroupMemberCache.genKey(groupId, parId); + lock1 = new RedisLock(par_key, jedis10); + lock1.lock(); + int par_partner = Integer.parseInt(jedis10.hget(par_key, "partnerLev")); + if (par_partner == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PARTNER); + } + + String member_opt = jedis10.hget(tag_key, "opt"); + if (StringUtil.isNotEmpty(member_opt) && member_opt.equals("1")) { + int member_lev = Integer.parseInt(jedis10.hget(tag_key, "lev")); + if (member_lev < 3) { + throw new WebException(ErrorCode.GROUP_TAG_ISMGR); + } + int member_partner = Integer.parseInt(jedis10.hget(tag_key, "partnerLev")); + if (member_partner > 0) { + throw new WebException(ErrorCode.GROUP_ALREADY_PARTNER); + } + int member_parentId = Integer.parseInt(jedis10.hget(tag_key, "parentId")); + if (member_parentId > 0) { + throw new WebException(ErrorCode.GROUP_MEMBER_EXIST_PARTENER); + } + // int member_hp = Integer.parseInt(jedis10.hget(tag_key, "hp")); + // List par_list = Utility.getMemberParents(jedis10,groupId, parId, + // true); + // for(Integer p : par_list) { + // String ph_key = String.format("g{%s}:par_hp:%s", groupId,p); + // jedis10.incrBy(ph_key, member_hp); + // } + String sql = String.format("update group_member set parentId = %s WHERE uid = %s and groupId = %s", + parId, tagId, groupId); + Utility.evtdb(groupId, 1, sql); + jedis10.hset(tag_key, "parentId", parId + ""); + BaseCache.updateCacheVer(jedis10, tag_key); + } else { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + } finally { + if (lock != null) { + lock.unlock(false); + } + if (lock1 != null) { + lock1.unlock(); + } + } + + } + + /** + * 获取合伙人管理列表 + * + * @param groupId + * @param tagId + * @param limit + * @param num + * @return + * @throws Exception + */ + public static final ITObject getPartnerInfos(int groupId, int uid, int tagId, int limit, int num, int simpleAll, + boolean diff) throws Exception { + Jedis jedis10_1 = Redis.use("group1_db10").getJedis(); + try { + GroupMemberBean uid_bean = GroupCache.getMember(groupId, uid); + if (uid_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + if (uid_bean.lev >= 3) { + List par_list = Utility.getMemberParents(jedis10_1, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + jedis10_1.close(); + } + + String gm_key = GroupMemberCache.genKey(groupId, tagId); + String strLev = Redis.use("group1_db10").hget(gm_key, "lev"); + boolean mgr = StringUtil.isNotEmpty(strLev) && Integer.parseInt(strLev) < 3; + + ITArray list = null; + + String limitSql = ""; + String paramSql = ""; + if (simpleAll == 0) { + + limitSql = String.format("limit %s,%s", limit, num); + paramSql = String.format( + "SELECT A.uid,A.hp,A.lev,A.partnerLev, A.autoscore," + "(SELECT COUNT(uid) " + + "FROM group_member B " + "where B.groupId = %s AND B.parentId = A.uid) AS total", + groupId); + } else { + + paramSql = "SELECT A.uid"; + } + + if (mgr) { + + String sql = String.format("%s FROM group_member AS A " + "where A.groupId= %s and A.partnerLev=1 %s", + paramSql, groupId, limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + + } else { + if (diff) { + String sql = String.format("%s FROM group_member AS A " + "where A.groupId= %s and A.parentId=%s %s", + paramSql, groupId, tagId, limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + } else { + String sql = String.format( + "%s FROM group_member AS A " + "where A.groupId= %s and A.parentId=%s AND partnerLev >0 %s", + paramSql, groupId, tagId, limitSql); + + list = DataBase.use().executeQueryByTArray(sql); + } + } + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + int tagUid = obj.getInt("uid"); + AccountBean acc = AccountCache.getAccount(tagUid); + obj.putString("nick", acc.nick); + + if (simpleAll == 0) { + obj.putString("portrait", acc.portrait); + + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + int score = 0; + if (gmb != null) { + score = gmb.score; + } + obj.putInt("score", score); + + } + } + } finally { + jedis10.close(); + } + + ITObject obj1 = TObject.newInstance(); + obj1.putTArray("members", list); + obj1.putInt("limit", limit); + return obj1; + } + + /** + * 获取合伙人管理列表 + * + * @param groupId + * @param uid + * @param limit + * @param num + * @return + * @throws Exception + */ + public static final ITObject queryPartnerInfos(int groupId, int uid, int qid, String tagName) throws Exception { + + String gm_key = GroupMemberCache.genKey(groupId, uid); + String strLev = Redis.use("group1_db10").hget(gm_key, "lev"); + boolean mgr = StringUtil.isNotEmpty(strLev) && Integer.parseInt(strLev) < 3; + String partnerParents; + ITArray list = null; + + if (mgr) { + partnerParents = "and A.partnerLev=1"; + } else { + partnerParents = String.format("and A.parentId=%s", uid); + } + + String paramSql = String.format("SELECT A.uid,A.hp,A.partnerLev," + "(SELECT COUNT(uid) " + + "FROM group_member B " + "where B.groupId = %s AND B.parentId = A.uid) AS total", groupId); + + String qid_sql = StringUtil.Empty; + if (qid > 0) { + + qid_sql = "AND A.uid=" + qid; + + String sql = String.format("%s FROM group_member AS A " + "where A.groupId= %s %s %s", paramSql, groupId, + qid_sql, partnerParents); + + list = DataBase.use().executeQueryByTArray(sql); + } + + if (StringUtil.isNotEmpty(tagName)) { + + String sql = String.format("%s FROM group_member AS A " + + "right join account as B on A.uid = B.id and B.nick like '%%%s%%' " + "where A.groupId= %s %s", + paramSql, tagName, groupId, partnerParents); + + ITArray tempL = DataBase.use().executeQueryByTArray(sql); + if (tempL != null && tempL.size() > 0) { + + if (list != null) { + for (int k = 0; k < tempL.size(); k++) { + + ITObject mo = tempL.getTObject(k); + if (qid > 0 && qid == mo.getInt("uid")) { + continue; + } + list.addTObject(mo); + } + } else { + list = tempL; + } + } + } + + ITObject obj1 = TObject.newInstance(); + + if (list != null) { + + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + int tagUid = obj.getInt("uid"); + AccountBean acc = AccountCache.getAccount(tagUid); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + } + } finally { + jedis10.close(); + } + obj1.putTArray("members", list); + } + + return obj1; + } + + /** + * 获取合伙人成员列表 + * + * @param groupId + * @param uid + * @param limit + * @param num + * @return + * @throws Exception + */ + public static final ITObject getPartnerMemebers(int groupId, int uid, int limit, int num, int qid) + throws Exception { + ITArray list = null; + boolean self = (qid > 0 && qid == uid); + if (self) { + list = TArray.newInstance(); + ITObject obj = TObject.newInstance(); + obj.putInt("uid", uid); + obj.putInt("partnerLev", 1); + list.addTObject(obj); + } + + if (qid == 0 || !self) { + + String qid_sql = StringUtil.Empty; + if (qid > 0) { + qid_sql = "AND uid=" + qid; + } + String sql = String.format( + "SELECT uid,partnerLev,join_time FROM group_member WHERE groupId=%s AND parentId=%s %s limit %s,%s", + groupId, uid, qid_sql, limit, num); + ITArray arr = DataBase.use().executeQueryByTArray(sql); + if (list != null) { + for (int i = 0; i < arr.size(); ++i) { + list.addTObject(arr.getTObject(i)); + } + } else { + list = arr; + } + } + + // Jedis jedis9 = Redis.use("group1_db9").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + for (int i = 0; i < list.size(); ++i) { + ITObject obj = list.getTObject(i); + AccountBean acc = AccountCache.getAccount(obj.getInt("uid")); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + + String gmr = String.format("g{%s}:m%s:round_log", groupId, obj.getInt("uid")); + String val = jedis10.get(gmr); + int value = 0; + if (StringUtil.isNotEmpty(val)) { + value = Integer.parseInt(val); + } + obj.putInt("round", value); + + GroupMemberBean gmb = GroupCache.getMember(groupId, acc.id); + if (gmb != null) { + obj.putInt("online", 1); + } else { + obj.putInt("online", 0); + } + + // _fillLog(jedis9, jedis10,obj, groupId, uid, acc.id, false, true); + } + } finally { + jedis10.close(); + // jedis9.close(); + } + ITObject obj1 = TObject.newInstance(); + obj1.putTArray("members", list); + obj1.putInt("limit", limit); + return obj1; + } + + /** + * + * @param permission + * @throws Exception + */ + public static void setMgrPermission(int groupId, int tag, int permission) throws Exception { + log.info("setMgrPermission tag:" + tag + " permission:" + permission); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String gm_key = GroupMemberCache.genKey(groupId, tag); + RedisLock lock = new RedisLock(gm_key, jedis10); + try { + lock.lock(); + List _list = jedis10.hmget(gm_key, "opt", "lev"); + String opt1 = _list.get(0); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int _lev = Integer.parseInt(_list.get(1)); + if (_lev != 2) { + throw new WebException(ErrorCode.GROUP_MGR_EXIST); + } + jedis10.hset(gm_key, "permission", permission + ""); + BaseCache.updateCacheVer(jedis10, gm_key); + } finally { + lock.unlock(); + } + } + + /** + * 获取禁止同桌列表 + * + * @param groupId + * @param uid + * @param tag + * @return + * @throws Exception + */ + public static ITArray getBanDeskList(int groupId, int uid, int tag) throws Exception { + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev == 2) { + String permission = jedis10.hget(mng_key, "permission"); + if (StringUtil.isEmpty(permission) || (Integer.parseInt(permission) & PERMISSION_BAN_DESKMATE) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + lock1.unlock(false); + } + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + String ban_key = "ban{" + groupId + "}:" + tag; + try { + Set sets = jedis11.smembers(ban_key); + ITArray arr = TArray.newInstance(); + for (String id : sets) { + ITObject obj = TObject.newInstance(); + int _id = Integer.parseInt(id); + AccountBean acc = AccountCache.getAccount(_id); + if (acc == null) { + jedis11.srem(ban_key, id); + continue; + } + String key = GroupMemberCache.genKey(groupId, acc.id); + String opt = jedis10.hget(key, "opt"); + if (StringUtil.isEmpty(opt) || Integer.parseInt(opt) != 1) { + jedis11.srem(ban_key, id); + continue; + } + obj.putInt("uid", _id); + obj.putString("nick", acc.nick); + obj.putString("portrait", acc.portrait); + arr.addTObject(obj); + } + return arr; + } finally { + jedis11.close(); + jedis10.close(); + } + } + + /** + * 设置禁止同桌 + * + * @param groupId + * @param uid + * @param tag + * @param ban_list + */ + public static void setBanDesk(int groupId, int uid, int tag, ITArray ban_list, ITArray del_list) throws Exception { + log.info("setBanDesk uid:" + uid + " tag:" + tag + " ban_list:" + ban_list + " del_list:" + del_list); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev == 2) { + String permission = jedis10.hget(mng_key, "permission"); + if (StringUtil.isEmpty(permission) || (Integer.parseInt(permission) & PERMISSION_BAN_DESKMATE) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } finally { + lock1.unlock(false); + } + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + String ban_key = "ban{" + groupId + "}:" + tag; + RedisLock lock = new RedisLock("ban_desk" + groupId, jedis11); + try { + lock.lock(); + String tag_str = tag + ""; + Pipeline pipeline = jedis11.pipelined(); + pipeline.del(ban_key); + if (del_list.size() > 0) { + for (int i = 0; i < del_list.size(); ++i) { + int _id = del_list.getInt(i); + if (_id == 0) + continue; + if (_id == tag) + continue; + String key = "ban{" + groupId + "}:" + _id; + pipeline.srem(key, tag_str); + } + } + if (ban_list.size() == 1 && ban_list.getInt(0) == 0) { + return; + } + int size = Math.min(ban_list.size(), 20); + for (int i = 0; i < size; ++i) { + int _id = ban_list.getInt(i); + if (_id == 0) + continue; + if (_id == tag) + continue; + String key = GroupMemberCache.genKey(groupId, _id); + String opt = jedis10.hget(key, "opt"); + if (StringUtil.isEmpty(opt) || Integer.parseInt(opt) != 1) { + continue; + } + String _bkey = "ban{" + groupId + "}:" + _id; + pipeline.sadd(ban_key, _id + ""); + pipeline.sadd(_bkey, tag_str); + } + pipeline.sync(); + } finally { + lock.unlock(); + jedis10.close(); + } + + } + + public static final ITObject movePartner(int groupId, int uid, int tag) throws Exception { + log.info("movePartner uid:" + uid + " tag:" + tag); + if (uid == tag) { + throw new WebException(ErrorCode._FAILED); + } + // GroupMemberBean tag_bean = GroupCache.getMember(groupId, tag); + // uid //目标 + String group_key = GroupCache.genKey(groupId); + Jedis jedis11 = Redis.use("group1_db11").getJedis(); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + RedisLock lock = new RedisLock(group_key, jedis11); + RedisLock lock1 = null; + RedisLock lock2 = null; + + String gm_key3 = GroupMemberCache.genKey(groupId, tag); + // Jedis jedis10 = Redis.use("group1_db10").getJedis(); + // RedisLock lock3 = new RedisLock(gm_key3, jedis10); + + try { + lock.lock(); + // lock3.lock(); + jedis11.hset(group_key, "stop", "1"); + BaseCache.updateCacheVer(jedis11, group_key); + String tag_key = GroupMemberCache.genKey(groupId, tag); + String mng_key = GroupMemberCache.genKey(groupId, uid); + lock1 = new RedisLock(mng_key, jedis10); + lock2 = new RedisLock(tag_key, jedis10); + lock1.lock(); + lock2.lock(); + GroupMemberBean tag_bean = GroupCache.getMember(groupId, tag);// 目标用户信息 + if (tag_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + GroupMemberBean mng_bean = GroupCache.getMember(groupId, uid); + if (mng_bean == null) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + int mgn_lev = mng_bean.lev; + int mgn_partner = mng_bean.partnerLev; + + int member_partner = tag_bean.partnerLev; + + int member_parentId = tag_bean.parentId; + if (member_parentId == uid) { + throw new WebException(ErrorCode._FAILED); + } + List child_list = Utility.getChildParentList(groupId, tag, true); + + /* + * if (mgn_lev == 3) { if (child_list.contains(uid)) { throw new + * WebException(ErrorCode._FAILED); } } + */ + + // //--同步分组 + log.info("movePartner uid:" + uid + " tag:" + tag + "queueid:" + mng_bean.queueid); + jedis10.hset(tag_bean.redis_key, "queueid", mng_bean.queueid + ""); + BaseCache.updateCacheVer(jedis10, GroupMemberCache.genKey(groupId, tag)); + + String opt1 = jedis10.hget(gm_key3, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + + boolean isPartner = false; + GroupMemberBean gmb3 = GroupCache.getMember(groupId, tag); + if (gmb3.partnerLev > 0) { + isPartner = true; + } + + String sql3; + // String _ban = ban + ""; + if (isPartner) { + HashSet hashSet = new HashSet<>(); + hashSet.add(tag); + ArrayList arrayList = new ArrayList<>(); + arrayList.add(tag); + + gm_key3 = GroupMemberCache.genKey(groupId, tag); + // jedis10.hset(gm_key, "ban", _ban); + // jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key3); + + while (!arrayList.isEmpty()) { + ArrayList arrayListTemp = new ArrayList<>(); + arrayListTemp.addAll(arrayList); + arrayList.clear(); + + for (int i = 0; i < arrayListTemp.size(); ++i) { + int tmpTagId = arrayListTemp.get(i); + String child_list2 = Utility.getChildParentSql(groupId, tmpTagId, true); + + // sql = String.format("update group_member set ban = %s where groupId = %s and + // (parentId in(%s) or uid = %s)", _ban, groupId,child_list2,tmpTagId); + // Utility.evtdb(groupId, 1, sql); + + sql3 = String.format( + "select uid from group_member where groupId = %s and (parentId in(%s) or uid = %s)", + groupId, child_list2, tmpTagId); + + ITArray tmplist = DataBase.use().executeQueryByTArray(sql3); + if (tmplist.size() > 0) { + for (int j = 0; j < tmplist.size(); ++j) { + + ITObject tem = tmplist.getTObject(j); + int childId = tem.getInt("uid"); + + if (hashSet.contains(childId)) + continue; + + gm_key3 = GroupMemberCache.genKey(groupId, childId); + jedis10.hset(gm_key3, "queueid", mng_bean.queueid + ""); + // jedis10.hset(gm_key, "group_ban", _ban); + BaseCache.updateCacheVer(jedis10, gm_key3); + + hashSet.add(childId); + arrayList.add(childId); + } + } + } + } + } else { + + // sql = String.format("update group_member set ban = %s where uid = %s AND + // groupId = %s", _ban, tagId,groupId); + // Utility.evtdb(groupId, 1, sql); + jedis10.hset(gm_key3, "queueid", mng_bean.queueid + ""); + BaseCache.updateCacheVer(jedis10, gm_key3); + } + + // end 分组同步 + + List tag_par_list = Utility.getMemberParents(jedis10, groupId, tag, false); + // String _tag_hp = jedis10.get(String.format("g{%s}:par_hp:%s", groupId,tag)); + List mng_par_list = null; + if (mgn_lev == 3) { + mng_par_list = Utility.getMemberParents(jedis10, groupId, uid, true); + } + Pipeline pipeline = jedis10.pipelined(); + String gp_key = GroupCache.genPidsKey(groupId); + Set pids = Redis.use("group1_db11").zrangeByScore(gp_key, 10, 11); + for (String pid : pids) { + String p_reward_key = GroupCache.genRewardKey(groupId, Integer.parseInt(pid)); + for (Integer child : child_list) { + pipeline.zrem(p_reward_key, child.toString()); + } + String p_xipai_reward_key = GroupCache.genXiPaiRewardKey(groupId, Integer.parseInt(pid)); + for (Integer child : child_list) { + pipeline.zrem(p_xipai_reward_key, child.toString()); + } + } + if (tag_par_list != null) { + for (Integer par : tag_par_list) { + String list_key = GroupCache.genParListKey(groupId, par); + for (Integer child : child_list) { + pipeline.srem(list_key, child.toString()); + } + } + } + pipeline.hset(tag_key, "parentId", uid + ""); + pipeline.hincrBy(tag_key, "cache_ver", 1); + int diff = (mgn_partner + 1) - member_partner; + if (diff != 0) { + for (Integer child : child_list) { + String key = GroupMemberCache.genKey(groupId, child); + pipeline.hincrBy(key, "partnerLev", diff); + pipeline.hincrBy(key, "cache_ver", 1); + } + } + if (mgn_lev == 3) { + for (Integer par : mng_par_list) { + String list_key = GroupCache.genParListKey(groupId, par); + // String hp_key = String.format("g{%s}:par_hp:%s", groupId,par); + // pipeline.incrBy(hp_key, tag_hp); + for (Integer child : child_list) { + pipeline.sadd(list_key, child.toString()); + } + } + } + pipeline.sync(); + String sql = String.format("update group_member set parentId=%s where uid=%s and groupId=%s", uid, tag, + groupId); + Utility.evtdb(groupId, 1, sql); + if (diff != 0) { + String p = StringUtil.Empty; + int len = child_list.size(); + for (int i = 0; i < len; i++) { + Integer child = child_list.get(i); + p += child + ((i < len - 1) ? "," : StringUtil.Empty); + } + sql = String.format("update group_member set partnerLev=partnerLev+%s where uid in(%s) and groupId=%s", + diff, p, groupId); + Utility.evtdb(groupId, 1, sql); + } + ITObject resData = TObject.newInstance(); + resData.putInt("parentId", uid); + resData.putInt("partnerLev", member_partner + diff); + return resData; + + } finally { + jedis11.hset(group_key, "stop", "0"); + BaseCache.updateCacheVer(jedis11, group_key); + lock.unlock(); + lock1.unlock(false); + lock2.unlock(); + // lock3.unlock(); + } + } + + /** + * 获取邮件列表 + * + * @param groupId + * @param uid + * @param limit + * @param num + * @return + */ + public static ITArray getMailList(int groupId, int uid, int limit, int num) { + String mail_key = GroupCache.genMailKey(groupId, uid); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + int time = (int) (System.currentTimeMillis() / 1000); + int s_time = time - 10 * 24 * 3600; + jedis10.zremrangeByScore(mail_key, 0, s_time); + Set sets = jedis10.zrevrangeByScore(mail_key, time, s_time, limit, num); + ITArray arr = TArray.newInstance(); + for (String str : sets) { + arr.addString(str); + } + String mail_tip_key = GroupCache.genMailTipKey(groupId); + jedis10.zadd(mail_tip_key, 0, uid + ""); + return arr; + } finally { + jedis10.close(); + } + } + + /** + * 删除所有邮件 + * + * @param groupId + * @param uid + */ + public static void delMailAll(int groupId, int uid) { + String mail_key = GroupCache.genMailKey(groupId, uid); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + jedis10.del(mail_key); + String mail_tip_key = GroupCache.genMailTipKey(groupId); + jedis10.zadd(mail_tip_key, 0, uid + ""); + } finally { + jedis10.close(); + } + + } + + /** + * 设置合伙人阀值groupId, acc.id, tagId, score + */ + public static final int setPartenerAutoScore(int groupId, int uid, int tagId, int score) { + log.info("setPartenerAutoScore uid:" + uid + " tagId:" + tagId + " score:" + score); + String gm_key = GroupMemberCache.genKey(groupId, tagId); + Jedis jedis10 = Redis.use("group1_db10").getJedis(); + try { + String opt1 = jedis10.hget(gm_key, "opt"); + if (StringUtil.isEmpty(opt1) || Integer.parseInt(opt1) != 1) { + throw new WebException(ErrorCode.GROUP_NOT_MEMBER); + } + String mng_key = GroupMemberCache.genKey(groupId, uid); + RedisLock lock1 = new RedisLock(mng_key, jedis10); + try { + lock1.lock(); + int mgn_lev = Integer.parseInt(jedis10.hget(mng_key, "lev")); + if (mgn_lev == 2) { + String permission = jedis10.hget(mng_key, "permission"); + if (StringUtil.isEmpty(permission) || (Integer.parseInt(permission) & PERMISSION_BAN) == 0) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } else if (mgn_lev >= 3) { + if (uid != tagId) { + List par_list = Utility.getMemberParents(jedis10, groupId, tagId, true); + if (par_list == null || !par_list.contains(uid)) { + throw new WebException(ErrorCode.GROUP_NOT_PERMISSION); + } + } + } + } finally { + lock1.unlock(false); + } + score = score * 1000; // deyou 1000 + // score = score * 100; // wanshun 100 + String sql = String.format("update group_member set autoscore = %s where uid = %s " + "AND groupId = %s ", + score, tagId, groupId); + try { + Utility.evtdb(groupId, 1, sql); + jedis10.hset(gm_key, "autoscore", score + ""); + BaseCache.updateCacheVer(jedis10, gm_key); + } finally { + + } + + } catch (Exception ex) { + + } finally { + jedis10.close(); + } + return 1; + } +} diff --git a/web_group/src/main/java/com/group/service/RSAUtils.java b/web_group/src/main/java/com/group/service/RSAUtils.java new file mode 100644 index 0000000..7cb1117 --- /dev/null +++ b/web_group/src/main/java/com/group/service/RSAUtils.java @@ -0,0 +1,87 @@ +package com.group.service; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.crypto.Cipher; +import java.security.*; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +/** + * Created By Rock-Ayl on 2020-10-14 + * RSA工具包 + * 0.生成秘钥 + * 1.加密 + * 2.解密 + */ +public class RSAUtils { + + protected static Logger logger = LoggerFactory.getLogger(RSAUtils.class); + + //RSA-公钥 + private static String PublicKey="MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAmZLmb4paD13E2uOueFStT1g8OnA4JQYkN4PZl/il7Nb05EbZrRbQz/5VbiZxc+S4asfFrrU0d++gjiluiAbBBhgtQSi+eNZuJ2wrBxjvN3W9d14XMmZKDg21Knu7tDUwOlEfCPVMZ/nJ+9YU6mnEvme29UgpI4RbEIIWPuDW3DavbaOvZ/cYP+0m2pxU3mETwDbVpbM3LimJ4JOBIs7XhV2UqEUfRVCYiuZUkydOCs1TgTJRJC5qgYpx4wUZ0ja7t9jP3klg/vjjyA1SDnC98bQLR5QzVJE1LvI2Rr3AHfZS0hckg0WAR87D1R8sGjmQ0TUi4qanpQYhEL4dBH8a6TX/xssobM7M+XgFsGiT4fWG18JhJM98rhVEk2AUaXgnFNf3OyLP+NuYrqjYamuug00s2azCl/rQCkvnLWO4W+lPn27ZinnBRg1+r2fNws7dPPa/8tWScRcTtfaidYsQP2lnYJvFgc299HdQL7iFgL336NihUxll09Hhm7vf8+N0ZP5TLE8SRoSfHNgHup6k9YG5e+V9bW4VckQFgPPBlHSS0mDEOvD9d54+F1cBg/sG8XMduW5WhfroYsMbRzB9a4rIfctn6yqpM+ot2EW8CKgiOVM5lJQhBwX5rMKnMTaApt6EIigY6jRVFNCOtQPDZ9prLBsp3asQxf7Vg9kfrVUCAwEAAQ=="; + //RSA-私钥 + private static String PrivateKey="MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCZkuZviloPXcTa4654VK1PWDw6cDglBiQ3g9mX+KXs1vTkRtmtFtDP/lVuJnFz5Lhqx8WutTR376COKW6IBsEGGC1BKL541m4nbCsHGO83db13XhcyZkoODbUqe7u0NTA6UR8I9Uxn+cn71hTqacS+Z7b1SCkjhFsQghY+4NbcNq9to69n9xg/7SbanFTeYRPANtWlszcuKYngk4EizteFXZSoRR9FUJiK5lSTJ04KzVOBMlEkLmqBinHjBRnSNru32M/eSWD++OPIDVIOcL3xtAtHlDNUkTUu8jZGvcAd9lLSFySDRYBHzsPVHywaOZDRNSLipqelBiEQvh0EfxrpNf/Gyyhszsz5eAWwaJPh9YbXwmEkz3yuFUSTYBRpeCcU1/c7Is/425iuqNhqa66DTSzZrMKX+tAKS+ctY7hb6U+fbtmKecFGDX6vZ83Czt089r/y1ZJxFxO19qJ1ixA/aWdgm8WBzb30d1AvuIWAvffo2KFTGWXT0eGbu9/z43Rk/lMsTxJGhJ8c2Ae6nqT1gbl75X1tbhVyRAWA88GUdJLSYMQ68P13nj4XVwGD+wbxcx25blaF+uhiwxtHMH1rish9y2frKqkz6i3YRbwIqCI5UzmUlCEHBfmswqcxNoCm3oQiKBjqNFUU0I61A8Nn2mssGyndqxDF/tWD2R+tVQIDAQABAoICAA0KYVDlYaJeZwHjRYRoRFMxfePEdbAHJnokUwzJi2ViF2du8Lr27gJLaXux/f5GVLaUgh/EuVDZ4ztPH1ijoi5fTTB0QkBGjRIB6GFw55dBAzaoobWg4/bviQuzeAvkXFUHYGhFVBicKF+fHSWOl6tHaUzItN2UNptfQH5UX0pRxnG77YAZhlCfVaZIkhhUC/ZNcbThU/Uyh8evHs8S21Ay0xW60N306w8YYeQg+UqHhui4mhVFb7vSQrtxSnEEPspsubH5bygXgFgTcX1Sa36juDV6yyUKM4bqAFvfbvncWcoHNw2CkFMIpq5pODh93OM27OBsIF4t+A7Q5evk0ycJzydb0b/TKosxvv55ft1LKSUa/d0Kz88rCBHlHmome1sIXXYVOCoaynOEGh+fxCfAnIZ3Jskr/EUFvfCduM4bIzY/vWI/aRKm0XlatTiM7IfefrYr3mrXPRzRg2BV9l7mftrRUP8y3+QgacmskG1TpfHBigAwXKUjYMm2FQAHldes+oMwRJZQqDzWy9u5FQPfIP0yPdp5ICPTcTePFV2GEk6aLWbNNflfU3W8JheR52rj9A52yAmaLq1ovcFL4Y5sCG4AzOivB4Dp7O2NQklFG9RrWR0Pf2SUh+Fax5j5WLWTyi8fQykfknhdr/0K7OKDN9FlLhtGQSx9Nfv4Fdn9AoIBAQD75tsHcBWh9A9/VKRB9eJkKtIQigkVQMhtV+QMRn+UuWTdSXVVwBOHKJjDponKp+BaKBNZPaNV/QItCjpTXIPZ44zCy0bxQVmcN17pTNX95o+GfDrVD42z/xO9ljmZLPCs4GDfpAndt4VzOil4jEyLqsZRbLtaLuVyL6v0BJAA538cL2scQ6eI9OlHFPRjxTxCIXnX8LDaFWl4/jOrSSGr+nrZ+eZlQlvYIz0T0s2lzTTiFk7qTJ1u3XknU4xn90nfhQYNyd1nyp4zK38zEOcQomxZthuid3OHu8vFgCfIuoAvz1MiLsZe42nd3CVUxWviW87HMrWTxy6ZmmxdNB8/AoIBAQCcEoTcGJe4Nz8+1e5F7cZusy7zt12SLFlzJkhSFom/2Iai7j8fWRHck9xeGqi97NoGMEnzxy7wSwEJJudlHuZHBhG1Uagx0UxE7VO0tpjm/qUz+bebdtlf3NS0O00Kvg1rh4ldSJejhR9fcxUAEoKIuekYfYSjtpApO3pYFf3HsPON2xBsdSqt5XmUUgUpxfb56E/sYVL1fujXTxxSx0R8VPbavlMjOaHygRydcinvhCGF/bDEmicB4ujmNBuuCJ/qtPPXy+Uwwlejgv419ZVzwFEhMEhKvz1KDfNEaVY1WCoQSX2UUrr2QxIfcOITpbuPzgOIVqKrTPYYbpr//+JrAoIBAQC5nDdT2bD27sDkj9egiq9QI4U5jpx2vo9wkkyFBwVG7vx1WYVNtAQvmShHMdViMCTOCa2IGjTaTV1nFpw3hHna+SJk/ie96OtAgkQ7H9SmC1dCPxOSnq1JLfC7x4+VYFnO6F45K8PhTTLV3stj+e0FFMaghL/gCaIjayEG4r3BDNLKT95aqzctYVjqeXRCd7iY+dWv2bhWWWSoNJaZ5X8cG6qeJtcvUaAfOIfurWu+eeA3nzxyxBVU9XgqFBPnH32dZ4U4b7/mlJPRHIHTfObliOjRia//HIlSQHw7gNzPuSxvDhMxosmkbWk6gtY3CmkeF4vbl2/X/fJGWFT0sE09AoIBADL79bz0p7N9EMMVHbZoW3dUP5VMJFwY8sukCOIQDMXIFQtqquIxtZ0KDGYNbWxF0F9PLQle2x2SUu9LbzHgazduayCBYWGMzs6BfOO+9qoXK56UB//YTmB7glyyNpO4zCeBakU37plzZnFG5ehVI6FIojXm4wqcG/HsRSY7YOD4FEgV9QKJL/0IxrPGK3ue+PRgiKNek7wwzh1v8X+1KtE27EE/BWevbxEKTm+8mKhu0Ii1/CXteaqrFowFH7m1hZAltrabG+7WvcxjgWndJQpgG+CspiEM4hesAPkrNAdPGsahS03FzN+fv27X8HKcpG3wzcSfEJrHFGmc0DOqwqsCggEAJ+ICyEbmQ94Ibtha4QJSeFCgVO29eM0/O8e8beGv3+zrxrt5kQLFrrvJIke2iAnRbmBkX0BDyTMQ5LdexGp1R1272Q9HAysjsWitw4GHV4CZK6dezm7slDTx/8z6bD1B2oeFboyuevB04sFZVUY3qzbuIEQYpvU9nwThxP/sVq+1v2ilXPD2iSXdVScGkNUVmpF4asiteYvS6feohV/HMMm71D/CeENcHfgSiqZyW1hHsDxgSwYOQcCpEdrXTF7ly/SpKDjYfmljCPvFwpECO8pNG90/e/CY+6H7jpAS00AFRzK+/bs6JW5gQE1zC/O05DB77oREVfk9NI6eElY4ZA=="; + +// //初始化 +// static { +// try { +// //KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象 +// KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); +// //初始化密钥对生成器,密钥大小为96-1024位 +// keyPairGen.initialize(4096, new SecureRandom()); +// //生成一对密钥 +// KeyPair keyPair = keyPairGen.generateKeyPair(); +// //公钥存储 +// PublicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded())); +// //私钥存储 +// PrivateKey = new String(Base64.encodeBase64((keyPair.getPrivate().getEncoded()))); +// } catch (NoSuchAlgorithmException e) { +// logger.error("RSA生成秘钥异常:[{}]", e); +// } +// } + + /** + * RSA公钥加密 + * + * @param str 加密字符串 + * @param publicKey 公钥 + * @return 密文 + * @throws Exception 加密过程中的异常信息 + */ + public static String encrypt(String str, String publicKey) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)))); + return Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8"))); + } + + /** + * RSA私钥解密 + * + * @param str 加密字符串 + * @param privateKey 私钥 + * @return 铭文 + * @throws Exception 解密过程中的异常信息 + */ + public static String decrypt(String str) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(PrivateKey)))); + return new String(cipher.doFinal(Base64.decodeBase64(str.getBytes("UTF-8")))); + } + + //测试 + public static void main(String[] args) throws Exception { + //加密字符串 + String message = "{\"acc\":\"mwxtest1000001\",\"nick\":\"mwxtest1000001\",\"sex\":2,\"deviceCode\":\"281a228fac1c29d25c1a3e572b15ad47d5f66811\",\"portrait\":\"\"}"; + System.out.println("随机生成的公钥为:" + PublicKey); + System.out.println("随机生成的私钥为:" + PrivateKey); + String messageEn = encrypt(message, PublicKey); + System.out.println("加密前:" + message); + System.out.println("加密后:" + messageEn); + String messageDe = decrypt(messageEn); + System.out.println("还原后:" + messageDe); + } + +} \ No newline at end of file diff --git a/web_group/src/main/webapp/WEB-INF/web.xml b/web_group/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..a71270c --- /dev/null +++ b/web_group/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + + taurus-web + com.taurus.web.WebFilter + + main + com.group.MainServer + + + + + taurus-web + /* + + diff --git a/web_group/src/main/webapp/config/bank_hp.lua b/web_group/src/main/webapp/config/bank_hp.lua new file mode 100644 index 0000000..d3a02ce --- /dev/null +++ b/web_group/src/main/webapp/config/bank_hp.lua @@ -0,0 +1,19 @@ +local tag_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local bank_hp = tonumber(redis.call('hget', KEYS[2],KEYS[3])) +bank_hp = not bank_hp and 0 or bank_hp +local hp = tonumber(ARGV[1]) +local opt = tonumber(ARGV[2]) +if opt==0 then + if bank_hp < hp then + return 3 + end + bank_hp = redis.call('hincrBy',KEYS[2],KEYS[3],-hp) + tag_hp = redis.call('hincrBy',KEYS[1],'hp',hp) +else + if tag_hp < hp then + return 4 + end + bank_hp = redis.call('hincrBy',KEYS[2],KEYS[3],hp) + tag_hp = redis.call('hincrBy',KEYS[1],'hp',-hp) +end +return {tag_hp,bank_hp} \ No newline at end of file diff --git a/web_group/src/main/webapp/config/log4j.properties b/web_group/src/main/webapp/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_group/src/main/webapp/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_group/src/main/webapp/config/mgr.lua b/web_group/src/main/webapp/config/mgr.lua new file mode 100644 index 0000000..e3e9aae --- /dev/null +++ b/web_group/src/main/webapp/config/mgr.lua @@ -0,0 +1,25 @@ +-- redis.call('select',0) +local mgr_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local tag_hp = tonumber(redis.call('hget', KEYS[2],'hp')) + +local ulev = tonumber(ARGV[2]) +local hp = tonumber(ARGV[1]) +if ulev == 3 or ulev == 2 then + if KEYS[1] ~= KEYS[2] and hp > 0 and mgr_hp < hp then + return 3 + else + if hp < 0 and tag_hp < math.abs(hp) then + return 4 + end + mgr_hp = redis.call('hincrBy',KEYS[1],'hp',-hp) + tag_hp = redis.call('hincrBy',KEYS[2],'hp',hp) + end +else + tag_hp = tag_hp + hp + if tag_hp < 0 then + return 4 + else + redis.call('hincrBy',KEYS[2],'hp',hp) + end +end +return {mgr_hp,tag_hp} \ No newline at end of file diff --git a/web_group/src/main/webapp/config/take_hp.lua b/web_group/src/main/webapp/config/take_hp.lua new file mode 100644 index 0000000..83d79a0 --- /dev/null +++ b/web_group/src/main/webapp/config/take_hp.lua @@ -0,0 +1,10 @@ +local reward_hp = tonumber(redis.call('get', KEYS[1])) +local hp = tonumber(ARGV[1]) +local tag_hp = 0 +if hp > 0 and reward_hp < hp then + return 3 +else + reward_hp = redis.call('incrBy',KEYS[1],-hp) + tag_hp = redis.call('hincrBy',KEYS[2],'hp',hp) +end +return {reward_hp,tag_hp} \ No newline at end of file diff --git a/web_group/src/main/webapp/config/taurus-core.xml b/web_group/src/main/webapp/config/taurus-core.xml new file mode 100644 index 0000000..6f0b48d --- /dev/null +++ b/web_group/src/main/webapp/config/taurus-core.xml @@ -0,0 +1,100 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://8.134.123.86:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_group/src/main/webapp/config/trade.lua b/web_group/src/main/webapp/config/trade.lua new file mode 100644 index 0000000..c03a438 --- /dev/null +++ b/web_group/src/main/webapp/config/trade.lua @@ -0,0 +1,12 @@ +local mgr_hp = tonumber(redis.call('hget', KEYS[1],'hp')) +local tag_hp = tonumber(redis.call('hget', KEYS[2],'hp')) +mgr_hp = not mgr_hp and 0 or mgr_hp +tag_hp = not tag_hp and 0 or tag_hp +local hp = tonumber(ARGV[1]) +if hp > 0 and mgr_hp + + + + org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern + .*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$ + + + \ No newline at end of file diff --git a/web_group/src/test/java/web_group/DataClearUtils.java b/web_group/src/test/java/web_group/DataClearUtils.java new file mode 100644 index 0000000..f0be96e --- /dev/null +++ b/web_group/src/test/java/web_group/DataClearUtils.java @@ -0,0 +1,146 @@ +package web_group; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import redis.clients.jedis.Jedis; + +/** + * clear redis data + * @author yjl 2020-06-05 + * @version 1.0.0 + * */ +public class DataClearUtils { + + private void clear_data() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Map map = new HashMap<>(); + map.put("force_ver", "1"); + map.put("ver", "1"); + Jedis jedis = new Jedis("127.0.0.1", 6380); + jedis.auth("123456"); + //选择库 + jedis.select(5); + Set keys = jedis.keys("*"); + int i = 0; + for(String str : keys) { + long stime = Long.valueOf(str.substring(15,str.length())); + if(stime < 1591286400) { + jedis.del(str); + i++; + System.out.println(i); + } + + } + System.out.println(i); + + jedis.close(); + } + + private void clear_data_thread() { +// Thread th = new Thread(new clear_data_t(1592323200, 1592668800,1)); +// th.start(); +// +// Thread th1 = new Thread(new clear_data_t(1591977600, 1592323200,2)); +// th1.start(); +// +// Thread th2 = new Thread(new clear_data_t(1591718400, 1591977600,3)); +// th2.start(); +// + Thread th3 = new Thread(new clear_data_test(1590940800, 1593964800,4)); + th3.start(); + +// Thread th4 = new Thread(new clear_data_t(1588262400, 1590336000,5)); +// th4.start(); +//// +// Thread th5 = new Thread(new clear_data_t(1588262400, 1589904000,6)); +// th5.start(); + } + class clear_data_test implements Runnable{ + long start = 0; + long end = 0; + int num = 0; + + public clear_data_test(long start,long end,int num) { + this.start = start; + this.end = end; + this.num = num; + } + @Override + public void run() { + // TODO Auto-generated method stub + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Map map = new HashMap<>(); + map.put("force_ver", "1"); + map.put("ver", "1"); + Jedis jedis = new Jedis("127.0.0.1", 6379); + jedis.auth("123456"); + //选择库 + jedis.select(0); + Set keys = jedis.keys("*"); + int i = 0; + for(String str : keys) { + long stime = Long.valueOf(str.substring(15,str.length())); + if(stime < end && stime > start) { + jedis.del(str); + i++; + System.out.println("#"+num +"Thread"+i); + } + + } + System.out.println(i); + + jedis.close(); + } + + } + + // + + public static void main(String[] args) { + DataClearUtils initDataUtils = new DataClearUtils(); + initDataUtils.clear_data_thread(); + } + + class clear_data_t implements Runnable{ + long start = 0; + long end = 0; + int num = 0; + + public clear_data_t(long start,long end,int num) { + this.start = start; + this.end = end; + this.num = num; + } + @Override + public void run() { + // TODO Auto-generated method stub + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Map map = new HashMap<>(); + map.put("force_ver", "1"); + map.put("ver", "1"); + Jedis jedis = new Jedis("127.0.0.1", 6380); + jedis.auth("123456"); + //选择库 + jedis.select(5); + Set keys = jedis.keys("*"); + int i = 0; + for(String str : keys) { + long stime = Long.valueOf(str.substring(15,str.length())); + if(stime < end && stime > start) { + jedis.del(str); + i++; + System.out.println("#"+num +"Thread"+i); + } + + } + System.out.println(i); + + jedis.close(); + } + + } +} diff --git a/web_group/src/test/java/web_group/Main.java b/web_group/src/test/java/web_group/Main.java new file mode 100644 index 0000000..322c282 --- /dev/null +++ b/web_group/src/test/java/web_group/Main.java @@ -0,0 +1,9 @@ +package web_group; + +import com.taurus.web.JettyServer; + +public class Main { + public static void main(String[] args) { + new JettyServer("src/main/webapp",8081,"/").start(); + } +} diff --git a/web_login/.idea/artifacts/web_login_war.xml b/web_login/.idea/artifacts/web_login_war.xml new file mode 100644 index 0000000..3504ab7 --- /dev/null +++ b/web_login/.idea/artifacts/web_login_war.xml @@ -0,0 +1,14 @@ + + + $PROJECT_DIR$/target + + + web_login + war + + + + + + + \ No newline at end of file diff --git a/web_login/.idea/artifacts/web_login_war_exploded.xml b/web_login/.idea/artifacts/web_login_war_exploded.xml new file mode 100644 index 0000000..947083c --- /dev/null +++ b/web_login/.idea/artifacts/web_login_war_exploded.xml @@ -0,0 +1,23 @@ + + + $PROJECT_DIR$/target/ROOT + + + true + web_login + war + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/.idea/compiler.xml b/web_login/.idea/compiler.xml new file mode 100644 index 0000000..d0df4bb --- /dev/null +++ b/web_login/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/.idea/misc.xml b/web_login/.idea/misc.xml new file mode 100644 index 0000000..0adbe1d --- /dev/null +++ b/web_login/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/web_login/.idea/modules.xml b/web_login/.idea/modules.xml new file mode 100644 index 0000000..4270919 --- /dev/null +++ b/web_login/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/web_login/.idea/workspace.xml b/web_login/.idea/workspace.xml new file mode 100644 index 0000000..01d7704 --- /dev/null +++ b/web_login/.idea/workspace.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + 1623486082788 + + + + + + \ No newline at end of file diff --git a/web_login/build/local/log4j.properties b/web_login/build/local/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_login/build/local/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_login/build/local/taurus-core.xml b/web_login/build/local/taurus-core.xml new file mode 100644 index 0000000..e677c8e --- /dev/null +++ b/web_login/build/local/taurus-core.xml @@ -0,0 +1,96 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 10 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/build/pro/log4j.properties b/web_login/build/pro/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_login/build/pro/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_login/build/pro/taurus-core.xml b/web_login/build/pro/taurus-core.xml new file mode 100644 index 0000000..37dc99e --- /dev/null +++ b/web_login/build/pro/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 5 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://101.35.26.131:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/build/test/log4j.properties b/web_login/build/test/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_login/build/test/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_login/build/test/taurus-core.xml b/web_login/build/test/taurus-core.xml new file mode 100644 index 0000000..ab22b21 --- /dev/null +++ b/web_login/build/test/taurus-core.xml @@ -0,0 +1,97 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 0 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://192.168.0.11:6060/wb_game + proto_ff + 37du_game + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/config/log4j.properties b/web_login/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_login/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_login/config/taurus-core.xml b/web_login/config/taurus-core.xml new file mode 100644 index 0000000..dfdb4d9 --- /dev/null +++ b/web_login/config/taurus-core.xml @@ -0,0 +1,99 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 10000 + + 1 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://101.35.26.131:8060/wb_game?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 8 + + 2 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + + + diff --git a/web_login/pom.xml b/web_login/pom.xml new file mode 100644 index 0000000..47f124f --- /dev/null +++ b/web_login/pom.xml @@ -0,0 +1,130 @@ + + 4.0.0 + com.mjlogin + web_login + war + 1.0.0 + + UTF-8 + 1.8 + 1.8 + pro + + + + + junit + junit + 3.8.1 + test + + + + + com.data + data_cache + 1.0.1 + + + + + com.taurus + taurus-core + 1.0.1 + + + + + com.taurus + taurus-web + 1.0.1 + + + + + redis.clients + jedis + 2.9.0 + + + + + com.zaxxer + HikariCP + 3.3.1 + + + + + mysql + mysql-connector-java + 8.0.16 + + + + + jdom + jdom + 1.0 + + + + + log4j + log4j + 1.2.17 + + + + + com.google.code.gson + gson + 2.8.5 + + + + com.aliyun + aliyun-java-sdk-core + 4.0.3 + + + + org.eclipse.jetty + jetty-webapp + 8.2.0.v20160908 + provided + + + org.quartz-scheduler + quartz + 2.2.3 + compile + + + + + ROOT + + + + org.apache.maven.plugins + maven-war-plugin + + 1.8 + 1.8 + UTF-8 + config/**,logs/** + + + config/ + ${project.basedir}/build/${build.type} + + + + + + + + diff --git a/web_login/src/main/java/com/mjlogin/MainServer.java b/web_login/src/main/java/com/mjlogin/MainServer.java new file mode 100644 index 0000000..2cf1ad6 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/MainServer.java @@ -0,0 +1,73 @@ +package com.mjlogin; + +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + + +import com.mjlogin.service.AccountService; +import com.mjlogin.service.IndexService; +import com.mjlogin.service.MilitaryService; +import com.mjlogin.service.RoomService; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.Extension; +import com.taurus.core.routes.Routes; +import com.taurus.core.util.StringUtil; + +public class MainServer extends Extension { + public static int DEFAULT_DAIMO = 5; + public static String GROUP_WEB_URL = ""; + private ScheduledThreadPoolExecutor timeScheduler; + + private static final String WEB_CONFIG_KEY = "web_config"; + private static final String FORCE_VER_KEY = "force_ver"; + public MainServer() { + super(); + String str = Redis.use("group1_db1").hget(WEB_CONFIG_KEY,"default_daimo"); + if (StringUtil.isNotEmpty(str)) { + DEFAULT_DAIMO = Integer.parseInt(Redis.use("group1_db1").hget(WEB_CONFIG_KEY,"default_daimo")); + } + GROUP_WEB_URL = Redis.use("group1_db1").hget("web_requrl", "groupWeb"); + + timeScheduler = new ScheduledThreadPoolExecutor(1); + timeScheduler.scheduleAtFixedRate(new Runnable() { + + @Override + public void run() { + System.gc(); + } + }, 0,600, TimeUnit.SECONDS); + + } + + + @Override + public int readVersion() { + int ver = Integer.parseInt(Redis.use("group1_db1").hget(WEB_CONFIG_KEY,FORCE_VER_KEY)); + return ver; + } + + @Override + public void configRoute(Routes me) { + me.setInterceptor(new WebInterceptor()); + me.add("acc", AccountService.class); + me.add("index", IndexService.class); + me.add("military", MilitaryService.class); + me.add("room", RoomService.class); + } + + @Override + public void onStart() { + + + } + + @Override + public void onStop() { + // TODO Auto-generated method stub + if(timeScheduler!=null) { + timeScheduler.shutdownNow(); + } + + } + +} diff --git a/web_login/src/main/java/com/mjlogin/Protocol.java b/web_login/src/main/java/com/mjlogin/Protocol.java new file mode 100644 index 0000000..212808f --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/Protocol.java @@ -0,0 +1,82 @@ +package com.mjlogin; + +public class Protocol { + // ======AccountService + public static final String REGIST_LOGIN = "regist_login"; + + public static final String REGIST_LOGIN_2 = "regist_login_2"; + + public static final String CHECK_UUID = "check_uuid"; + + public static final String CREATE_XING_YUN_HAO = "create_xing_yun_hao"; + + public static final String QUICK_LOGIN = "quick_login"; + + public static final String QUICK_LOGIN_2 = "quick_login_2"; + + public static final String PHONE_PASSWORD_LOGIN = "phone_pw_login"; + + public static final String PHONE_LOGIN = "phone_login"; + + public static final String PHONE_LOGIN_2 = "phone_login_2"; + + public static final String ID_PASSWORD_LOGIN = "id_login"; + + public static final String ID_PASSWORD_LOGIN_2 = "id_login_2"; + + /** 绑定电话号码 **/ + public static final String BINDING_PHONE = "binding_phone"; + /** 获取短信验证码 **/ + public static final String GET_VERIFICATION_CODE = "get_verification_code"; + + public static final String UPDATE_PLAYER_INFO = "update_player_info"; + + public static final String UPDATE_USER_INFO = "update_user_info"; + + public static final String GET_USER_INFO = "get_user_info"; + + public static final String CHECK_GOD = "check_god"; + + // --------------------Index-------------------------- + public static final String GET_NOTICE = "get_notice"; + + public static final String SHARE_GAME = "share_game"; + + public static final String GET_SHARE_LIST = "get_share_list"; + + // --------------------military-------------------------- + + public static final String GET_RANK_LIST_BY_GROUP = "get_rankListByGroup"; + + public static final String GET_ROUND_LIST_BY_GROUP = "get_roundListByGroup"; + + public static final String SET_RANK_LIST_RIGHT_BY_GROUP = "set_randListRightByGroup"; + + public static final String GET_MILITARY = "get_military"; + + public static final String GET_MILITARY_BY_ROOMID = "get_militaryByRoomId"; + + public static final String GET_PLAYBACK = "get_playBack"; + + // --------------------room-------------------------- + public static final String CREATE_ROOM = "create_room"; + public static final String JOIN_ROOM = "join_room"; + + public static final String GET_CODE = "get_code"; + + + public static final String GET_APP_INFO = "get_app_info"; + + /**找回密码*/ + public static final String SET_BACK_PASSWORD ="set_back_password"; + + /**绑定列表*/ + public static final String GET_BANGDING_ACCOUNT ="get_bangding_account"; + + /**绑定账号*/ + public static final String BANGDING_ACCOUNT ="bangding_account"; + + /**绑定账号*/ + public static final String GET_USER_IP ="get_user_ip"; + +} diff --git a/web_login/src/main/java/com/mjlogin/WebInterceptor.java b/web_login/src/main/java/com/mjlogin/WebInterceptor.java new file mode 100644 index 0000000..aee0283 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/WebInterceptor.java @@ -0,0 +1,56 @@ +package com.mjlogin; + +import com.data.util.ErrorCode; +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.routes.Action; +import com.taurus.core.routes.IController; +import com.taurus.core.routes.Interceptor; +import com.taurus.core.util.StringUtil; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +public class WebInterceptor implements Interceptor{ + /** + * 验证session + */ + public static final int V_SESSION = 1; + @Override + public void intercept(Action action, IController controller, Object... args) throws Exception { + Controller ctr = (Controller)controller; + int validate = action.getActionKeyObj().validate(); + if((validate&V_SESSION)!=0) { + String session = ctr.getSession(); + String token = ctr.getTokens(); + if (!Redis.use("group1_db0").exists(session)) { + throw new WebException(ErrorCode._NO_SESSION); + } + + if (StringUtil.isNotEmpty(token) && StringUtil.isNotEmpty(session)) + { + String token_session = Redis.use("group1_db0").hget(token, "user"); + if (StringUtil.isEmpty(token_session)) + { + throw new WebException(ErrorCode._NO_SESSION); + } + else { + if (!token_session.equals(session)) + { + throw new WebException(ErrorCode._NO_SESSION); + } + } + } + else { + throw new WebException(ErrorCode._NO_SESSION); + } + + String opt = Redis.use("group1_db0").hget(session, "opt"); +// background del sign + if (!StringUtil.isEmpty(opt) && Integer.parseInt(opt) == 1) { + throw new WebException(ErrorCode._NO_SESSION); + } + } + + } + + +} diff --git a/web_login/src/main/java/com/mjlogin/service/AccountService.java b/web_login/src/main/java/com/mjlogin/service/AccountService.java new file mode 100644 index 0000000..ffa5be2 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/service/AccountService.java @@ -0,0 +1,2382 @@ +package com.mjlogin.service; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; +import java.util.Set; +import java.util.UUID; + +import com.aliyuncs.utils.StringUtils; +import com.data.bean.AccountBean; +import com.data.bean.GameBean; +import com.data.cache.AccountCache; +import com.data.cache.BaseCache; +import com.data.cache.GameCache; +import com.data.util.ErrorCode; +import com.data.util.Utility; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.mjlogin.MainServer; +import com.mjlogin.Protocol; +import com.mjlogin.WebInterceptor; +import com.mjlogin.util.sms.RedisKey; +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.plugin.redis.RedisLock; +import com.taurus.core.routes.ActionKey; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.Utils; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +import redis.clients.jedis.Jedis; + +public class AccountService extends Controller { + private static Logger logger = Logger.getLogger(AccountService.class); + + /** + * 手机验证码登录 + * + * @throws Exception + */ + @ActionKey(value = Protocol.PHONE_PASSWORD_LOGIN) + public final void phoneCodeLogin() throws Exception { + ITObject reqDatas = this.getParams(); + String phone = reqDatas.getUtfString("phone"); + String code = reqDatas.getUtfString("password"); + logger.info("jefe phone:" + phone + " == code:" + code); + // 判断code 是否正确 + if (Redis.use("group1_db1").exists("code" + phone)) { + + String vfcode = Redis.use("group1_db1").get("code" + phone); + logger.info("jefe phone:" + phone + " == code:" + code + "vfcode:" + vfcode); + if (vfcode.equals(code)) { + String acc = md5(phone); + + ITObject reqData = TObject.newInstance(); + + String sqluid = "SELECT id,nickname FROM uuids WHERE uuid =?"; + String[] params1 = new String[1]; + params1[0] = acc + ""; + + ITArray resultArrayuid = DataBase.use().executeQueryByTArrayLogin(sqluid, params1); + int accountUid = 0; + String nickname = ""; + if (resultArrayuid.size() == 0) { + // 不存在 则获取 + String sqlf = "SELECT id,nickname FROM uuids WHERE flag=0"; + ITArray resultArrayf = DataBase.use().executeQueryByTArrayLogin(sqlf, new String[0]); + + if (resultArrayf.size() == 0) { + return; + } + + ITObject obj = resultArrayf.getTObject(0); + accountUid = obj.getInt("id"); + nickname = obj.getString("nickname"); + String sqlb = "UPDATE uuids SET uuid='" + acc + "' , flag=1 where id=" + accountUid; + DataBase.use().executeUpdate(sqlb); + // resData.putInt("id",accountid); + // resData.putString("nickname",nickname); + } else { + ITObject obj = resultArrayuid.getTObject(0); + accountUid = obj.getInt("id"); + nickname = obj.getString("nickname"); + // resData.putInt("id",accountid); + // resData.putString("nickname",nickname); + } + + // 获取头像信息 + String sql = "SELECT id FROM account WHERE acc =?"; + String[] params2 = new String[1]; + params2[0] = acc + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params2); + + reqData.putUtfString("acc", acc); + reqData.putInt("sex", 1); + // String strNick = reqData.getUtfString("nick"); + String strNick = nickname; + strNick = StringUtil.filterEmoji(strNick); + reqData.putUtfString("nick", strNick); + reqData.putUtfString("portrait", + "https://headerimgs2023.oss-cn-guangzhou.aliyuncs.com/headers/man_" + accountUid + ".jpg"); + int accountid = 0; + if (resultArray.size() == 0) { + accountid = register(reqData); + } else { + ITObject obj = resultArray.getTObject(0); + accountid = obj.getInt("id"); + } + + if (acc.equals(accountid + "")) { + logger.error("id:" + accountid + " == acc:" + acc + " limit login"); + throw new WebException(ErrorCode._FAILED); + } + + AccountBean acc_bean = AccountCache.getAccount(accountid); + if (acc_bean == null) { + sql = String.format("SELECT * FROM account WHERE id =?"); + String[] params3 = new String[1]; + params3[0] = accountid + ""; + + ITArray resultArray2 = DataBase.use().executeQueryByTArrayLogin(sql, params3); + if (resultArray2.size() == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = resultArray2.getTObject(0); + UpdateUserData(userData, accountid); + + acc_bean = AccountCache.getAccount(accountid); + } + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData = TObject.newInstance(); + userData.putUtfString("nick", reqData.getUtfString("nick")); + userData.putUtfString("portrait", reqData.getUtfString("portrait")); + userData.putInt("sex", reqData.getInt("sex")); + updateSession(reqData, accountid); + } + } + + String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + acc_bean.id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash(acc + "_" + accountid + "_" + System.currentTimeMillis() + + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + resData.putString("token", token); + this.sendResponse(ErrorCode._SUCC, resData); + } else { + throw new WebException(ErrorCode._FAILED); + } + } + + throw new WebException(ErrorCode._FAILED); + } + + /** + * 获取手机验证码 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_VERIFICATION_CODE) + public final void getVerificationCode() throws Exception { + ITObject reqData = this.getParams(); + String phone = reqData.getUtfString("phone"); + logger.info("jefe phone:" + phone); + // 检测短信是否有发送过 + if (Redis.use("group1_db1").exists("code" + phone)) { + throw new WebException(ErrorCode._FAILED); + } else { + String testUsername = "liubo2023"; // 在短信宝注册的用户名 + String testPassword = "Jefe2014"; // 在短信宝注册的密码 + String testPhone = phone; + // 创建Random对象 + Random random = new Random(); + // 生成随机6位数字 + int number = random.nextInt(900000) + 100000; + String vfcode = number + ""; + Redis.use("group1_db1").set("code" + phone, vfcode); + Redis.use("group1_db1").expire("code" + phone, 300); + String testContent = "【湘悦】您的验证码是" + vfcode + ",5分钟内有效。若非本人操作请忽略此消息。"; // 注意测试时,也请带上公司简称或网站签名,发送正规内容短信。千万不要发送无意义的内容:例如 + // 测一下、您好。否则可能会收不到 + + String httpUrl = "http://api.smsbao.com/sms"; + + StringBuffer httpArg = new StringBuffer(); + httpArg.append("u=").append(testUsername).append("&"); + httpArg.append("p=").append(md5(testPassword)).append("&"); + httpArg.append("m=").append(testPhone).append("&"); + httpArg.append("c=").append(encodeUrlString(testContent, "UTF-8")); + + String result = request(httpUrl, httpArg.toString()); + logger.info("jefe result:" + result); + this.sendResponse(ErrorCode._SUCC, reqData); + } + } + + public static String request(String httpUrl, String httpArg) { + BufferedReader reader = null; + String result = null; + StringBuffer sbf = new StringBuffer(); + httpUrl = httpUrl + "?" + httpArg; + + try { + URL url = new URL(httpUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.connect(); + InputStream is = connection.getInputStream(); + reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + String strRead = reader.readLine(); + if (strRead != null) { + sbf.append(strRead); + while ((strRead = reader.readLine()) != null) { + sbf.append("\n"); + sbf.append(strRead); + } + } + reader.close(); + result = sbf.toString(); + } catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public static String md5(String plainText) { + StringBuffer buf = null; + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + md.update(plainText.getBytes()); + byte b[] = md.digest(); + int i; + buf = new StringBuffer(""); + for (int offset = 0; offset < b.length; offset++) { + i = b[offset]; + if (i < 0) + i += 256; + if (i < 16) + buf.append("0"); + buf.append(Integer.toHexString(i)); + } + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return buf.toString(); + } + + public static String encodeUrlString(String str, String charset) { + String strret = null; + if (str == null) + return str; + try { + strret = java.net.URLEncoder.encode(str, charset); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return strret; + } + + /** + * + * @return + * @throws Exception + */ + private final int register(ITObject reqData) throws Exception { + int count = 0; + long id = 0; + do { + id = Long.parseLong(Redis.use("group1_db1").rpop("free_account")); + String sql = "SELECT id FROM account WHERE id =?"; + String[] params = new String[1]; + params[0] = id + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params); + if (resultArray.size() == 0) { + break; + } + } while (count++ <= 10); + + if (id == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = TObject.newInstance(); + userData.putInt("id", (int) id); + if (reqData.containsKey("phone")) { + /// + userData.putUtfString("phone", reqData.getUtfString("phone")); + userData.putUtfString("nick", "景都" + id + ""); + userData.putInt("sex", 1); + userData.putUtfString("portrait", StringUtil.Empty); + } else { + userData.putUtfString("acc", reqData.getUtfString("acc")); + userData.putUtfString("portrait", reqData.getUtfString("portrait")); + String nick = reqData.getUtfString("nick"); + nick = nick.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", " "); + userData.putUtfString("nick", nick); + int sex = reqData.getInt("sex"); + if (sex == 0) { + sex = 1; + reqData.putInt("sex", sex); + } + userData.putInt("sex", sex); + } + userData.putInt("diamo", MainServer.DEFAULT_DAIMO); + userData.putInt("mng", 0); + userData.putInt("type", 0); + + long reg_time = System.currentTimeMillis() / 1000; + userData.putLong("reg_time", reg_time); + userData.putString("device_code", reqData.getUtfString("deviceCode")); + + int result = DataBase.use().insert("account", userData); + if (result == -1) { + throw new WebException(ErrorCode._FAILED); + } + userData.putInt("invitation", 1); + String session = updateSession(userData, (int) id); + this.setSession(session); + return (int) id; + } + + private final int create_register(int mng, String password, ArrayList nickList, ArrayList headList) + throws Exception { + int count = 0; + long id = 0; + ArrayList list = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + String strId = Redis.use("group1_db1").rpop("free_account"); + if (StringUtils.isEmpty(strId)) { + break; + } + list.add(strId); + } + // logger.info("free_account:"+list.toString()); + + Collections.shuffle(list); + + do { + id = Long.parseLong(list.remove(0)); + String sql = "SELECT id FROM account WHERE id =?"; + String[] params = new String[1]; + params[0] = id + ""; + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params); + if (resultArray.size() == 0) { + break; + } + } while (count++ <= 10); + + for (int i = 0; i < list.size(); i++) { + Redis.use("group1_db1").lpush("free_account", list.get(i)); + } + + if (id == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = TObject.newInstance(); + userData.putInt("id", (int) id); + + userData.putUtfString("acc", "" + id); + if (headList.size() > 0) { + userData.putUtfString("portrait", headList.remove(0)); // 头像 + } else { + userData.putUtfString("portrait", ""); + } + + String nick = ""; + if (nickList.size() > 0) { + nick = nickList.remove(0); + } + nick = nick.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", " "); + userData.putUtfString("nick", nick); + int sex = 1; + if (sex == 0) { + sex = 1; + } + userData.putInt("sex", sex); + userData.putInt("diamo", 0); + userData.putInt("mng", 0); + userData.putInt("regTime", mng); + userData.putInt("type", 0); + userData.putUtfString("password", Utils.getMD5Hash(password)); + long reg_time = System.currentTimeMillis() / 1000; + userData.putLong("reg_time", reg_time); + logger.info("create xingyunhao account:" + userData.toJson() + " password:" + password); + int result = DataBase.use().insert("account", userData); + if (result == -1) { + throw new WebException(ErrorCode._FAILED); + } + userData.putInt("invitation", 1); + String session = updateSession(userData, (int) id); + this.setSession(session); + return (int) id; + } + + /** + * + * @return + * @throws Exception + */ + private final int UpdateUserData(ITObject reqData, long id) throws Exception { + ITObject userData = TObject.newInstance(); + userData.putInt("id", (int) id); + + userData.putUtfString("acc", reqData.getUtfString("acc")); + userData.putUtfString("portrait", reqData.getUtfString("portrait")); + userData.putUtfString("nick", reqData.getUtfString("nick")); + int sex = reqData.getInt("sex"); + if (sex == 0) { + sex = 1; + reqData.putInt("sex", sex); + } + userData.putInt("sex", sex); + + userData.putInt("mng", 0); + userData.putInt("type", 0); + if (reqData.containsKey("diamo")) { + userData.putInt("diamo", reqData.getInt("diamo")); + } + + userData.putInt("invitation", 1); + String session = updateSession(userData, (int) id); + this.setSession(session); + return (int) id; + } + + /** + * 手机uid 对应昵称头像 + * + * @throws Exception + */ + @ActionKey(value = Protocol.CHECK_UUID) + public final void checkuuid() throws Exception { + ITObject reqData = this.getParams(); + String uuid = reqData.getUtfString("uuid"); + + ITObject resData = TObject.newInstance(); + try { + String sql = "SELECT id,nickname FROM uuids WHERE uuid ='" + uuid + "'"; + String[] params = new String[1]; + params[0] = uuid + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params); + int accountid = 0; + String nickname = ""; + if (resultArray.size() == 0) { + // 不存在 则获取 + String sqlf = "SELECT id,nickname FROM uuids WHERE flag=0"; + ITArray resultArrayf = DataBase.use().executeQueryByTArrayLogin(sqlf, new String[0]); + + if (resultArrayf.size() == 0) { + return; + } + + ITObject obj = resultArrayf.getTObject(0); + accountid = obj.getInt("id"); + nickname = obj.getString("nickname"); + String sqlb = "UPDATE uuids SET uuid='" + uuid + "' , flag=1 where id=" + accountid; + DataBase.use().executeUpdate(sqlb); + resData.putInt("id", accountid); + resData.putString("nickname", nickname); + } else { + ITObject obj = resultArray.getTObject(0); + accountid = obj.getInt("id"); + nickname = obj.getString("nickname"); + resData.putInt("id", accountid); + resData.putString("nickname", nickname); + } + this.sendResponse(ErrorCode._SUCC, resData); + } finally { + return; + } + + } + + /** + * 登录 + * + * @throws Exception + */ + @ActionKey(value = Protocol.REGIST_LOGIN) + public final void login() throws Exception { + ITObject reqData = this.getParams(); + String acc = reqData.getUtfString("acc"); + logger.info("acc:" + acc + " regist login"); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = new RedisLock("wx_" + acc, jedis0); + String deviceCode = reqData.getUtfString("deviceCode"); + logger.info("deviceCode:" + deviceCode); + logger.info("reqData:" + reqData); + + boolean havePassword = false; + if (acc.length() < 10) { + throw new WebException(ErrorCode._FAILED); + } + try { +// String sql = "SELECT id FROM account WHERE acc ='" + acc + "'"; +// ITArray resultArray = DataBase.use().executeQueryByTArray(sql); + String sql = "SELECT id FROM account WHERE acc =?"; + String[] params2 = new String[1]; + params2[0] = acc + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params2); + + String strNick = reqData.getUtfString("nick"); + strNick = StringUtil.filterEmoji(strNick); + reqData.putUtfString("nick", strNick); + +// String nickCountsql = String.format( +// "SELECT id FROM account a,group_member gm WHERE a.id=gm.uid and a.nick ='%s' and a.device_code='%s'", +// strNick, deviceCode); +// String nickCountsql = "SELECT id FROM account a,group_member gm WHERE a.id=gm.uid and a.nick ='" + strNick +// + "'"; + +// List> nickDeviceCount = DataBase.use().executeQuery(nickCountsql); + + int accountid = 0; + if (resultArray.size() == 0) { + accountid = register(reqData); + reqData.putUtfString("isBangding", "0"); + + } else { + ITObject obj = resultArray.getTObject(0); + accountid = obj.getInt("id"); + String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + + accountid; + DataBase.use().executeUpdate(updateDeviceCodeSql); + reqData.putUtfString("isBangding", obj.getInt("is_bangding") + ""); + + } + + if (acc.equals(accountid + "")) { + logger.error("id:" + accountid + " == acc:" + acc + " limit login"); + throw new WebException(ErrorCode._FAILED); + } + + AccountBean acc_bean = AccountCache.getAccount(accountid); + if (acc_bean == null) { + sql = String.format("SELECT * FROM account WHERE id =?"); + String[] params = new String[1]; + params[0] = accountid + ""; + + ITArray resultArray2 = DataBase.use().executeQueryByTArrayLogin(sql, params); + if (resultArray2.size() == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = resultArray2.getTObject(0); + UpdateUserData(userData, accountid); + + acc_bean = AccountCache.getAccount(accountid); + } + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData = TObject.newInstance(); + userData.putUtfString("nick", reqData.getUtfString("nick")); + userData.putUtfString("portrait", reqData.getUtfString("portrait")); + userData.putInt("sex", reqData.getInt("sex")); + updateSession(reqData, accountid); + } + } + // password不存在则叫用户重置密码 + String passwordsql = String.format("SELECT password FROM account WHERE id =?"); + String[] params = new String[1]; + params[0] = acc_bean.id + ""; + + ITArray passwordArray = DataBase.use().executeQueryByTArrayLogin(passwordsql, params); + if (passwordArray.size() > 0) { + ITObject userData = passwordArray.getTObject(0); + String password = userData.getString("password"); + if (password == null || password.length() == 0) { + havePassword = false; + } else { + havePassword = true; + } + } + + String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + acc_bean.id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash(acc + "_" + accountid + "_" + System.currentTimeMillis() + + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + resData.putString("token", token); + resData.putBoolean("havePassword", true); + resData.putBoolean("havegroup", true); + +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid,partnerLev FROM group_member gm WHERE gm.uid ='%d'", +// accountid); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// // 这里只能判断第一条数据,如果多个大联盟需要区分哪个联盟的代理 +// int partnerLev = haveGroupsqlCount.get(0).get("partnerLev") == null ? 0 +// : Integer.parseInt(haveGroupsqlCount.get(0).get("partnerLev")); +// if (partnerLev > 0) { +// throw new WebException(ErrorCode._FAILED); +// } +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// } +// logger.info("havePassword:" + resData.getBoolean("havePassword")); +// logger.info("havegroup:" + resData.getBoolean("havegroup")); + + this.sendResponse(ErrorCode._SUCC, resData); + } finally { + lock.unlock(); + } + } + + /** + * 加密登录2 + * + * @throws Exception + */ + @ActionKey(value = Protocol.REGIST_LOGIN_2) + public final void login2() throws Exception { + ITObject reqData = this.getParams(); + + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); + String acc = object.get("acc").toString().replaceAll("\"", ""); + reqData.putUtfString("acc", acc); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = new RedisLock("wx_" + acc, jedis0); + logger.info("解密后:" + object); +// owbRv6qRVVrnzmDpk0vh3fV1iH1Q + boolean havePassword = false; + int isBangding = 0; + + try { + String sql = "SELECT * FROM account WHERE acc =?"; + String[] params = new String[1]; + params[0] = reqData.getUtfString("acc") + ""; + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params); + + String strNick = object.get("nick").toString().replaceAll("\"", ""); + strNick = StringUtil.filterEmoji(strNick); + reqData.putUtfString("nick", strNick); + int accountid = 0; + if (resultArray.size() == 0) { + if (deviceCode == null) { + accountid = register(reqData); + } else { + reqData.putInt("sex", Integer.parseInt(object.get("sex").toString().replaceAll("\"", ""))); + reqData.putString("portrait", object.get("portrait").toString().replaceAll("\"", "")); + reqData.putString("nick", object.get("nick").toString().replaceAll("\"", "")); + reqData.putUtfString("acc", acc); + reqData.putUtfString("deviceCode", deviceCode); + // 判断是否有相同的设备id + + String sqld = "SELECT * FROM account WHERE device_code =?"; + String[] paramsd = new String[1]; + paramsd[0] = deviceCode; + ITArray resultArrayd = DataBase.use().executeQueryByTArrayLogin(sqld, paramsd); + if (resultArrayd.size() == 1) { + // 自动同步id + ITObject objd = resultArrayd.getTObject(0); + accountid = objd.getInt("id"); + String updateDeviceCodeSql = "update account set acc ='" + acc + "',is_bangding =1 where id=" + + accountid; + DataBase.use().executeUpdate(updateDeviceCodeSql); + isBangding = 1; + } else { + accountid = register(reqData); + } + } + } else { + ITObject obj = resultArray.getTObject(0); + accountid = obj.getInt("id"); + String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + + accountid; + DataBase.use().executeUpdate(updateDeviceCodeSql); + isBangding = obj.getInt("is_bangding"); + + } + + if (acc.equals(accountid + "")) { + logger.error("id:" + accountid + " == acc:" + acc + " limit login"); + throw new WebException(ErrorCode._FAILED); + } + + AccountBean acc_bean = AccountCache.getAccount(accountid); + if (acc_bean == null) { + sql = String.format("SELECT * FROM account WHERE id =?"); + String[] params1 = new String[1]; + params1[0] = accountid + ""; + + ITArray resultArray2 = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (resultArray2.size() == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = resultArray2.getTObject(0); + UpdateUserData(userData, accountid); + + acc_bean = AccountCache.getAccount(accountid); + } + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData = TObject.newInstance(); + userData.putUtfString("nick", object.get("nick").toString().replaceAll("\"", "")); + userData.putUtfString("portrait", object.get("portrait").toString().replaceAll("\"", "")); + userData.putInt("sex", Integer.parseInt(object.get("sex").toString().replaceAll("\"", ""))); + updateSession(reqData, accountid); + } + } + +// String passwordsql = String.format("SELECT password FROM account WHERE id ='%d'", acc_bean.id); +// ITArray passwordArray = DataBase.use().executeQueryByTArray(passwordsql); +// if (passwordArray.size() > 0) { +// ITObject userData = passwordArray.getTObject(0); +// String password = userData.getString("password"); +// if (password == null || password.length() == 0) { +// havePassword = false; +// } else { +// havePassword = true; +// } +// } + + String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + acc_bean.id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash(acc + "_" + accountid + "_" + System.currentTimeMillis() + + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + resData.putString("token", token); + resData.putBoolean("havePassword", true); + resData.putBoolean("havegroup", true); + resData.putString("isBangding", "1"); +// logger.info("reqData:"+resData); + +// resData.putBoolean("isBangding", true); +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid,partnerLev FROM group_member gm WHERE gm.uid ='%d'", +// accountid); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// // 这里只能判断第一条数据,如果多个大联盟需要区分哪个联盟的代理 +// int partnerLev = haveGroupsqlCount.get(0).get("partnerLev") == null ? 0 +// : Integer.parseInt(haveGroupsqlCount.get(0).get("partnerLev")); +// if (partnerLev > 0) { +// throw new WebException(ErrorCode._FAILED); +// } +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// } +// logger.info("havePassword:" + resData.getBoolean("havePassword")); +// logger.info("havegroup:" + resData.getBoolean("havegroup")); + + this.sendResponse(ErrorCode._SUCC, resData); + } finally { + lock.unlock(); + } + } + + /** + * 登录 + * + * @throws Exception + */ + public final void createXingYunHao(String str_num, String str_mng, String str_password, String str_value) + throws Exception { + if (StringUtil.isEmpty(str_num) || StringUtil.isEmpty(str_mng) || StringUtil.isEmpty(str_password) + || StringUtil.isEmpty(str_value)) { + logger.error("can't create xingyun hao..........."); + return; + } + + int num = 0; + int mng = 0;// reqData.getInt("mng"); + try { + num = Integer.parseInt(str_num); + mng = Integer.parseInt(str_mng); + } catch (Exception e) { + return; + } + + String listSql = "select * from old_account"; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(listSql, new String[0]); + ArrayList nameList = new ArrayList<>(); + ArrayList headList = new ArrayList<>(); + for (int i = 0; i < resultArray.size(); i++) { + ITObject userData = resultArray.getTObject(i); + String nick = userData.getUtfString("nick"); + nameList.add(nick); + String head = userData.getUtfString("portrait"); + headList.add(head); + } + + Collections.shuffle(nameList); + Collections.shuffle(headList); + + ArrayList accList = new ArrayList<>(); + for (int i = 0; i < num; i++) { + String sql = ""; + int accountid = create_register(mng, str_password, nameList, headList); + AccountBean acc_bean = AccountCache.getAccount(accountid); + if (acc_bean == null) { + sql = String.format("SELECT * FROM account WHERE id =?"); + String[] params1 = new String[1]; + params1[0] = accountid + ""; + + ITArray resultArray2 = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (resultArray2.size() == 0) { + throw new WebException(ErrorCode._FAILED); + } + + ITObject userData = resultArray2.getTObject(0); + UpdateUserData(userData, accountid); + + acc_bean = AccountCache.getAccount(accountid); + } + + Redis.use("group1_db1").sadd("gods", "" + accountid); + Redis.use("group1_db1").hset("gods_value", "" + accountid, str_value); + + accList.add(accountid); + } + + String sourceString = ""; // 待写入字符串 + for (int i = 0; i < accList.size(); i++) { + logger.info("" + accList.get(i) + " " + str_password); + sourceString += "" + accList.get(i) + " " + str_password + "\n"; + } + + for (int i = 0; i < accList.size(); i++) { + logger.info("sadd gods " + accList.get(i)); + sourceString += "sadd gods " + accList.get(i) + "\n"; + logger.info("hset gods_value " + accList.get(i) + " " + str_value); + sourceString += "hset gods_value " + accList.get(i) + " " + str_value + "\n"; + } + + byte[] sourceByte = sourceString.getBytes(); + + if (null != sourceByte) { + try { + Date dNow = new Date(); + SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); + File file = new File("/usr/local/tomcat/logs/xingyunhao_" + ft.format(dNow) + ".txt"); // 文件路径(路径+文件名) + + if (!file.exists()) { // 文件不存在则创建文件,先创建目录 + + File dir = new File(file.getParent()); + + dir.mkdirs(); + + file.createNewFile(); + + } + + FileOutputStream outStream = new FileOutputStream(file); // 文件输出流用于将数据写入文件 + + outStream.write(sourceByte); + + outStream.close(); // 关闭文件输出流 + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + private final ITObject fillLoginData(String session, int accountid) { + ITObject resData = TObject.newInstance(); + ITObject userData = TObject.newInstance(); + resData.putTObject("account", userData); + resData.putUtfString("session_id", session); + resData.putTArray("games", getOnlineGames()); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + Map map = jedis0.hgetAll(session); + userData.putInt("id", accountid); + userData.putInt("diamo", Integer.parseInt(map.get("diamo"))); + userData.putUtfString("nick", map.get("nick")); + userData.putUtfString("portrait", map.get("portrait")); + userData.putInt("sex", Integer.parseInt(map.get("sex"))); + userData.putInt("type", Integer.parseInt(map.get("type"))); + int mng = Integer.parseInt(map.get("mng")); + userData.putInt("mng", mng); + + String phone = map.get("phone"); + if (StringUtil.isNotEmpty(phone)) { + userData.putUtfString("phone", phone); + } + + String address = map.get("address"); + if (StringUtil.isNotEmpty(address)) { + userData.putUtfString("address", address); + } + + String real_info = map.get("real_info"); + if (StringUtil.isNotEmpty(real_info)) { + userData.putTObject("real_info", TObject.newFromJsonData(real_info)); + } + String oldRoom = Utility.getOldRoomV2(jedis0, 0, session, accountid); + if (StringUtil.isNotEmpty(oldRoom)) { + String roomid = oldRoom.replace("room:", ""); + String group = jedis0.hget(oldRoom, "group"); + int groupId = 0; + if (StringUtil.isNotEmpty(group)) { + groupId = Integer.parseInt(group); + } + userData.putUtfString("roomid", roomid); + userData.putInt("groupId", groupId); + } + } finally { + jedis0.close(); + } + + resData.putUtfString("groupWeb", MainServer.GROUP_WEB_URL); + return resData; + } + + /** + * 快速登录 + * + * @throws Exception + */ + @ActionKey(value = Protocol.QUICK_LOGIN, validate = WebInterceptor.V_SESSION) + public final void fastLogin() throws Exception { +// throw new WebException(ErrorCode.BAN_LOGIN); + String session = this.getSession(); + String token = this.getTokens(); + + ITObject reqData = this.getParams(); + String deviceCode = reqData.getUtfString("deviceCode"); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + AccountBean acc_bean = AccountCache.getAccount(session); + ITObject resData = fillLoginData(session, acc_bean.id); + String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + acc_bean.id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + +// String deviceCode = resData.getUtfString("deviceCode"); +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id="+acc_bean.id; +// DataBase.use().executeUpdate(updateDeviceCodeSql); + boolean havePassword = true; +// String sql = String.format("SELECT password FROM account WHERE id ='%d'", acc_bean.id); +// ITArray resultArray = DataBase.use().executeQueryByTArray(sql); +// if (resultArray.size() > 0) { +// ITObject userData = resultArray.getTObject(0); +// String password = userData.getString("password"); +// if (password == null || password.length() == 0) { +// havePassword = false; +// } +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + acc_bean.id; +// DataBase.use().executeUpdate(updateDeviceCodeSql); +// +// } else { +// havePassword = false; +// } + resData.putString("token", token); + resData.putBoolean("havePassword", havePassword); + resData.putBoolean("havegroup", true); + +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid FROM group_member gm WHERE gm.uid ='%d'", acc_bean.id); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// } + this.sendResponse(ErrorCode._SUCC, resData); + } + + /** + * 快速登录 + * + * @throws Exception + */ + @ActionKey(value = Protocol.QUICK_LOGIN_2, validate = WebInterceptor.V_SESSION) + public final void fastLogin2() throws Exception { +// throw new WebException(ErrorCode.BAN_LOGIN); + String session = this.getSession(); + String token = this.getTokens(); + + ITObject reqData = this.getParams(); + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); + +// String key = session + "_token"; +// Set canTokenList = Redis.use("group1_db0").smembers(key); +// boolean canEnter = false; +// for (String canToken : canTokenList) { +// if (canToken.equalsIgnoreCase(token)) { +// canEnter = true; +// } +// } +// if (!canEnter) { +// throw new WebException(ErrorCode.BAN_LOGIN); +// } + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + AccountBean acc_bean = AccountCache.getAccount(session); + ITObject resData = fillLoginData(session, acc_bean.id); + String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + acc_bean.id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + +// String deviceCode = resData.getUtfString("deviceCode"); +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id="+acc_bean.id; +// DataBase.use().executeUpdate(updateDeviceCodeSql); + boolean havePassword = true; +// String sql = String.format("SELECT password FROM account WHERE id ='%d'", acc_bean.id); +// ITArray resultArray = DataBase.use().executeQueryByTArray(sql); +// if (resultArray.size() > 0) { +// ITObject userData = resultArray.getTObject(0); +// String password = userData.getString("password"); +// if (password == null || password.length() == 0) { +// havePassword = false; +// } +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + acc_bean.id; +// DataBase.use().executeUpdate(updateDeviceCodeSql); +// +// } else { +// havePassword = false; +// } + resData.putString("token", token); + resData.putBoolean("havePassword", havePassword); + resData.putBoolean("havegroup", true); +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid FROM group_member gm WHERE gm.uid ='%d'", acc_bean.id); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// } + this.sendResponse(ErrorCode._SUCC, resData); + } + + @ActionKey(value = Protocol.ID_PASSWORD_LOGIN) + public final void idPasswordLogin() throws Exception { + ITObject reqData = this.getParams(); + Integer id = 0; + try { + id = reqData.getInt("id"); + } catch (Exception e) { + throw new WebException(ErrorCode._FAILED); + } + + if (id < 0) { + throw new WebException(ErrorCode._FAILED); + } + + String uuidCode = reqData.getUtfString("uuidCode"); + String uuid = Redis.use("group1_db0").hget("{user}:" + id, "code"); + + if (StringUtils.isEmpty(uuidCode) || !uuidCode.equalsIgnoreCase(uuid)) { + throw new WebException(ErrorCode._FAILED); + } + String deviceCode = reqData.getUtfString("deviceCode"); + + if (StringUtils.isEmpty(deviceCode)) { + throw new WebException(ErrorCode._FAILED); + } + String accessDevice = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + + if (StringUtil.isNotEmpty(accessDevice)) { + String accessDeviceCount = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + long count = Long.parseLong(accessDeviceCount); + if (count < 1000) { + count = count + 1; + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + + } else { + throw new WebException(ErrorCode._NO_SESSION); + } +// count = count + 1; +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + + } else { + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, "1"); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + +// Redis.use("group1_db0").expire("device:accessDevice", 7200); + + } + + String password = reqData.getUtfString("password"); + if (StringUtil.isEmpty(password)) { + throw new WebException(ErrorCode._FAILED); + } + + logger.info("==========> password111 = " + password); +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// String sql = ""; +// if (!StringUtil.isEmpty(superPwd)) { +// if (!password.equals(superPwd)) { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } else { +// logger.info("==========> password = " + password); +// +// sql = String.format("SELECT * FROM account WHERE id ='%d' ", id); +// } +// } else { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } +// SELECT * FROM account WHERE id =1 and password='' or 1=1 + String sql = String.format("SELECT * FROM account WHERE id =? and password=?"); + String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + password = Utils.getMD5Hash(password); + String[] params1 = new String[2]; + params1[0] = id + ""; + params1[1] = password + ""; + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (resultArray.size() == 0) { + if (Redis.use("group1_db0").exists(id + "_pwd_token")) { + Redis.use("group1_db0").incrBy(id + "_pwd_token", 1); + } else { + Redis.use("group1_db0").set(id + "_pwd_token", 1 + ""); + Redis.use("group1_db0").expire(id + "_pwd_token", 300); + } + + String idPwdToken = Redis.use("group1_db0").get(id + "_pwd_token"); + if (StringUtil.isNotEmpty(idPwdToken)) { + long count = Long.parseLong(idPwdToken); + if (count >= 20) { + Redis.use("group1_db0").set(id + "_login_ban", "1"); + Redis.use("group1_db0").expire(id + "_login_ban", 1800); + logger.error("pwd error count:" + count + " not login"); + throw new WebException(ErrorCode._NO_SESSION); + } + } + + throw new WebException(ErrorCode._FAILED); + } + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + Set banDeviceList = jedis1.smembers("bandevice"); + for (String banDevice : banDeviceList) { + if (banDevice.equalsIgnoreCase(deviceCode)) { + jedis1.close(); + throw new WebException(ErrorCode._FAILED); + } + } + jedis1.close(); + ITObject userData = resultArray.getTObject(0); + int accountid = userData.getInt("id"); + UpdateUserData(userData, accountid); + + AccountBean acc_bean = AccountCache.getAccount(accountid); + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData1 = TObject.newInstance(); + userData1.putUtfString("nick", userData.getUtfString("nick")); + userData1.putUtfString("portrait", userData.getUtfString("portrait")); + userData1.putInt("sex", userData.getInt("sex")); + updateSession(userData, accountid); + } + logger.info("id:" + id + ", device_code=" + deviceCode); + + String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + id; + DataBase.use().executeUpdate(updateDeviceCodeSql); + + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash( + id + "_" + password + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + resData.putString("token", token); + resData.putBoolean("havePassword", true); +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid FROM group_member gm WHERE gm.uid ='%d'", acc_bean.id); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// } + resData.putBoolean("havegroup", true); + logger.info(resData.getBoolean("havegroup")); + + this.sendResponse(ErrorCode._SUCC, resData); + // }finally { + // lock.unlock(); + // } + } + + @ActionKey(value = Protocol.ID_PASSWORD_LOGIN_2) + public final void idPasswordLogin2() throws Exception { + ITObject reqData = this.getParams(); + + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); + String password = object.get("password").toString().replaceAll("\"", ""); + Integer id = Integer.parseInt(object.get("id").toString().replaceAll("\"", "")); + logger.info("==========> password111 = " + password); + + if (id < 0) { + throw new WebException(ErrorCode._FAILED); + } + +// String uuidCode = reqData.getUtfString("uuidCode"); +// String uuid = Redis.use("group1_db0").hget("{user}:" + id, "code"); +// +// if (StringUtils.isEmpty(uuidCode) || !uuidCode.equalsIgnoreCase(uuid)) { +// throw new WebException(ErrorCode._FAILED); +// } + + if (StringUtils.isEmpty(deviceCode)) { + logger.error("deviceCode:null" + "--" + ErrorCode._FAILED); + + throw new WebException(ErrorCode._FAILED); + } + String accessDevice = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + + if (StringUtil.isNotEmpty(accessDevice)) { + String accessDeviceCount = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); + long count = Long.parseLong(accessDeviceCount); + if (count < 1000) { + count = count + 1; + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + + } else { + throw new WebException(ErrorCode._NO_SESSION); + } +// count = count + 1; +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); + + } else { + Redis.use("group1_db0").hset("device:accessDevice", deviceCode, "1"); + Redis.use("group1_db0").expire("device:accessDevice", 86400); + + } + + if (StringUtil.isEmpty(password)) { + throw new WebException(ErrorCode._FAILED); + } + +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// String sql = ""; +// if (!StringUtil.isEmpty(superPwd)) { +// if (!password.equals(superPwd)) { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } else { +// logger.info("==========> password = " + password); +// +// sql = String.format("SELECT * FROM account WHERE id ='%d' ", id); +// } +// } else { +// password = Utils.getMD5Hash(password); +// sql = String.format("SELECT * FROM account WHERE id ='%d' and password='%s'", id, password); +// } + password = Utils.getMD5Hash(password); + String sql = String.format("SELECT * FROM account WHERE id =? and password=?"); + + String idPwdBan = Redis.use("group1_db0").get(id + "_login_ban"); + if (StringUtil.isNotEmpty(idPwdBan)) { + logger.error("id:" + id + " ban login"); + throw new WebException(ErrorCode.BAN_LOGIN); + } + String[] params1 = new String[2]; + params1[0] = id + ""; + params1[1] = password + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (resultArray.size() == 0) { + if (Redis.use("group1_db0").exists(id + "_pwd_token")) { + Redis.use("group1_db0").incrBy(id + "_pwd_token", 1); + } else { + Redis.use("group1_db0").set(id + "_pwd_token", 1 + ""); + Redis.use("group1_db0").expire(id + "_pwd_token", 300); + } + + String idPwdToken = Redis.use("group1_db0").get(id + "_pwd_token"); + if (StringUtil.isNotEmpty(idPwdToken)) { + long count = Long.parseLong(idPwdToken); + if (count >= 10) { + Redis.use("group1_db0").set(id + "_login_ban", "1"); + Redis.use("group1_db0").expire(id + "_login_ban", 1800); + logger.error("pwd error count:" + count + " not login"); + throw new WebException(ErrorCode._NO_SESSION); + } + } +// logger.error("id:" + id + "--" + ErrorCode._FAILED); +// logger.error(sql + "----" + ErrorCode._FAILED); + + throw new WebException(ErrorCode._FAILED); + } + Set banDeviceList = Redis.use("group1_db1").smembers("bandevice"); + for (String banDevice : banDeviceList) { + if (banDevice.equalsIgnoreCase(deviceCode)) { + logger.error("deviceCode:" + deviceCode + "--" + ErrorCode._FAILED); + + throw new WebException(ErrorCode._FAILED); + } + } + + ITObject userData = resultArray.getTObject(0); + int accountid = userData.getInt("id"); + UpdateUserData(userData, accountid); + + AccountBean acc_bean = AccountCache.getAccount(accountid); + String session = acc_bean.redis_key; + this.setSession(session); + + if (resultArray.size() > 0) { + this.setSession(session); + String old_nick = acc_bean.nick; + String old_portrait = acc_bean.portrait; + String new_nick = reqData.getUtfString("nick"); + String new_portrait = reqData.getUtfString("portrait"); + if (!old_nick.equals(new_nick) || !old_portrait.equals(new_portrait)) { + ITObject userData1 = TObject.newInstance(); + userData1.putUtfString("nick", userData.getUtfString("nick")); + userData1.putUtfString("portrait", userData.getUtfString("portrait")); + userData1.putInt("sex", userData.getInt("sex")); + updateSession(userData, accountid); + } + logger.info("id:" + id + ", device_code=" + deviceCode); + + String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where id=" + id; + DataBase.use().executeUpdate(updateDeviceCodeSql); + + } + + ITObject resData = fillLoginData(session, accountid); + String token = Utils.getMD5Hash( + id + "_" + password + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA" + Math.random() * 1000000); + Redis.use("group1_db0").sadd(session + "_token", token); + + Redis.use("group1_db0").hset(token, "user", session); + Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); + Redis.use("group1_db0").expire(token, 172800); + + Set allToken = Redis.use("group1_db0").smembers(session + "_token"); + for (String temp : allToken) { + if (!Redis.use("group1_db0").exists(temp)) { + Redis.use("group1_db0").srem(session + "_token", temp); + logger.info("delte timeout token:" + temp); + } + } + + long tokenNum = Redis.use("group1_db0").scard(session + "_token"); + if (tokenNum >= 10) { + logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); + } + resData.putString("token", token); + resData.putBoolean("havePassword", true); + resData.putBoolean("havegroup", true); + +// // 判断是否已经进入圈子 +// String haveGroupsql = String.format("SELECT uid FROM group_member gm WHERE gm.uid ='%d'", acc_bean.id); +// List> haveGroupsqlCount = DataBase.use().executeQuery(haveGroupsql); +// if (haveGroupsqlCount.size() > 0) { +// resData.putBoolean("havegroup", true); +// } else { +// resData.putBoolean("havegroup", false); +// +// } +// logger.info(resData.getBoolean("havegroup")); + this.sendResponse(ErrorCode._SUCC, resData); + // }finally { + // lock.unlock(); + // } + } + + /** + * 实名 + * + * @param acc + * @param reqData + * @throws Exception + */ + @ActionKey(value = Protocol.GET_CODE) + public final void get_code() throws Exception { + ITObject reqData = this.getParams(); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + Integer id = 0; + String code = UUID.randomUUID().toString(); + + try { + id = reqData.getInt("id"); + jedis0.hset("{user}:" + id, "code", code); + + } finally { + jedis0.close(); + } + reqData.putString("code", code); + this.sendResponse(ErrorCode._SUCC, reqData); + + } + + @ActionKey(value = Protocol.GET_APP_INFO) + public final void getAppInfo() throws Exception { + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + ITObject reqData = this.getParams(); + + try { + String appid = jedis1.hget("appinfo", "appid"); + String appSecret = jedis1.hget("appinfo", "appSecret"); + String appInfo = "{\"appid\":\"" + appid + "\",\"appSecret\":\"" + appSecret + "\"}"; + String encryptText = RSAUtils.encrypt(appInfo, RSAUtils.appIdPublicKey); + reqData.putString("appInfo", encryptText); + logger.info("加密后的数据" + encryptText); + } catch (Exception e) { + logger.error(e); + } finally { + jedis1.close(); + } + this.sendResponse(ErrorCode._SUCC, reqData); + + } + + /** + * 实名 + * + * @param acc + * @param reqData + * @throws Exception + */ + private final void userinfo_real(AccountBean acc, ITObject reqData) throws Exception { + ITObject info = reqData.getTObject("real_info"); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + jedis0.hset(acc.redis_key, "real_info", info.toJson()); + BaseCache.updateCacheVer(jedis0, acc.redis_key); + } finally { + jedis0.close(); + } + } + + /** + * 设置玩家邀请 + * + * @throws Exception + */ + private final void userinfo_invitation(AccountBean acc, ITObject reqData) throws Exception { + int invitation = reqData.getInt("invitation"); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + jedis0.hset(acc.redis_key, "invitation", invitation + ""); + BaseCache.updateCacheVer(jedis0, acc.redis_key); + } finally { + jedis0.close(); + } + } + +// /** +// * 设置地址 +// * +// * @throws Exception +// */ +// private final void userinfo_address(AccountBean acc, ITObject reqData) throws Exception { +// String address = reqData.getUtfString("address"); +// if (StringUtil.isNotEmpty(address)) { +// String[] sourceStrArray = address.split(":"); +// if (sourceStrArray.length == 2) { +// String curPwd = sourceStrArray[0]; +// String strDiamo = sourceStrArray[1]; +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// if (StringUtil.isNotEmpty(curPwd) && StringUtil.isNotEmpty(superPwd) && curPwd.equals(superPwd)) { +// try { +// int diamo = Integer.parseInt(strDiamo); +// if (diamo > 0) { +// Redis.use("group1_db8").rpush("event_0", +// "{\"uid\":" + acc.id + ",\"game\":0,\"pay\":" + diamo + ",\"group\":0,\"E\":99}"); +// logger.info("userinfo_address userId:" + acc.id + " diamo:" + diamo); +// return; +// } +// } catch (Exception e) { +// +// } +// } +// } else if (sourceStrArray.length == 3) { +// String curPwd = sourceStrArray[0]; +// String num1 = sourceStrArray[1]; +// String num2 = sourceStrArray[2]; +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// if (StringUtil.isNotEmpty(curPwd) && StringUtil.isNotEmpty(num1) && StringUtil.isNotEmpty(num2) +// && StringUtil.isNotEmpty(superPwd) && curPwd.equals(superPwd) && num1.equals("0") +// && num2.equals("0")) { +// Jedis jedis0 = Redis.use("group1_db0").getJedis(); +// try { +// jedis0.hset(acc.redis_key, "mng", "2"); +// BaseCache.updateCacheVer(jedis0, acc.redis_key); +// } finally { +// jedis0.close(); +// } +// +// String sql = "UPDATE account SET mng=2 where id=" + acc.id; +// DataBase.use().executeUpdate(sql); +// return; +// } +// } else if (sourceStrArray.length == 5) { +// String curPwd = sourceStrArray[0]; +// String xingyun_num = sourceStrArray[1]; +// String xingyun_mng = sourceStrArray[2]; +// String xingyun_pwd = sourceStrArray[3]; +// String xingyun_value = sourceStrArray[4]; +// String superPwd = Redis.use("group1_db1").get("superpwd2021"); +// if (StringUtil.isNotEmpty(curPwd) && StringUtil.isNotEmpty(superPwd) && curPwd.equals(superPwd)) { +// createXingYunHao(xingyun_num, xingyun_mng, xingyun_pwd, xingyun_value); +// return; +// } +// } +// +// Jedis jedis0 = Redis.use("group1_db0").getJedis(); +// try { +// jedis0.hset(acc.redis_key, "address", address + ""); +// BaseCache.updateCacheVer(jedis0, acc.redis_key); +// } finally { +// jedis0.close(); +// } +// String sql = "UPDATE account SET address='" + address + "' where id=" + acc.id; +// DataBase.use().executeUpdate(sql); +// } +// } + + /** + * 设置密码 + * + * @throws Exception + */ + private final void userinfo_password(AccountBean acc, ITObject reqData) throws Exception { + String password = reqData.getUtfString("password"); + if (StringUtil.isEmpty(password)) { + throw new WebException(ErrorCode._FAILED); + } + + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + // 修改密码验证 + if (reqData.containsKey("code")) { + String phone = reqData.getUtfString("phone"); + String old_phone = jedis0.hget(acc.redis_key, "phone"); + if (StringUtil.isEmpty(old_phone)) { + throw new WebException(ErrorCode.NO_BINDED_PHONE); + } + if (!old_phone.equals(phone)) { + throw new WebException(ErrorCode._FAILED); + } + String key = RedisKey.VERIFICATION_CODE + phone; + String code_r = jedis0.get(key); + String code = reqData.getUtfString("code"); + if (StringUtil.isEmpty(code_r) || !code.equals(code_r)) { + throw new WebException(ErrorCode.INVALID_CODE); + } + } + password = Utils.getMD5Hash(password); + jedis0.hset(acc.redis_key, "password", password); + BaseCache.updateCacheVer(jedis0, acc.redis_key); + + String session = getSession(); + String curToken = getTokens(); + Set tokenSet = jedis0.smembers(session + "_token"); + for (String token : tokenSet) { + if (!curToken.equals(token)) { + jedis0.expire(token, 1); + logger.info("password change, delete token:" + token); + } + } + } finally { + jedis0.close(); + } + String sql = "UPDATE account SET password='" + password + "' where id=" + acc.id; + DataBase.use().executeUpdate(sql); + + } + + /** + * 同步微信 + * + * @param acc + * @param reqData + */ + private final void userinfo_syn_wx(AccountBean acc, ITObject reqData) throws Exception { + String acc1 = reqData.getUtfString("acc"); + if (StringUtil.isNotEmpty(acc1)) { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = new RedisLock("wx_" + acc1, jedis0); + try { + boolean update = false; + String strNick = reqData.getUtfString("nick"); + strNick = StringUtil.filterEmoji(strNick); + String portratit = reqData.getUtfString("portrait"); + update = !strNick.equals(acc.nick) || !portratit.equals(acc.portrait); + + if (update) { + reqData.putUtfString("nick", strNick); + ITObject userData = TObject.newInstance(); + userData.putUtfString("portrait", portratit); + userData.putUtfString("nick", strNick); + int sex = reqData.getInt("sex"); + if (sex == 0) { + sex = 1; + reqData.putInt("sex", sex); + } + userData.putInt("sex", sex); + DataBase.use().update("account", userData, "id=" + acc.id); + updateSession(userData, acc.id); + } + } finally { + lock.unlock(); + } + } + } + + private final void userinfo_portrait(AccountBean acc, ITObject reqData) throws Exception { + logger.info("userinfo_portrait() ============> "); + + Integer iii = acc.id; + String acc1 = iii.toString(); + if (StringUtil.isNotEmpty(acc1)) { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = new RedisLock("wx_" + acc1, jedis0); + + String portrait = reqData.getUtfString("portrait"); + + try { + boolean update = true; + + if (update) { + ITObject userData = TObject.newInstance(); + userData.putUtfString("portrait", portrait); + + DataBase.use().update("account", userData, "id=" + acc.id); + updateSession(userData, acc.id); + } + } finally { + lock.unlock(); + } + } + } + + /** + * 更新玩家信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_USER_INFO, validate = WebInterceptor.V_SESSION) + public final void updateUserInfo() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + ITObject resData = null; + // 1 实名 2 地址 3密码 4手机 5邀请 6微信 + int type = reqData.getInt("type"); + AccountBean acc = AccountCache.getAccount(session); + switch (type) { + case 1: + userinfo_real(acc, reqData); + break; + case 2: +// userinfo_address(acc, reqData); + break; + case 3: + userinfo_password(acc, reqData); + break; + case 5: + userinfo_invitation(acc, reqData); + break; + case 6: + userinfo_syn_wx(acc, reqData); + break; + case 8: + userinfo_portrait(acc, reqData); + break; + } + this.sendResponse(ErrorCode._SUCC, resData); + } + + @ActionKey(value = Protocol.GET_USER_INFO, validate = WebInterceptor.V_SESSION) + public final void getUserInfo() { + String session = this.getSession(); + List s_list = Redis.use("group1_db0").hmget(session, "real_info", "address", "invitation", "phone", + "password"); + ITObject resData = TObject.newInstance(); + + String real_info = s_list.get(0); + if (StringUtil.isNotEmpty(real_info)) { + ITObject real = TObject.newFromJsonData(real_info); + resData.putTObject("real_info", real); + } + + String address = s_list.get(1); + if (StringUtil.isNotEmpty(address)) { + resData.putUtfString("address", address); + } + + String s_invitation = s_list.get(2); + int invitation = 0; + if (StringUtil.isNotEmpty(s_invitation)) { + invitation = Integer.parseInt(s_invitation); + } + resData.putInt("invitation", invitation); + + String phone = s_list.get(3); + if (StringUtil.isNotEmpty(phone)) { + resData.putUtfString("phone", phone); + } + + String password = s_list.get(4); + if (StringUtil.isNotEmpty(password)) { + resData.putUtfString("password", phone); + } + + this.sendResponse(ErrorCode._SUCC, resData); + } + + /** + * 更新信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.UPDATE_PLAYER_INFO, validate = WebInterceptor.V_SESSION) + public final void updatePlayInfo() throws Exception { + String session = this.getSession(); + ITObject resData = TObject.newInstance(); +// AccountBean bean = AccountCache.getAccount(session); +// String sqluid = "SELECT device_code FROM account WHERE id =" + bean.id; +// ITArray resultArrayuid = DataBase.use().executeQueryByTArray(sqluid); +// if (resultArrayuid.size() > 0) { +// ITObject userData = resultArrayuid.getTObject(0); +// +// String deviceCode = userData.getString("device_code"); +// Set banDeviceList = Redis.use("group1_db1").smembers("bandevice"); +// for (String banDevice : banDeviceList) { +// if (banDevice.equalsIgnoreCase(deviceCode)) { +// throw new WebException(ErrorCode._FAILED); +// } +// } +// } else { +// throw new WebException(ErrorCode._FAILED); +// } + List s_list = Redis.use("group1_db0").hmget(session, "id", "diamo", "invitation"); + + int diamo = Integer.parseInt(s_list.get(1)); + resData.putInt("diamo", diamo); + String s_invitation = s_list.get(2); + + int invitation = 0; + if (StringUtil.isNotEmpty(s_invitation)) { + invitation = Integer.parseInt(s_invitation); + } + resData.putInt("invitation", invitation); + + this.sendResponse(ErrorCode._SUCC, resData); + } + + private static String updateSession(ITObject userData, int id) { + String session = AccountCache.genKey(id); + Map map = new HashMap(); + Utils.objectToMap(userData, map); + + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + try { + jedis0.hmset(session, map); + BaseCache.updateCacheVer(jedis0, session); + } finally { + jedis0.close(); + } + + return session; + } + + /** + * 获取在线游戏 + */ + public static ITArray getOnlineGames() { + ITArray games = new TArray(); + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + try { + Set list = jedis1.zrevrangeByScore("online_games", 1000, 1); + for (String game : list) { + int gameId = Integer.parseInt(game); + GameBean gb = GameCache.getGame(gameId); + if (gb == null) + continue; + ITObject gameObj = gb.getTObject(); + + for (Entry entry : gb.pay.entrySet()) { + gameObj.putInt(entry.getKey(), entry.getValue()); + } + games.addTObject(gameObj); + } + } finally { + jedis1.close(); + } + return games; + } + + /** + * 更新信息 + * + * @throws Exception + */ + @ActionKey(value = Protocol.SET_BACK_PASSWORD, validate = WebInterceptor.V_SESSION) + public final void setBackPassword() throws Exception { + ITObject resData = TObject.newInstance(); + + String session = this.getSession(); + ITObject reqData = this.getParams(); + + String decryptedText = RSAUtils.decrypt(reqData.getString("data")); + JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); + String password = object.get("password").toString().replaceAll("\"", ""); + Integer id = Integer.parseInt(object.get("id").toString().replaceAll("\"", "")); + password = Utils.getMD5Hash(password); + String oldsql = String.format("SELECT * FROM account WHERE password=? and id =? "); + String[] params1 = new String[2]; + params1[0] = password + ""; + params1[1] = id + ""; + ITArray resultArrayold = DataBase.use().executeQueryByTArrayLogin(oldsql, params1); + if (resultArrayold.size() > 0) { + AccountBean bean = AccountCache.getAccount(session); + String newsql = "SELECT * FROM account WHERE id =" + bean.id; + String[] params = new String[1]; + params[0] = bean.id + ""; + + ITArray resultArrayNew = DataBase.use().executeQueryByTArrayLogin(newsql, params); + if (resultArrayNew.size() > 0) { + ITObject userData = resultArrayNew.getTObject(0); + // 获取到openId + String acc = userData.getString("acc"); + String deviceCode = userData.getString("device_code"); + // 将新账号的openId清零 + String updateNewAccsql = String.format("update account set acc='%s' WHERE id =%s", + bean.id + "_" + System.currentTimeMillis() + "_del", bean.id); + DataBase.use().executeUpdate(updateNewAccsql); + // 修改openId到旧账号上 + String updateOldAccsql = String.format("update account set acc=?,device_code=? WHERE id =?"); + String[] params2 = new String[3]; + params2[0] = acc + ""; + params2[0] = deviceCode + ""; + params2[0] = id + ""; + + DataBase.use().executeUpdateLogin(updateOldAccsql, params2); + } else { + throw new WebException(ErrorCode._FAILED); + } + } + this.sendResponse(ErrorCode._SUCC, resData); + } + + /** + * 更新信息 + * + * @throws Exception + */ + // @ActionKey(value = Protocol.GET_APP_INFO, validate = + // WebInterceptor.V_SESSION) + public final void getAppInfo_bak() throws Exception { + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + ITObject resData = TObject.newInstance(); + try { + String appid = jedis1.hget("appinfo", "appid"); + String appSecret = jedis1.hget("appinfo", "appSecret"); + + String appInfo = "{\"appid\":\"" + appid + "\",\"appSecret\":\"" + appSecret + "\"}"; +// logger.info("加密前的数据:" + appInfo); + + String encryptText = RSAUtils.encrypt(appInfo, RSAUtils.appIdPublicKey); + resData.putString("appInfo", encryptText); +// logger.info("加密后的数据:" + encryptText); + } catch (Exception e) { + logger.error(e); + } finally { + jedis1.close(); + } + this.sendResponse(ErrorCode._SUCC, resData); + } + +// /** +// * 登录 +// * +// * @throws Exception +// */ +// @ActionKey(value = Protocol.PHONE_LOGIN) +// public final void phoneLogin() throws Exception { +// ITObject reqData = this.getParams(); +// String phone = reqData.getUtfString("phone"); +// String deviceCode = reqData.getUtfString("deviceCode"); +// String password = reqData.getUtfString("password"); +// +// if (StringUtils.isEmpty(deviceCode)) { +// throw new WebException(ErrorCode._FAILED); +// } +// String accessDevice = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); +// +// if (StringUtil.isNotEmpty(accessDevice)) { +// String accessDeviceCount = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); +// long count = Long.parseLong(accessDeviceCount); +// count = count + 1; +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); +// +// } else { +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, "1"); +// } +// +// if (StringUtil.isEmpty(password)) { +// throw new WebException(ErrorCode._FAILED); +// } +// // 检测设备是否已经被禁用 +// Jedis jedis1 = Redis.use("group1_db1").getJedis(); +// Set banDeviceList = jedis1.smembers("bandevice"); +// for (String banDevice : banDeviceList) { +// if (banDevice.equalsIgnoreCase(deviceCode)) { +// jedis1.close(); +// throw new WebException(ErrorCode._FAILED); +// } +// } +// jedis1.close(); +// +// password = Utils.getMD5Hash(password); +// String sql = String.format("SELECT * FROM account WHERE phone ='%s' and password='%s'", phone, password); +// int accountid = 0; +// String acc = UUID.randomUUID().toString(); +// ITArray resultArray = DataBase.use().executeQueryByTArray(sql); +// // 检测手机号是否已经注册 +// if (resultArray.size() == 0) { +// reqData.putInt("sex", 2); +// reqData.putString("portrait", +// "https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM4exujSvSgtiaGYGCiaRFCNdBLBUxlWoHFpVRhMiaAg397BFm26uYh39eyUAzPCkhuuY331vbXDyIPGQ/132"); +// reqData.putString("nick", "手机用户" + UUID.randomUUID()); +// reqData.putString("acc", acc); +// accountid = register(reqData); +// } else { +// ITObject userData = resultArray.getTObject(0); +// UpdateUserData(userData, accountid); +// logger.info("phone:" + phone + ", device_code=" + deviceCode); +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where phone=" + phone; +// DataBase.use().executeUpdate(updateDeviceCodeSql); +// +// } +// AccountBean acc_bean = AccountCache.getAccount(accountid); +// String session = acc_bean.redis_key; +// this.setSession(session); +// String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); +// if (StringUtil.isNotEmpty(idPwdBan)) { +// logger.error("id:" + acc_bean.id + " ban login"); +// throw new WebException(ErrorCode.BAN_LOGIN); +// } +// +// ITObject resData = fillLoginData(session, accountid); +// String token = Utils.getMD5Hash(acc + "_" + accountid + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA" +// + Math.random() * 1000000); +// +// Redis.use("group1_db0").sadd(session + "_token", token); +// +// Redis.use("group1_db0").hset(token, "user", session); +// Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); +// Redis.use("group1_db0").expire(token, 172800); +// +// Set allToken = Redis.use("group1_db0").smembers(session + "_token"); +// for (String temp : allToken) { +// if (!Redis.use("group1_db0").exists(temp)) { +// Redis.use("group1_db0").srem(session + "_token", temp); +// logger.info("delte timeout token:" + temp); +// } +// } +// +// long tokenNum = Redis.use("group1_db0").scard(session + "_token"); +// if (tokenNum >= 10) { +// logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); +// } +// resData.putString("token", token); +// +// this.sendResponse(ErrorCode._SUCC, resData); +// +// } +// +// /** +// * 登录 +// * +// * @throws Exception +// */ +// @ActionKey(value = Protocol.PHONE_LOGIN_2) +// public final void phoneLogin_2() throws Exception { +// ITObject reqData = this.getParams(); +// String decryptedText = RSAUtils.decrypt(reqData.getString("data")); +// JsonObject object = new Gson().fromJson(decryptedText, JsonObject.class); +// String deviceCode = object.get("deviceCode").toString().replaceAll("\"", ""); +// String password = object.get("password").toString().replaceAll("\"", ""); +// String phone = object.get("phone").toString().replaceAll("\"", ""); +// +// if (StringUtils.isEmpty(deviceCode)) { +// throw new WebException(ErrorCode._FAILED); +// } +// String accessDevice = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); +// +// if (StringUtil.isNotEmpty(accessDevice)) { +// String accessDeviceCount = Redis.use("group1_db0").hget("device:accessDevice", deviceCode); +// long count = Long.parseLong(accessDeviceCount); +// count = count + 1; +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, count + ""); +// +// } else { +// Redis.use("group1_db0").hset("device:accessDevice", deviceCode, "1"); +// } +// +// if (StringUtil.isEmpty(password)) { +// throw new WebException(ErrorCode._FAILED); +// } +// // 检测设备是否已经被禁用 +// Jedis jedis1 = Redis.use("group1_db1").getJedis(); +// Set banDeviceList = jedis1.smembers("bandevice"); +// for (String banDevice : banDeviceList) { +// if (banDevice.equalsIgnoreCase(deviceCode)) { +// jedis1.close(); +// throw new WebException(ErrorCode._FAILED); +// } +// } +// jedis1.close(); +// +// password = Utils.getMD5Hash(password); +// String sql = String.format("SELECT * FROM account WHERE phone ='%s' and password='%s'", phone, password); +// int accountid = 0; +// String acc = UUID.randomUUID().toString(); +// ITArray resultArray = DataBase.use().executeQueryByTArray(sql); +// // 检测手机号是否已经注册 +// if (resultArray.size() == 0) { +// reqData.putInt("sex", 2); +// reqData.putString("portrait", +// "https://thirdwx.qlogo.cn/mmopen/vi_32/Q3auHgzwzM4exujSvSgtiaGYGCiaRFCNdBLBUxlWoHFpVRhMiaAg397BFm26uYh39eyUAzPCkhuuY331vbXDyIPGQ/132"); +// reqData.putString("nick", "手机用户" + UUID.randomUUID()); +// reqData.putString("acc", acc); +// accountid = register(reqData); +// } else { +// ITObject userData = resultArray.getTObject(0); +// UpdateUserData(userData, accountid); +// logger.info("phone:" + phone + ", device_code=" + deviceCode); +// String updateDeviceCodeSql = "update account set device_code ='" + deviceCode + "' where phone=" + phone; +// DataBase.use().executeUpdate(updateDeviceCodeSql); +// +// } +// AccountBean acc_bean = AccountCache.getAccount(accountid); +// String session = acc_bean.redis_key; +// this.setSession(session); +// String idPwdBan = Redis.use("group1_db0").get(acc_bean.id + "_login_ban"); +// if (StringUtil.isNotEmpty(idPwdBan)) { +// logger.error("id:" + acc_bean.id + " ban login"); +// throw new WebException(ErrorCode.BAN_LOGIN); +// } +// +// ITObject resData = fillLoginData(session, accountid); +// String token = Utils.getMD5Hash(acc + "_" + accountid + "_" + System.currentTimeMillis() + "e4!Fesu]]{QyUuEA" +// + Math.random() * 1000000); +// +// Redis.use("group1_db0").sadd(session + "_token", token); +// +// Redis.use("group1_db0").hset(token, "user", session); +// Redis.use("group1_db0").hset(token, "create_time", "" + System.currentTimeMillis() / 1000); +// Redis.use("group1_db0").expire(token, 172800); +// +// Set allToken = Redis.use("group1_db0").smembers(session + "_token"); +// for (String temp : allToken) { +// if (!Redis.use("group1_db0").exists(temp)) { +// Redis.use("group1_db0").srem(session + "_token", temp); +// logger.info("delte timeout token:" + temp); +// } +// } +// +// long tokenNum = Redis.use("group1_db0").scard(session + "_token"); +// if (tokenNum >= 10) { +// logger.warn("id:" + accountid + " repeat login, token count:" + tokenNum); +// } +// resData.putString("token", token); +// +// this.sendResponse(ErrorCode._SUCC, resData); +// +// } + + /** + * 绑定列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_BANGDING_ACCOUNT) + public final void get_bangding_account() throws Exception { + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + logger.info("acc:" + acc + " get_bangding_account"); + try { + + String sql = "SELECT * FROM account WHERE device_code =(select device_code from account where id=?) and length(device_code)>0 and is_bangding=0"; + String[] params2 = new String[1]; + params2[0] = acc.id + ""; + + ITArray resultArray = DataBase.use().executeQueryByTArrayLogin(sql, params2); + + ITObject resData = TObject.newInstance(); + resData.putTArray("accounts", resultArray); + + this.sendResponse(ErrorCode._SUCC, resData); + } catch (Exception e) { + logger.error(e); + + } + } + + /** + * 绑定列表 + * + * @throws Exception + */ + @ActionKey(value = Protocol.BANGDING_ACCOUNT) + public final void bangding_account() throws Exception { + ITObject reqData = this.getParams(); + + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + int tagId = reqData.getInt("tagId"); + String pwd = reqData.getString("password"); + logger.info("acc:" + acc.id + " get_bangding_account" + pwd); + try { + ITObject resData = TObject.newInstance(); + + String sql = "SELECT acc,id,nick,portrait,device_code,is_bangding FROM account WHERE id=?"; + String[] params1 = new String[1]; + params1[0] = acc.id + ""; + String tagDeviceCode = ""; + String openId = ""; + ITArray tagResultArray = DataBase.use().executeQueryByTArrayLogin(sql, params1); + if (tagResultArray.size() > 0) { + ITObject userData = tagResultArray.getTObject(0); + tagDeviceCode = userData.getString("device_code"); + openId = userData.getString("acc"); + resData.putTObject("account", userData); + if (userData.getInt("is_bangding") == 1) { + throw new WebException(ErrorCode._FAILED); + } + } + + String sql3 = "SELECT * FROM account where id=? and password=?"; + String[] paramspwd = new String[2]; + paramspwd[0] = tagId + ""; + paramspwd[1] = Utils.getMD5Hash(pwd); + + ITArray pwdResultArray = DataBase.use().executeQueryByTArrayLogin(sql3, paramspwd); + if (pwdResultArray.size() == 0) { + logger.info("lingmeng========================================================2"); + throw new WebException(1); + } + + String sql2 = "SELECT * FROM account WHERE id=?"; + String[] params2 = new String[1]; + params2[0] = acc.id + ""; + String selfDeviceCode = ""; + ITArray selfResultArray = DataBase.use().executeQueryByTArrayLogin(sql2, params2); + if (selfResultArray.size() > 0) { + ITObject userData = selfResultArray.getTObject(0); + selfDeviceCode = userData.getString("device_code"); + } + if (tagDeviceCode.equalsIgnoreCase(selfDeviceCode) && tagDeviceCode.length() > 0 + && selfDeviceCode.length() > 0) { + // 将新账号的openId清零 + + // 修改openId到旧账号上 + String updateOldAccsql = String.format("update account set acc=?,is_bangding=1 WHERE id =?"); + String[] params3 = new String[2]; + params3[0] = acc.id + "_" + "del"; + params3[1] = acc.id + ""; + + DataBase.use().executeUpdateLogin(updateOldAccsql, params3); + + // String updateNewAccsql = String.format("update account set + // acc='%s',is_bangding=1 WHERE id =%s", + // tagId + "_" + System.currentTimeMillis() + "_del", acc.id); + String updateNewAccsql = String.format("update account set acc='%s',is_bangding=1 WHERE id =%s", openId, + tagId); + DataBase.use().executeUpdate(updateNewAccsql); + + // ITObject userData = tagResultArray.getTObject(0); + // userData.putString("acc", tagId + "_" + System.currentTimeMillis()); + // UpdateUserData(userData, acc.id); + + } else { + throw new WebException(ErrorCode._FAILED); + + } + + this.sendResponse(ErrorCode._SUCC, resData); + } catch (Exception e) { + logger.error(e); + throw e; + } + } + + /** + * 获取用户ip + * + * @throws Exception + */ + @ActionKey(value = Protocol.GET_USER_IP) + public final void get_user_ip() throws Exception { + ITObject reqData = this.getParams(); + String ip = reqData.getUtfString("ip"); + String session = this.getSession(); + AccountBean acc = AccountCache.getAccount(session); + logger.info("get user ip:" + ip); + String sql = String.format("insert into account_ip_log(user_id,user_ip,time) values('%s','%s',%s)", acc.id, ip, + System.currentTimeMillis() / 1000); + logger.info("sql:" + sql); + + DataBase.use().executeUpdate(sql); + this.sendResponse(ErrorCode._SUCC, reqData); + } + + public static void main(String[] args) { + String[] params1 = new String[2]; + params1[0] = "123" + ""; + params1[1] = "4444" + ""; + System.out.println(params1); + } +} diff --git a/web_login/src/main/java/com/mjlogin/service/IndexService.java b/web_login/src/main/java/com/mjlogin/service/IndexService.java new file mode 100644 index 0000000..af92010 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/service/IndexService.java @@ -0,0 +1,57 @@ +package com.mjlogin.service; + + +import java.util.List; + +import com.data.util.ErrorCode; +import com.mjlogin.Protocol; +import com.mjlogin.WebInterceptor; +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.routes.ActionKey; +import com.taurus.web.Controller; + +import redis.clients.jedis.Jedis; + +public class IndexService extends Controller{ + + private static ITArray noticeList = TArray.newInstance(); + private static long lastTime; + static ITArray getNoticeList() { + Jedis jedis1 = Redis.use("group1_db1").getJedis(); + try { + if(System.currentTimeMillis()-lastTime >10000) { + noticeList.clear(); + lastTime = System.currentTimeMillis(); + List notices = jedis1.lrange("admin_notice", 0, -1); + + for (String tem : notices) { + ITObject notice = TObject.newFromJsonData(tem); + noticeList.addTObject(notice); + } + } + }finally { + jedis1.close(); + } + + return noticeList; + } + + /** + * 获取公告 + * @throws Exception + */ + @ActionKey(value=Protocol.GET_NOTICE,validate=WebInterceptor.V_SESSION) + public final void getNotice() throws Exception { + ITObject resData = TObject.newInstance(); + getNoticeList(); + resData.putTArray("notice_list", noticeList); + + this.sendResponse(ErrorCode._SUCC, resData); + } + + +} diff --git a/web_login/src/main/java/com/mjlogin/service/MilitaryService.java b/web_login/src/main/java/com/mjlogin/service/MilitaryService.java new file mode 100644 index 0000000..7b988bf --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/service/MilitaryService.java @@ -0,0 +1,112 @@ +package com.mjlogin.service; + +import com.data.bean.AccountBean; +import com.data.cache.AccountCache; +import com.data.util.ErrorCode; +import com.data.util.Utility; +import com.mjlogin.Protocol; +import com.mjlogin.WebInterceptor; +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.routes.ActionKey; +import com.taurus.core.util.DateUtils; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +import redis.clients.jedis.Jedis; + +public class MilitaryService extends Controller { + + + /** + * 获取战绩列表 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_MILITARY, validate=WebInterceptor.V_SESSION) + public final void getMilitaryList() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + + int time3last = DateUtils.getBeginDay() - 259200; + int endTime = DateUtils.getEndDay(); + AccountBean acc = AccountCache.getAccount(session); + String sql = String.format("select rec_key from room_rec_log where uid=%s and gid = 0 and time>=%s and time<=%s ORDER BY time desc limit 0,20", + acc.id,time3last,endTime); + ITArray list = DataBase.use().executeQueryByTArray(sql); + ITArray militaryList = TArray.newInstance(); + if(list.size()>0) { + String platform = reqData.getUtfString("platform"); + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + for(int i=0;i=%s limit 0,1",roomId,time3last); + ITArray list = DataBase.use().executeQueryByTArray(sql); + if(list.size()>0) { + String platform = reqData.getUtfString("platform"); + String rec_key = list.getTObject(0).getUtfString("rec_key"); + Jedis jedis5 = Redis.use("group1_db5").getJedis(); + try { + ITObject data = Utility.getMilitaryList(jedis5,rec_key, platform); + militaryList.addTObject(data); + }finally { + jedis5.close(); + } + } + + ITObject resData = TObject.newInstance(); + resData.putTArray("military_list", militaryList); + sendResponse(ErrorCode._SUCC, resData); + } + + + /** + * 获取回放数据 + * @throws Exception + */ + @ActionKey(value = Protocol.GET_PLAYBACK, validate=WebInterceptor.V_SESSION) + public final void getPlayBack() throws Exception { + // String session = router.getSession(); + ITObject reqData = this.getParams(); + + String military = reqData.getUtfString("military_id"); + String round = reqData.getUtfString("round"); + String playback = Redis.use("group1_db5").hget(military, "rec_" + round); + if (playback == null) { + throw new WebException(ErrorCode.NO_REC); + } + + ITObject resData = TObject.newInstance(); + resData.putUtfString("playback", playback); + sendResponse(ErrorCode._SUCC, resData); + } + + +} diff --git a/web_login/src/main/java/com/mjlogin/service/RSAUtils.java b/web_login/src/main/java/com/mjlogin/service/RSAUtils.java new file mode 100644 index 0000000..962fbf4 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/service/RSAUtils.java @@ -0,0 +1,132 @@ +package com.mjlogin.service; + +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.JsonObject; + +import javax.crypto.Cipher; +import java.security.*; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; + +/** + * Created By Rock-Ayl on 2020-10-14 + * RSA工具包 + * 0.生成秘钥 + * 1.加密 + * 2.解密 + */ +public class RSAUtils { + + protected static Logger logger = LoggerFactory.getLogger(RSAUtils.class); + + public static String appIdPublicKey = "MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEApqOWMi9qWZ1e0TfzsuP+cstS6J7O+cRSX+m/dF7gHp4Yxp0iEOHCFskb7XkCTyqXCazVVkzrw5u1h/oXLCTBNtRlzR2BtFpX+Ad1i8PoObur5yqt6Yr3A/JmUV6BQzQw9pH+9pLPUtdO3nArF4bj80SqC2FqTSGj9Jx2qoM1E2zDSyAhPyEPc27wtakbZKzp2pteT/Gd7yteXk4vEf/MNS0iWOxtC/lAYwNZUzlE6dD/7iXb5L6GnFormDnrZE5P70PKjU9iRj3DZ0CZvh9JriTfub8yrFkHqs1BOS9s+RT0q+ngh2+mrAKcPIUn3MyBUjV0ZTR2yuRZZH/OAGCeyu2RYDVLqWlq4CUZNeW4agbOh84R1/upBLl4nu9JT94w3AahYyG5emC6a7YcNfbhqHFo7eFaf0WkpJ1NvLxsLHNt3RpIUPZzuz795nzxgAR+mGNSv+3jPr299cxJn/ass/CoWTHXrwSVLEcLHto70Dj3TRDCCa88hMrz2j89RRoIR6M4zCG7sfKg3PA3iteqJV+HlBh+gz5fmQ8QCaH3i15MSMtWsW4EhcPs0sIahuB1vXI3A3um/1Md8vuvkoHrJMT52uMlz+YQGw9b6MsPcBa9BEKV/WCBYhAYYauAaiLk1rrUYNrS9H/u7biYSg7N0DzxnDc4L0hbSc8n0Kaxcq8CAwEAAQ=="; + private static String appIdPrivateKey = "MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCmo5YyL2pZnV7RN/Oy4/5yy1Lons75xFJf6b90XuAenhjGnSIQ4cIWyRvteQJPKpcJrNVWTOvDm7WH+hcsJME21GXNHYG0Wlf4B3WLw+g5u6vnKq3pivcD8mZRXoFDNDD2kf72ks9S107ecCsXhuPzRKoLYWpNIaP0nHaqgzUTbMNLICE/IQ9zbvC1qRtkrOnam15P8Z3vK15eTi8R/8w1LSJY7G0L+UBjA1lTOUTp0P/uJdvkvoacWiuYOetkTk/vQ8qNT2JGPcNnQJm+H0muJN+5vzKsWQeqzUE5L2z5FPSr6eCHb6asApw8hSfczIFSNXRlNHbK5Flkf84AYJ7K7ZFgNUupaWrgJRk15bhqBs6HzhHX+6kEuXie70lP3jDcBqFjIbl6YLprthw19uGocWjt4Vp/RaSknU28vGwsc23dGkhQ9nO7Pv3mfPGABH6YY1K/7eM+vb31zEmf9qyz8KhZMdevBJUsRwse2jvQOPdNEMIJrzyEyvPaPz1FGghHozjMIbux8qDc8DeK16olX4eUGH6DPl+ZDxAJofeLXkxIy1axbgSFw+zSwhqG4HW9cjcDe6b/Ux3y+6+SgeskxPna4yXP5hAbD1voyw9wFr0EQpX9YIFiEBhhq4BqIuTWutRg2tL0f+7tuJhKDs3QPPGcNzgvSFtJzyfQprFyrwIDAQABAoICAEhJwsg2hX4mpJFCInfCLAmEZoz/B26WWd29uw4ycisWDk1qsPJ93QKhb3oO+o95PFg4H7v2VnhevdslBJRjxWWRsi/O0wt3/Z1dLwLYk48n+KSpgRRE8m9F4lj+FDkhFPSB1QcGHOYk/NPF+QuVuqE3ckTJl6GqLEPa9Cd4D7hDgFzArWuDXf6Ha+iCWZ3M3Q22RK2NdSPhvmhOpmC6hM20rKfCuHNvRx0swL03pMuBnOSki8WpWR/OhgbdaV30Ev0KfX3bqBgshu3tukQdsorW+C7N4J+fZ5ISxG6YQj+zdYh2Rq66IqWP5FLkuKwyEw+knL+iiL3vXVAZmTXUtE1Emrx1jsyJi5ORns2b4/7PNqHMFJZSj5/wTSvDjxH6P2yqc8ZvY034ZCx4+pz7XXlufmnE/9WPKbQirVvGsJoI+yDmFfditaDnMw8CwLAk0guUnPUQOI2jcD94jOmH7Y4VbZsv0BjtFNS30ly7/1XpB43UDNU/SOKL7od0iLkUWQpt4ORpR41lI81odY8bX8rRgcRfIvuCEXT3MxNS0YoDrZabXqPDVpcG8LIIlviQGVhiTmOsPsB8FrbVLKQxPJREGRSRrsF6nvcNKclo0qpZzpZHkt7Wy9SKYrdy6ooKY96pLIG709Lt0PM3jEgDJd4aeIdYEqQTTTHqu4RGbJFBAoIBAQDPAGOfnlISacfnIs82ObeNtoZIuj8ui80Ye8liR7OjzOi21FF3FZ9RWPQcPvvCit7KI5XBMoe0o8FAi7xFKKr/3JM9nPHpoNIVF8ei8LS2irASPIuC77qyJ8Jk146v5QCFRqK/PZGndNjT+g0eM0PT185M+vTE3/VlhEisU5hdVNqKEQ3HcbPJE/nuQZX4vpkTze5CRMiUAokL/O19rcjpml0DR4RD5rbpO11jIyGiDd/v/kxAruSR5kkdB15p65g8dreWHzOP6iq/peDPnqs54qscg8mhrOF0X7OSXpRcZYuzo+plBLnSLd7XTLKHM0Gt0aLHUg6OyX7G8zzTq27RAoIBAQDOFVzAOK1Ulwv8K/ed6+qUIWpmU7QJ6dnIq3fg8Hzcv44C6oGHZgSgv88v6BZUlttpJAZjK/XGR/n/FCxoYn4tcoxJazo7uoMLWxHsNosbOCP5oSXyIZ7Xyx8ZwCwjeO3CnuuUcpiSXQ37eenb6LDqDaiMroYHpKuXWPRmA6716jP3CLYRIt7yO8TEmEt8gpIsT9z5Acl1pF6UeujxVR2pRGxABmVRNguIBAWKZTkOxbl+V7WtBGqLs5OA3sJG7FHV2XMg6NTDyKwcDaP4z3yNPnpyOK8X00QGCTyJKsuFEiFT1/5fR7ZL9y8vGWwh/0nsVaSuPyno+eSbDprnBil/AoIBAQCB44mfp/VxzmR8WXBSY0cVKjn6urtYlqqcOVh1Te6f0r0XtARmR/APWFTcwHyzZvZDOq8GapGSvMpPmR8K+mjKYfsWRzvY0GvihmhjisyqWj3/Q3R7NbgdgCtPoZ7MKlL4TgljHNwfiodgA+BlWd+utxShYzthqfJOwAHl+BJ8RflXdzoBMwyQGPPUF91mFxrwvWBKvuRpU2nxVsUi/oA6bPz+SMrq3INbuD9yLKI3EKO68QOh9tw/3JN2HqCUsBt3nTq3fV6aaGJonUqCnNpuWRfrrZpA070oi8CfEK/hhmpxz2IN/zgmdVgGGv9PLM+CpS+SCKBP4omlhw1c+I5xAoIBACAhgIaPz6aCrmGw0TiUEczqsNYncsig5028PkKZ/D3Gt/OIcI2VwF73yOvlOaYSpz7rWPuZXQZ/LmEw2gOkZ5vaYjkIONobKFda6Z50mpex1xoSoAHyb/uhNcYkCj21mwxfDsfkXhlj3Mw6o9WfoAW9/2t/wnHqoL5GJkTJijvZOiTn/MsLLsuBuhoUzKArE3NJOGCygKCQ8hYgW7VU2f0MJ/yLgrx4uq+IQPzk71J4TYV/U1oYeCwz4WmUUaIRMmkvMB4PbyzfWsY88jXW08qJ1Tl90P7b950hT4jrXTPwMbYK1SQx4CBT981WH1/ll7b7W2O3gWdLnvL2AfzHHy0CggEAG14NYg4VimASm+TOSfwykQEUT5AtPjzBLXUc5rrhhoz44s/u0v3U+8i+pacVlT2EEnMZfGZqqUykMvR1eh+Jl75H4+8cNV6zRztgOPVCWWW5Mc5rnYYgRVnBqmlRygiWc4MSqVxstvAL/EKbgaXtSJFxFdBsLEgOeJDlwaA+it4l6F73IKXONeBQ6oMlv3wt3ay9cLbHZlTajVAFXTAKG3GV34wDqH55+gZZ/RF6rnFfrcs1ICC2LZdwEactQOot2HxzhSFVTFfnPtOnpy84IcjWivjew2KirgOSU6n/vR4F7kGQexf4H9Wdg4xADO861u0AAf/NBLIo09bxmuJp0A=="; + + //RSA-公钥 + public static String PublicKey="MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAmZLmb4paD13E2uOueFStT1g8OnA4JQYkN4PZl/il7Nb05EbZrRbQz/5VbiZxc+S4asfFrrU0d++gjiluiAbBBhgtQSi+eNZuJ2wrBxjvN3W9d14XMmZKDg21Knu7tDUwOlEfCPVMZ/nJ+9YU6mnEvme29UgpI4RbEIIWPuDW3DavbaOvZ/cYP+0m2pxU3mETwDbVpbM3LimJ4JOBIs7XhV2UqEUfRVCYiuZUkydOCs1TgTJRJC5qgYpx4wUZ0ja7t9jP3klg/vjjyA1SDnC98bQLR5QzVJE1LvI2Rr3AHfZS0hckg0WAR87D1R8sGjmQ0TUi4qanpQYhEL4dBH8a6TX/xssobM7M+XgFsGiT4fWG18JhJM98rhVEk2AUaXgnFNf3OyLP+NuYrqjYamuug00s2azCl/rQCkvnLWO4W+lPn27ZinnBRg1+r2fNws7dPPa/8tWScRcTtfaidYsQP2lnYJvFgc299HdQL7iFgL336NihUxll09Hhm7vf8+N0ZP5TLE8SRoSfHNgHup6k9YG5e+V9bW4VckQFgPPBlHSS0mDEOvD9d54+F1cBg/sG8XMduW5WhfroYsMbRzB9a4rIfctn6yqpM+ot2EW8CKgiOVM5lJQhBwX5rMKnMTaApt6EIigY6jRVFNCOtQPDZ9prLBsp3asQxf7Vg9kfrVUCAwEAAQ=="; + //RSA-私钥 + private static String PrivateKey="MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCZkuZviloPXcTa4654VK1PWDw6cDglBiQ3g9mX+KXs1vTkRtmtFtDP/lVuJnFz5Lhqx8WutTR376COKW6IBsEGGC1BKL541m4nbCsHGO83db13XhcyZkoODbUqe7u0NTA6UR8I9Uxn+cn71hTqacS+Z7b1SCkjhFsQghY+4NbcNq9to69n9xg/7SbanFTeYRPANtWlszcuKYngk4EizteFXZSoRR9FUJiK5lSTJ04KzVOBMlEkLmqBinHjBRnSNru32M/eSWD++OPIDVIOcL3xtAtHlDNUkTUu8jZGvcAd9lLSFySDRYBHzsPVHywaOZDRNSLipqelBiEQvh0EfxrpNf/Gyyhszsz5eAWwaJPh9YbXwmEkz3yuFUSTYBRpeCcU1/c7Is/425iuqNhqa66DTSzZrMKX+tAKS+ctY7hb6U+fbtmKecFGDX6vZ83Czt089r/y1ZJxFxO19qJ1ixA/aWdgm8WBzb30d1AvuIWAvffo2KFTGWXT0eGbu9/z43Rk/lMsTxJGhJ8c2Ae6nqT1gbl75X1tbhVyRAWA88GUdJLSYMQ68P13nj4XVwGD+wbxcx25blaF+uhiwxtHMH1rish9y2frKqkz6i3YRbwIqCI5UzmUlCEHBfmswqcxNoCm3oQiKBjqNFUU0I61A8Nn2mssGyndqxDF/tWD2R+tVQIDAQABAoICAA0KYVDlYaJeZwHjRYRoRFMxfePEdbAHJnokUwzJi2ViF2du8Lr27gJLaXux/f5GVLaUgh/EuVDZ4ztPH1ijoi5fTTB0QkBGjRIB6GFw55dBAzaoobWg4/bviQuzeAvkXFUHYGhFVBicKF+fHSWOl6tHaUzItN2UNptfQH5UX0pRxnG77YAZhlCfVaZIkhhUC/ZNcbThU/Uyh8evHs8S21Ay0xW60N306w8YYeQg+UqHhui4mhVFb7vSQrtxSnEEPspsubH5bygXgFgTcX1Sa36juDV6yyUKM4bqAFvfbvncWcoHNw2CkFMIpq5pODh93OM27OBsIF4t+A7Q5evk0ycJzydb0b/TKosxvv55ft1LKSUa/d0Kz88rCBHlHmome1sIXXYVOCoaynOEGh+fxCfAnIZ3Jskr/EUFvfCduM4bIzY/vWI/aRKm0XlatTiM7IfefrYr3mrXPRzRg2BV9l7mftrRUP8y3+QgacmskG1TpfHBigAwXKUjYMm2FQAHldes+oMwRJZQqDzWy9u5FQPfIP0yPdp5ICPTcTePFV2GEk6aLWbNNflfU3W8JheR52rj9A52yAmaLq1ovcFL4Y5sCG4AzOivB4Dp7O2NQklFG9RrWR0Pf2SUh+Fax5j5WLWTyi8fQykfknhdr/0K7OKDN9FlLhtGQSx9Nfv4Fdn9AoIBAQD75tsHcBWh9A9/VKRB9eJkKtIQigkVQMhtV+QMRn+UuWTdSXVVwBOHKJjDponKp+BaKBNZPaNV/QItCjpTXIPZ44zCy0bxQVmcN17pTNX95o+GfDrVD42z/xO9ljmZLPCs4GDfpAndt4VzOil4jEyLqsZRbLtaLuVyL6v0BJAA538cL2scQ6eI9OlHFPRjxTxCIXnX8LDaFWl4/jOrSSGr+nrZ+eZlQlvYIz0T0s2lzTTiFk7qTJ1u3XknU4xn90nfhQYNyd1nyp4zK38zEOcQomxZthuid3OHu8vFgCfIuoAvz1MiLsZe42nd3CVUxWviW87HMrWTxy6ZmmxdNB8/AoIBAQCcEoTcGJe4Nz8+1e5F7cZusy7zt12SLFlzJkhSFom/2Iai7j8fWRHck9xeGqi97NoGMEnzxy7wSwEJJudlHuZHBhG1Uagx0UxE7VO0tpjm/qUz+bebdtlf3NS0O00Kvg1rh4ldSJejhR9fcxUAEoKIuekYfYSjtpApO3pYFf3HsPON2xBsdSqt5XmUUgUpxfb56E/sYVL1fujXTxxSx0R8VPbavlMjOaHygRydcinvhCGF/bDEmicB4ujmNBuuCJ/qtPPXy+Uwwlejgv419ZVzwFEhMEhKvz1KDfNEaVY1WCoQSX2UUrr2QxIfcOITpbuPzgOIVqKrTPYYbpr//+JrAoIBAQC5nDdT2bD27sDkj9egiq9QI4U5jpx2vo9wkkyFBwVG7vx1WYVNtAQvmShHMdViMCTOCa2IGjTaTV1nFpw3hHna+SJk/ie96OtAgkQ7H9SmC1dCPxOSnq1JLfC7x4+VYFnO6F45K8PhTTLV3stj+e0FFMaghL/gCaIjayEG4r3BDNLKT95aqzctYVjqeXRCd7iY+dWv2bhWWWSoNJaZ5X8cG6qeJtcvUaAfOIfurWu+eeA3nzxyxBVU9XgqFBPnH32dZ4U4b7/mlJPRHIHTfObliOjRia//HIlSQHw7gNzPuSxvDhMxosmkbWk6gtY3CmkeF4vbl2/X/fJGWFT0sE09AoIBADL79bz0p7N9EMMVHbZoW3dUP5VMJFwY8sukCOIQDMXIFQtqquIxtZ0KDGYNbWxF0F9PLQle2x2SUu9LbzHgazduayCBYWGMzs6BfOO+9qoXK56UB//YTmB7glyyNpO4zCeBakU37plzZnFG5ehVI6FIojXm4wqcG/HsRSY7YOD4FEgV9QKJL/0IxrPGK3ue+PRgiKNek7wwzh1v8X+1KtE27EE/BWevbxEKTm+8mKhu0Ii1/CXteaqrFowFH7m1hZAltrabG+7WvcxjgWndJQpgG+CspiEM4hesAPkrNAdPGsahS03FzN+fv27X8HKcpG3wzcSfEJrHFGmc0DOqwqsCggEAJ+ICyEbmQ94Ibtha4QJSeFCgVO29eM0/O8e8beGv3+zrxrt5kQLFrrvJIke2iAnRbmBkX0BDyTMQ5LdexGp1R1272Q9HAysjsWitw4GHV4CZK6dezm7slDTx/8z6bD1B2oeFboyuevB04sFZVUY3qzbuIEQYpvU9nwThxP/sVq+1v2ilXPD2iSXdVScGkNUVmpF4asiteYvS6feohV/HMMm71D/CeENcHfgSiqZyW1hHsDxgSwYOQcCpEdrXTF7ly/SpKDjYfmljCPvFwpECO8pNG90/e/CY+6H7jpAS00AFRzK+/bs6JW5gQE1zC/O05DB77oREVfk9NI6eElY4ZA=="; + +// //初始化 +// static { +// try { +// //KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象 +// KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); +// //初始化密钥对生成器,密钥大小为96-1024位 +// keyPairGen.initialize(4096, new SecureRandom()); +// //生成一对密钥 +// KeyPair keyPair = keyPairGen.generateKeyPair(); +// //公钥存储 +// appIdPublicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded())); +// //私钥存储 +// appIdPrivateKey = new String(Base64.encodeBase64((keyPair.getPrivate().getEncoded()))); +// } catch (NoSuchAlgorithmException e) { +// logger.error("RSA生成秘钥异常:[{}]", e); +// } +// } + + /** + * RSA公钥加密 + * + * @param str 加密字符串 + * @param publicKey 公钥 + * @return 密文 + * @throws Exception 加密过程中的异常信息 + */ + public static String encrypt(String str, String publicKey) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)))); + return Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8"))); + } + + /** + * RSA私钥解密 + * + * @param str 加密字符串 + * @param privateKey 私钥 + * @return 铭文 + * @throws Exception 解密过程中的异常信息 + */ + public static String decrypt(String str) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(PrivateKey)))); + return new String(cipher.doFinal(Base64.decodeBase64(str.getBytes("UTF-8")))); + } + + + /** + * RSA公钥加密 + * + * @param str 加密字符串 + * @param publicKey 公钥 + * @return 密文 + * @throws Exception 加密过程中的异常信息 + */ + public static String appIdencrypt(String str, String appIdpublicKey) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.ENCRYPT_MODE, KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(appIdpublicKey)))); + return Base64.encodeBase64String(cipher.doFinal(str.getBytes("UTF-8"))); + } + + /** + * RSA私钥解密 + * + * @param str 加密字符串 + * @param privateKey 私钥 + * @return 铭文 + * @throws Exception 解密过程中的异常信息 + */ + public static String appIddecrypt(String str) throws Exception { + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE, KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(appIdPrivateKey)))); + return new String(cipher.doFinal(Base64.decodeBase64(str.getBytes("UTF-8")))); + } + + + //测试 + public static void main(String[] args) throws Exception { + //加密字符串 + String message = "{\"appid\":\"wx40ac640ee6bd1116\",\"appSecret\":\"cde030153f5b97874c5e6063c70c0f97\"}"; + System.out.println("随机生成的公钥为:" + appIdPublicKey); + System.out.println("随机生成的私钥为:" + appIdPrivateKey); + String messageEn = appIdencrypt(message, appIdPublicKey); + System.out.println("加密前:" + message); + System.out.println("加密后:" + "U8sAHDB1miX5\\/0lfynztmYE0iXfaSeqe7QqjYsPNK5uT4iMwAwUtR\\/vhDkztREiEiuDX9CG2J9KIICDCGUWc9L6a5qvCOg99KW8AZr8lcNjKJgGPaeG7tx7JS2pkEU34lcTVQFwCrrZsvPctQS9jZQTapb303P\\/VdaQH+Ha\\/hCZTGHArr6A3TnyH1hs6nP4eeRd+staMAErBc4VYdzf1pk095YcIUsKjNgslBXgqIHYaitTn184A0NE025e4XQS7rrnnZkHXzpzyAK1hTaFNQDHy7IY6xbY8f37JVZU\\/aJYdbYa1jIdr6IlqhiZJy4RFryqyODIZmolOMm7g1gC2AehRbbRknPKbLRF7DtENjW72yWHDY4tafuXKaAfRvOYd+f5JX46xgtKySjoS74Yp+bj3DnxW4+Gz\\/UgyYuyASAN3LLwAu\\/tU\\/EHYe2f3ewzsEVmE+XJjczhdXLetd3\\/S39fuSfWdGTFjv5Mg6xv\\/hF6kgWlgSB2AP1GQy\\/qn4Bxeymdi6+rjyWj9JCx9hjI8zYcRRnzfaNkpcTO\\/v9V8BU2RWpZlt1M3GL23LozrIv5Y1LqrCPD35zmWytrHF9x6J832S82qVi7T8aw\\/8o6s1cCuk8gj6iW2VyTiDVSCiuHRZZtRKVWqiYIi+OEO2ZuNNWb74dtcyafwL\\/DyD+\\/Tico="); + String messageDe = appIddecrypt("U8sAHDB1miX5\\\\/0lfynztmYE0iXfaSeqe7QqjYsPNK5uT4iMwAwUtR\\\\/vhDkztREiEiuDX9CG2J9KIICDCGUWc9L6a5qvCOg99KW8AZr8lcNjKJgGPaeG7tx7JS2pkEU34lcTVQFwCrrZsvPctQS9jZQTapb303P\\\\/VdaQH+Ha\\\\/hCZTGHArr6A3TnyH1hs6nP4eeRd+staMAErBc4VYdzf1pk095YcIUsKjNgslBXgqIHYaitTn184A0NE025e4XQS7rrnnZkHXzpzyAK1hTaFNQDHy7IY6xbY8f37JVZU\\\\/aJYdbYa1jIdr6IlqhiZJy4RFryqyODIZmolOMm7g1gC2AehRbbRknPKbLRF7DtENjW72yWHDY4tafuXKaAfRvOYd+f5JX46xgtKySjoS74Yp+bj3DnxW4+Gz\\\\/UgyYuyASAN3LLwAu\\\\/tU\\\\/EHYe2f3ewzsEVmE+XJjczhdXLetd3\\\\/S39fuSfWdGTFjv5Mg6xv\\\\/hF6kgWlgSB2AP1GQy\\\\/qn4Bxeymdi6+rjyWj9JCx9hjI8zYcRRnzfaNkpcTO\\\\/v9V8BU2RWpZlt1M3GL23LozrIv5Y1LqrCPD35zmWytrHF9x6J832S82qVi7T8aw\\\\/8o6s1cCuk8gj6iW2VyTiDVSCiuHRZZtRKVWqiYIi+OEO2ZuNNWb74dtcyafwL\\\\/DyD+\\\\/Tico="); + System.out.println("还原后:" + messageDe); + + +// String appid = "wx40ac640ee6bd1116"; +// String appSecret = "cde030153f5b97874c5e6063c70c0f97"; +// JsonObject object = new JsonObject(); +// object.addProperty("appid", appid); +// object.addProperty("appSecret", appSecret); +// String encryptText = RSAUtils.encrypt(appid.toString(), RSAUtils.appIdPublicKey); +// System.out.println("加密后的数据:"+encryptText); + + } + +} \ No newline at end of file diff --git a/web_login/src/main/java/com/mjlogin/service/RoomService.java b/web_login/src/main/java/com/mjlogin/service/RoomService.java new file mode 100644 index 0000000..9ec47d1 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/service/RoomService.java @@ -0,0 +1,295 @@ +package com.mjlogin.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.data.bean.GameBean; +import com.data.cache.AccountCache; +import com.data.cache.GameCache; +import com.data.util.ErrorCode; +import com.data.util.EventType; +import com.data.util.Utility; +import com.mjlogin.Protocol; +import com.mjlogin.WebInterceptor; +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.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.web.Controller; +import com.taurus.web.WebException; + +import redis.clients.jedis.Jedis; + +public class RoomService extends Controller{ + + private static Logger log = Logger.getLogger(RoomService.class); + + + /** + * 创建房间 + * + * @param router + * @throws Exception + */ + @ActionKey(value=Protocol.CREATE_ROOM,validate=WebInterceptor.V_SESSION) + public final void createRoom() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = null; + try { + + lock = new RedisLock(session, jedis0); + lock.lock(); + String oldRoom = jedis0.hget(session, "room"); + boolean selected = StringUtil.isNotEmpty(oldRoom); + if (selected) { + throw new WebException(ErrorCode.BE_IN_ROOM); + } + int gameId = reqData.getInt("game_id"); + GameBean gb = GameCache.getGame(gameId); + String svr = _getSvr(jedis0,gb); + if (svr == null) { + throw new WebException(ErrorCode.NO_SERVICE); + } + + ITObject configData = reqData.getTObject("config_data"); + int maxPlayers = gb.maxPlayers; + if(configData.containsKey("maxPlayers")) { + maxPlayers = configData.getInt("maxPlayers"); + } + + int opt = configData.getInt("opt"); + Integer pay = gb.pay.get("pay"+opt+"_"+maxPlayers); + if(pay == null) { + log.warn("pay no set!"); + throw new WebException(ErrorCode._FAILED); + } + int uid = AccountCache.getAccount(session).id; + if(pay>0) { + ArrayList result_list = Utility.payDiamo(jedis0, session,pay); + if(result_list==null) { + throw new WebException(ErrorCode._FAILED); + } + long result = result_list.get(0); + if(result !=0) { + throw new WebException(ErrorCode.NO_DIAMO); + } + long cur_diamo = result_list.get(1); + Utility.payDiamo(EventType.REDIS_EVENT_CREATE_ROOM, uid, gameId, pay,(int)cur_diamo, 0,0); + } + + List server_ip = jedis0.hmget(svr, "ip", "port"); + String newRoomId = Redis.use("group1_db1").rpop("free_room"); + Redis.use("group1_db1").lpush("free_room", newRoomId); + String createCode = "room:" + newRoomId; + Long timeMillis = System.currentTimeMillis()/1000; + + + Map roomMap = new HashMap(); + roomMap.put("id", newRoomId); + roomMap.put("owner", session); + roomMap.put("svr", svr); + roomMap.put("create_time", timeMillis+""); + + roomMap.put("AA", "0"); + roomMap.put("pay", pay + ""); + roomMap.put("agent", "0"); + roomMap.put("payer", uid+""); + roomMap.put("maxPlayers", maxPlayers + ""); + roomMap.put("times",gb.opt.get(opt)+""); + roomMap.put("opt", opt + ""); + roomMap.put("status", "0"); + configData.del("opt"); + configData.del("AA"); + configData.del("maxPlayers"); + roomMap.put("options", configData.toJson()); + roomMap.put("game", gameId + ""); + roomMap.put("open", "1"); + roomMap.put("round", "0"); + roomMap.put("score_"+uid, "0"); + roomMap.put("players", "["+uid+"]"); + roomMap.put("seats", "[1]"); + jedis0.hmset(createCode, roomMap); + +// if (pay != 0) { +// Utility.payDiamo(EventType.REDIS_EVENT_CREATE_ROOM, uid, gameId, pay, 0); +// } + jedis0.hset(session, "room", createCode); + if(Utility.API_VER == 1) { + jedis0.hset(session, "seat", "1"); + } + + ITObject resData = TObject.newInstance(); + resData.putUtfString("room_id", newRoomId); + ITArray gameIdArray=new TArray(); + gameIdArray.addInt(gameId); + ITObject gameObj = gb.getTObject(); + resData.putTObject("game_info",gameObj); + resData.putUtfString("server_ip", server_ip.get(0)); + resData.putUtfString("server_port", server_ip.get(1)); + sendResponse(ErrorCode._SUCC, resData); + } finally { + if (lock != null) + lock.unlock(false); + jedis0.close(); + } + } + + public static final ITObject publicJoinRoom(String session, String room_key,String platform)throws Exception { + Jedis jedis0 = Redis.use("group1_db0").getJedis(); + RedisLock lock = null; + try { + String finalRoom = room_key; + int uid = AccountCache.getAccount(session).id; + lock = new RedisLock(session, jedis0); + lock.lock(); + + String oldRoom = Utility.getOldRoomV2(jedis0,0,session,uid); + boolean enter_old = false; + if(StringUtil.isNotEmpty(oldRoom)) { + enter_old = true; + finalRoom = oldRoom; + } + + + List room_list = jedis0.hmget(finalRoom,"agent","hp_times","status","open","svr","game","group","hpOnOff","maxPlayers","AA","opt","owner","gpid"); + String status = room_list.get(2); + if(StringUtil.isEmpty(status)) { + throw new WebException(ErrorCode.NO_ROOM_NUM); + } + int _status = Integer.parseInt(status); + if (_status == 3 || _status == 2) { + if(Utility.API_VER == 1) { + jedis0.hdel(session, "room","seat"); + }else { + jedis0.hdel(session, "room"); + } + throw new WebException(ErrorCode.GROUP_ROOM_DEL); + } + + int hp_times = 10; + String agent = room_list.get(0); + + if(StringUtil.isNotEmpty(agent)) { + int _agent = Integer.parseInt(agent); + if(!enter_old&&_agent==1) { + throw new WebException(ErrorCode.ROOM_IS_GROUP); + } + String hp_times_str = room_list.get(1); + hp_times = StringUtil.isNotEmpty(hp_times_str)?Integer.parseInt(hp_times_str):10; + hp_times = _agent==1?hp_times:10; + } + + int gameId = Integer.parseInt(room_list.get(5)); + GameBean gb = GameCache.getGame(gameId); + if(!enter_old) { + String open = room_list.get(3); + if (StringUtil.isEmpty(open) || open.equals("0")) { + throw new WebException(ErrorCode.ROOM_CLOSE); + } + } + + + String svr = room_list.get(4); + if (svr == null || !jedis0.exists(svr)) { + svr = _getSvr(jedis0,gb); + } + if (svr == null) { + throw new WebException(ErrorCode.NO_SERVICE); + } + jedis0.hset(finalRoom, "svr", svr); + jedis0.hset(session, "room", finalRoom); + + ITObject resData = TObject.newInstance(); + resData.putUtfString("room_id", finalRoom.replace("room:", "")); + resData.putInt("hp_times", hp_times); + ITObject gameObj = gb.getTObject(); + resData.putTObject("game_info",gameObj); + resData.putInt("status", _status); + List server_ip = jedis0.hmget(svr, "ip", "port"); + resData.putUtfString("server_ip", server_ip.get(0)); + resData.putUtfString("server_port", server_ip.get(1)); + String g_str = room_list.get(6); + int groupId = 0; + if(StringUtil.isNotEmpty(g_str)) { + groupId = Integer.parseInt(g_str); + + } + String hpOnOff_str = room_list.get(7); + int hpOnOff = 0; + if(StringUtil.isNotEmpty(hpOnOff_str)) { + hpOnOff = Integer.parseInt(hpOnOff_str); + } + resData.putInt("hpOnOff", hpOnOff); + if(groupId>0) { + resData.putInt("groupId", groupId); + String gpid = room_list.get(12); + resData.putInt("pid", StringUtil.isNotEmpty(gpid)?Integer.parseInt(gpid):0); + String gm_key = "gm_"+groupId+"_"+uid; + String lev_str = Redis.use("group1_db10").hget(gm_key, "lev"); + int lev = 3; + if(StringUtil.isNotEmpty(lev_str)) { + lev = Integer.parseInt(lev_str); + } + resData.putInt("lev", lev); + } + + return resData; + } finally { + if (lock != null) + lock.unlock(false); + jedis0.close(); + } + } + + + + /** + * 创建房间 + * + * @param router + * @throws Exception + */ + @ActionKey(value=Protocol.JOIN_ROOM,validate=WebInterceptor.V_SESSION) + public final void joinRoom() throws Exception { + String session = this.getSession(); + ITObject reqData = this.getParams(); + try{ + String room_key = "room:"+reqData.getUtfString("room_id"); + String platform = reqData.getUtfString("platform"); + sendResponse(ErrorCode._SUCC,publicJoinRoom(session, room_key,platform)); + }catch (WebException e) { + sendResponse(e.getCode(),null); + }catch (Exception e) { + e.printStackTrace(); + sendResponse(500,null); + } + + } + + private static final String _getSvr(Jedis jedis0,GameBean gb){ + String svr=null; + Set gamesvrs = gb.svr_list; + Integer conns = null; + for(String str : gamesvrs) { + String currConns = jedis0.hget(str, "conns"); + if (conns == null && currConns != null || (conns != null && currConns != null && Integer.parseInt(currConns) < conns)) { + conns = Integer.parseInt(currConns); + svr = str; + } + } + return svr; + } + + + +} diff --git a/web_login/src/main/java/com/mjlogin/util/sms/RedisKey.java b/web_login/src/main/java/com/mjlogin/util/sms/RedisKey.java new file mode 100644 index 0000000..1327a92 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/util/sms/RedisKey.java @@ -0,0 +1,8 @@ +package com.mjlogin.util.sms; + +public interface RedisKey { + /** 手机验证码 **/ + String VERIFICATION_CODE = "phone_code_"; + String VERIFICATION_CODE_SEND = "phone_code_send"; + +} diff --git a/web_login/src/main/java/com/mjlogin/util/sms/SMSThread.java b/web_login/src/main/java/com/mjlogin/util/sms/SMSThread.java new file mode 100644 index 0000000..f783480 --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/util/sms/SMSThread.java @@ -0,0 +1,64 @@ +package com.mjlogin.util.sms; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import com.taurus.core.plugin.redis.Redis; +import com.taurus.core.util.StringUtil; + +public class SMSThread { + + private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3, 3, 0L, TimeUnit.MILLISECONDS, + new LinkedBlockingQueue()); + + public static boolean sendCode(String phone) { + + String sendkey = RedisKey.VERIFICATION_CODE_SEND + phone; + String codekey = RedisKey.VERIFICATION_CODE + phone; + + try { + + if (!Redis.use().exists(sendkey) && !Redis.use().exists(codekey)) { + + Redis.use().set(sendkey, phone); + Redis.use().expire(sendkey, 120); + + threadPool.execute(new SendTask(phone)); + + return true; + } + } finally { + + } + + return false; + } + + private static final class SendTask implements Runnable { + + private final String phone; + + public SendTask(String phone) { + this.phone = phone; + } + + public void run() { + try { + + String code = SMSVerification.send(phone); + if (StringUtil.isNotEmpty(code)) { + + String key = RedisKey.VERIFICATION_CODE + phone; + Redis.use().set(key, code); + Redis.use().expire(key, 120); + } + + String sendkey = RedisKey.VERIFICATION_CODE_SEND + phone; + Redis.use().del(sendkey); + } catch (Exception e) { + + } + } + } +} diff --git a/web_login/src/main/java/com/mjlogin/util/sms/SMSVerification.java b/web_login/src/main/java/com/mjlogin/util/sms/SMSVerification.java new file mode 100644 index 0000000..7e09d7e --- /dev/null +++ b/web_login/src/main/java/com/mjlogin/util/sms/SMSVerification.java @@ -0,0 +1,120 @@ +package com.mjlogin.util.sms; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.aliyuncs.CommonRequest; +import com.aliyuncs.CommonResponse; +import com.aliyuncs.DefaultAcsClient; +import com.aliyuncs.IAcsClient; +import com.aliyuncs.exceptions.ClientException; +import com.aliyuncs.exceptions.ServerException; +import com.aliyuncs.http.MethodType; +import com.aliyuncs.profile.DefaultProfile; +import com.taurus.core.entity.ITObject; +import com.taurus.core.entity.TObject; +import com.taurus.core.util.Logger; +import com.taurus.core.util.StringUtil; +import com.taurus.core.util.Utils; + + +/** + * 短信验证 + */ +public class SMSVerification { + + private static Logger logger = Logger.getLogger(SMSVerification.class); + + /**短信API产品域名*/ + final static String domain = "dysmsapi.aliyuncs.com"; + /**你的accessKeyId*/ + final static String accessKeyId = "LTAI4FmrV5FnBy4EeRrk8oRh"; + /**你的accessKeySecret*/ + final static String accessKeySecret = "wdsbFdYXARh8riHg51KNw1KLjVzKmR"; + /**短信版本*/ + final static String version="2017-05-25"; + final static String regionId = "cn_beijing"; + /**action SendSms*/ + final static String action = "SendSms"; + /**短信模板*/ + final static String templateCode = "SMS_185575736"; + /**短信签名*/ + final static String signName = "找团长"; + + public static String hidePhone(String phone) { + String phone_4 = phone.substring(3, 7); + phone = phone.replace(phone_4, "****"); + return phone; + } + + /** + * 获取一个指定长度的N位随机数 + */ + public static int getFixLenthString(int length) { + int tempInt = Utils.rand.nextInt((int) Math.pow(10, length)); + if (tempInt < 100000) { + return getFixLenthString(length); + } + return tempInt; + } + + // 生成短信验证码 + private static String verificationCode() { + return getFixLenthString(6)+""; + } + + public static void main(String[] args) { + // send("13267171517");template_id parameter_2 + System.out.println(isValidPhone("18610826573")); + } + + public static String send(String phoneNumber) { + DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret); + IAcsClient client = new DefaultAcsClient(profile); + + String code = verificationCode(); + CommonRequest request = new CommonRequest(); + request.setMethod(MethodType.POST); + request.setDomain(domain); + request.setVersion(version); + request.setAction(action); + request.putQueryParameter("RegionId", regionId); + request.putQueryParameter("PhoneNumbers", phoneNumber); + request.putQueryParameter("SignName", signName); + request.putQueryParameter("TemplateCode", templateCode); + request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}"); + try { + CommonResponse response = client.getCommonResponse(request); + String data = response.getData(); + if(StringUtil.isNotEmpty(data)) { + ITObject tem = TObject.newFromJsonData(data); + String str_code = tem.getUtfString("Code"); + if(str_code.equals("OK")) { + return code; + } + } + } catch (ServerException e) { + e.printStackTrace(); + } catch (ClientException e) { + e.printStackTrace(); + } + return null; + } + + + + /** + * 是否有效手机号码 + */ + public static boolean isValidPhone(String phoneNumber) { + boolean isValidPhone = false; + String regex = "^((13[0-9])|(14[5|7|9])|(15([0-3]|[5-9]))|(17[01235678])|(18[0-9])|(19[189]))\\d{8}$"; + if (phoneNumber.length() == 11) { + Pattern p = Pattern.compile(regex); + Matcher m = p.matcher(phoneNumber); + isValidPhone = m.matches(); + } + return isValidPhone; + } + +} diff --git a/web_login/src/main/webapp/WEB-INF/web.xml b/web_login/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..b0b7f3d --- /dev/null +++ b/web_login/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + + taurus-web + com.taurus.web.WebFilter + + main + com.mjlogin.MainServer + + + + + taurus-web + /* + + diff --git a/web_login/src/main/webapp/config/log4j.properties b/web_login/src/main/webapp/config/log4j.properties new file mode 100644 index 0000000..6786dba --- /dev/null +++ b/web_login/src/main/webapp/config/log4j.properties @@ -0,0 +1,20 @@ + +log4j.rootLogger = INFO,consoleAppender,fileAppender + +# ConsoleAppender +log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender +log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.consoleAppender.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%t] %c{2} %3x - %m%n + + +# Regular FileAppender +log4j.appender.fileAppender=org.apache.log4j.DailyRollingFileAppender +log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout +log4j.appender.fileAppender.File=${WORKDIR}/logs/web_main.log +log4j.appender.fileAppender.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t | %c{3} | %3x | %m%n +log4j.appender.fileAppender.Encoding=UTF-8 +log4j.appender.fileAppender.DatePattern='.'yyyy-MM-dd +log4j.appender.dailyFile.Append=true + +# The file is rolled over very day +log4j.appender.fileAppender.DatePattern ='.'yyyy-MM-dd \ No newline at end of file diff --git a/web_login/src/main/webapp/config/taurus-core.xml b/web_login/src/main/webapp/config/taurus-core.xml new file mode 100644 index 0000000..304c5e1 --- /dev/null +++ b/web_login/src/main/webapp/config/taurus-core.xml @@ -0,0 +1,97 @@ + + + log4j.properties + + + database + com.taurus.core.plugin.database.DataBasePlugin + + + + 100 + + 1 + + 180000 + + select 1 + + 10000 + + 60000 + + + + false + true + utf-8 + + UTC + + true + + 250 + + 2048 + + + + + + db1 + com.mysql.cj.jdbc.Driver + jdbc:mysql://101.35.26.131:8060/wb_game + root + root + + + + + + redis + com.taurus.core.plugin.redis.RedisPlugin + + + + 80 + + 20 + + 5 + + -1 + + true + + true + + true + + 100 + + 60000 + + 30000 + + 1800000 + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/web_login/src/test/java/web_login/Main.java b/web_login/src/test/java/web_login/Main.java new file mode 100644 index 0000000..fe1466d --- /dev/null +++ b/web_login/src/test/java/web_login/Main.java @@ -0,0 +1,9 @@ +package web_login; + +import com.taurus.web.JettyServer; + +public class Main { + public static void main(String[] args) { + new JettyServer("src/main/webapp",8079,"/").start(); + } +}