feat(game): 添加玩家胜利标识并优化游戏结束逻辑
- - 优化 Room 类中的游戏结束处理逻辑,包括分数保存和奖励计算 - 更新 RoomEndState 类的 enter 方法,改进玩家状态切换流程 - 在 EXPlayerBetState 中添加日志输出,便于调试- 为 EXPlayBack 类的 addResultCommand 方法添加注释,提高代码可读性master
parent
561d4f5d27
commit
b134082820
|
|
@ -163,6 +163,9 @@ public class Player {
|
||||||
*/
|
*/
|
||||||
public int xi_pai_total = 0;
|
public int xi_pai_total = 0;
|
||||||
|
|
||||||
|
//赢了的玩家
|
||||||
|
public int winer_playerid = 0;
|
||||||
|
|
||||||
public Player(int playerid, Room table, String session_id) {
|
public Player(int playerid, Room table, String session_id) {
|
||||||
this.room = table;
|
this.room = table;
|
||||||
this.playerid = playerid;
|
this.playerid = playerid;
|
||||||
|
|
|
||||||
|
|
@ -624,6 +624,7 @@ public class Room implements Runnable {
|
||||||
this.saveMilitaryTotal(true);
|
this.saveMilitaryTotal(true);
|
||||||
} else {
|
} else {
|
||||||
roomResult();
|
roomResult();
|
||||||
|
// this.saveMilitaryTotal(true);
|
||||||
}
|
}
|
||||||
Global.logger.info("total: "+total);
|
Global.logger.info("total: "+total);
|
||||||
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
|
||||||
|
|
@ -1056,17 +1057,17 @@ public class Room implements Runnable {
|
||||||
pdata.putInt("accId", player.playerid);
|
pdata.putInt("accId", player.playerid);
|
||||||
plist.addTObject(pdata);
|
plist.addTObject(pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 人头制-是否需要奖励
|
// 人头制-是否需要奖励
|
||||||
// 以大赢家为标准 -2019.12.23
|
// 以大赢家为标准 -2019.12.23
|
||||||
if (this.hpData != null ) {
|
if (this.hpData != null ) {
|
||||||
|
|
||||||
int type = this.hpData.containsKey("type") ? this.hpData.getInt("type") : 2;
|
int type = this.hpData.containsKey("type") ? this.hpData.getInt("type") : 2;
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
|
|
||||||
int lowerThanValue = 0;
|
int lowerThanValue = 0;
|
||||||
if(hpData.containsKey("UpperLimitReward") && hpData.getInt("UpperLimitReward") > 0) {
|
if(hpData.containsKey("UpperLimitReward") && hpData.getInt("UpperLimitReward") > 0) {
|
||||||
|
|
||||||
if (hpData.containsKey("UpperLimit")) {
|
if (hpData.containsKey("UpperLimit")) {
|
||||||
lowerThanValue = hpData.getInt("UpperLimit");
|
lowerThanValue = hpData.getInt("UpperLimit");
|
||||||
roomMoney = hpData.getInt("UpperLimitReward");
|
roomMoney = hpData.getInt("UpperLimitReward");
|
||||||
|
|
@ -1076,14 +1077,14 @@ public class Room implements Runnable {
|
||||||
// 新浮动抽水数据
|
// 新浮动抽水数据
|
||||||
ITArray rewards_list = this.hpData.getTArray("rewards_list");
|
ITArray rewards_list = this.hpData.getTArray("rewards_list");
|
||||||
if (rewards_list.size() > 0) {
|
if (rewards_list.size() > 0) {
|
||||||
|
|
||||||
lowerThanValue = rewards_list.getTObject(0).getInt("UpperLimit");
|
lowerThanValue = rewards_list.getTObject(0).getInt("UpperLimit");
|
||||||
if(rewards_list.getTObject(0).containsKey("UpperLimitReward")) {
|
if(rewards_list.getTObject(0).containsKey("UpperLimitReward")) {
|
||||||
roomMoney = rewards_list.getTObject(0).getInt("UpperLimitReward");
|
roomMoney = rewards_list.getTObject(0).getInt("UpperLimitReward");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scoreDesc().size()>0 && scoreDesc().get(0).hpPumpValue() < lowerThanValue && roomMoney > 0 ) {
|
if(scoreDesc().size()>0 && scoreDesc().get(0).hpPumpValue() < lowerThanValue && roomMoney > 0 ) {
|
||||||
aHeadReward = false;
|
aHeadReward = false;
|
||||||
}else {
|
}else {
|
||||||
|
|
@ -1117,7 +1118,7 @@ public class Room implements Runnable {
|
||||||
if (this.agent && this.groupId > 0) {
|
if (this.agent && this.groupId > 0) {
|
||||||
|
|
||||||
Global.eventCtr.redisGroupRound(this, groupId, groupPid, hpPump ? 1 : 0);
|
Global.eventCtr.redisGroupRound(this, groupId, groupPid, hpPump ? 1 : 0);
|
||||||
|
|
||||||
for (Entry<Integer, Player> entry : this.playerMapBySeat.entrySet()) {
|
for (Entry<Integer, Player> entry : this.playerMapBySeat.entrySet()) {
|
||||||
Player player = entry.getValue();
|
Player player = entry.getValue();
|
||||||
if (player.already_round == 0)
|
if (player.already_round == 0)
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,24 @@ import com.game.state.StateBase;
|
||||||
|
|
||||||
|
|
||||||
public class RoomEndState extends StateBase<Room>{
|
public class RoomEndState extends StateBase<Room>{
|
||||||
|
/**
|
||||||
|
* 当玩家进入房间时调用此方法,以处理进入房间后的相关操作
|
||||||
|
*
|
||||||
|
* @param owner 房间的拥有者对象,用于访问和操作房间的相关数据
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enter(Room owner) {
|
public void enter(Room owner) {
|
||||||
owner.saveSocre();
|
// 保存房间拥有者的分数,以便在进入房间后更新分数信息
|
||||||
|
owner.saveSocre();
|
||||||
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
// 遍历房间中所有座位上的玩家,为每个玩家更新状态
|
||||||
Player player = entry.getValue();
|
for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
|
||||||
player.stateMachine.changeState( Global.getState(PlayerEndState.class));
|
// 获取当前遍历到的玩家对象
|
||||||
}
|
Player player = entry.getValue();
|
||||||
|
// 为玩家切换到结束状态,表示玩家已准备好开始游戏或观战
|
||||||
|
player.stateMachine.changeState( Global.getState(PlayerEndState.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Room owner, String cmd, int gid, Object param) {
|
public void execute(Room owner, String cmd, int gid, Object param) {
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -39,7 +39,15 @@ public class EXPlayBack extends BasePlayBack{
|
||||||
addCommand("newindex", 0, cmdData);
|
addCommand("newindex", 0, cmdData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加结果命令
|
||||||
|
* 该方法用于向特定座位的玩家添加一个结果命令,结果命令包含了一些数据,用于表示游戏结果或其他重要信息
|
||||||
|
*
|
||||||
|
* @param seat 座位号,表示命令是为哪个座位的玩家添加的,必须是有效的座位号
|
||||||
|
* @param cmdData 命令数据,是一个ITObject对象,包含要添加的命令的具体数据,不能为空
|
||||||
|
*/
|
||||||
public void addResultCommand(int seat,ITObject cmdData) {
|
public void addResultCommand(int seat,ITObject cmdData) {
|
||||||
|
// 调用addCommand方法,将命令类型设置为"result",将特定座位号和命令数据作为参数传递
|
||||||
addCommand("result", seat, cmdData);
|
addCommand("result", seat, cmdData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,9 @@ public class EXPlayerBetState extends StateBase<EXPlayer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("当前用户 :"+owner.playerid);
|
||||||
|
System.out.println("当前用户的总下注分数:"+owner.totalLostScore);
|
||||||
|
|
||||||
owner.totalLostScore += owner.betScore;
|
owner.totalLostScore += owner.betScore;
|
||||||
// 扣除下注分数
|
// 扣除下注分数
|
||||||
owner.lostScore =owner.betScore;
|
owner.lostScore =owner.betScore;
|
||||||
|
|
@ -150,8 +153,8 @@ public class EXPlayerBetState extends StateBase<EXPlayer> {
|
||||||
|
|
||||||
for (Entry<Integer, Player> entry : room.playerMapBySeat.entrySet()) {
|
for (Entry<Integer, Player> entry : room.playerMapBySeat.entrySet()) {
|
||||||
EXPlayer player = (EXPlayer) entry.getValue();
|
EXPlayer player = (EXPlayer) entry.getValue();
|
||||||
|
System.out.println("基础分数:"+player.baseScore);
|
||||||
param.putInt("seat_" + player.seat, player.baseScore - player.totalLostScore);
|
param.putInt("seat_" + player.seat, player.baseScore - player.totalLostScore);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
room.broadCastToClient(0, Config.GAME_EVT_RESULT, param);
|
room.broadCastToClient(0, Config.GAME_EVT_RESULT, param);
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue