Browse Source

比牌

master
cristianoxin 5 months ago
parent
commit
c662199be4
  1. 12
      assets/10001/language/en/language.json
  2. 4
      assets/10001/prefab/TeenPattieBiPaiSuccGame.prefab
  3. 3
      assets/10001/src/GameConst10001.ts
  4. 8
      assets/10001/src/game/TeenPattieGameEntity.ts
  5. 235
      assets/10001/src/game/component/TeenPattieBiPaiSuccGamePanel.ts
  6. 10
      assets/10001/src/game/logic/TeenPattiePkCardsLogic.ts
  7. 9
      assets/10001/src/game/logic/TeenPattiePlayerLogic.ts
  8. 84
      assets/10001/src/game/system/TeenpattieGameProxySystem.ts
  9. 12
      assets/10001/src/tool/TeenPattiePathTool.ts

12
assets/10001/language/en/language.json

@ -331,6 +331,18 @@
"des":"现在退出游戏,将输掉本局游戏",
"value":"Quiting the game now will result in losing this round."
},
"game.tip.WatchBattle":{
"des":"{0}正在观战",
"value":"{0} Watch the battle"
},
"game.tip.JoinedGame":{
"des":"{0}已加入游戏",
"value":"{0} Joined the game"
},
"game.tip.quitGame":{
"des":"{0}已退出游戏",
"value":"{0} Exited the game"
},
"game.tip.exitRoom":{
"des":"退出房间",
"value":"Exit the room"

4
assets/10001/prefab/TeenPattieBiPaiSuccGame.prefab

@ -1354,7 +1354,7 @@
"__id__": 85
}
],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 91
@ -3227,7 +3227,7 @@
"__id__": 173
}
],
"_active": false,
"_active": true,
"_components": [
{
"__id__": 179

3
assets/10001/src/GameConst10001.ts

@ -19,6 +19,9 @@ export enum GameNetCode{
PlayerOut = 10001022,// 玩家退出 结束游戏 退出房间
RoomWait = 10001023,// 房间等待倒计时
GameRecord = 10001024, // 玩家自己看牌返回
WatchToDown = 10001025, // 主动观战转坐下
NotifyWatchToDown = 1000132, // 通知玩家观战转坐下
NotifyDownToWatch = 1000133, // 通知玩家坐下转观战
}
export enum GamePanelConst{

8
assets/10001/src/game/TeenPattieGameEntity.ts

@ -1,6 +1,6 @@
import { Component, _decorator } from "cc";
import { TeenPattieGameComponent } from "./component/TeenPattieGameComponent";
import { GameConst, Message, Network, SocketConst, UILayerIndex, UIManager } from "../sdk/API";
import { GameConst, Message, Network, SocketConst, SystemParams, UILayerIndex, UIManager } from "../sdk/API";
import { TeenPattieEventType } from "../tool/TeenPattieEventType";
import { UserData } from "../sdk/GameVO";
import { TeenPattieCommData } from "./TeenPattieCommData";
@ -47,12 +47,14 @@ export class TeenPattieGameEntity extends Component{
private init() {
TeenPattieCommData.getInstance().clearCommData();
Message.send(TeenPattieEventType.Reconnect);
console.log("gameID:",UserData.gameID,"roomID:",UserData.gameLevel,"tableID:",UserData.tableID)
console.log("gameID:",UserData.gameID,"roomID:",UserData.gameLevel,"tableID:",UserData.tableID);
let isWatch:boolean = SystemParams.getInstance().getValue("isWatch") == 1 ? true : false;
const data ={
gameId: UserData.gameID,
roomId: UserData.gameLevel,
tableID: UserData.tableID,
agentID: parseInt(localStorage.getItem("agentID"))
agentID: parseInt(localStorage.getItem("agentID")),
isWatching: isWatch
}
Network.getInstance().send(GameNetCode.Join_Game, data)
}

235
assets/10001/src/game/component/TeenPattieBiPaiSuccGamePanel.ts

@ -1,10 +1,10 @@
import { _decorator, Animation, Button, Component, find, Label, Node, sp, Sprite } from 'cc';
import { _decorator, Animation, Button, Component, find, Label, Node, sp, Sprite, SpriteFrame } from 'cc';
import { TeenPattieCommData } from '../TeenPattieCommData';
import { TeenPattiePathTool } from '../../tool/TeenPattiePathTool';
import { TeenPattieCommTool } from '../../tool/TeenPattieCommTool';
import { TeenPattieEventType } from '../../tool/TeenPattieEventType';
import { AudioManager, Message, Sleep, UIManager } from '../../sdk/API';
import { GamePanelConst, GameSound, GameStatus } from '../../GameConst10001';
import { AudioManager, LoaderManager, Message, Sleep, UIManager } from '../../sdk/API';
import { BundleName, GamePanelConst, GameSound, GameStatus } from '../../GameConst10001';
const { ccclass, property } = _decorator;
@ccclass('TeenPattieBiPaiSuccGamePanel')
@ -36,6 +36,11 @@ export class TeenPattieBiPaiSuccGamePanel extends Component {
private cardList_2: Sprite[];
private cardType_2: Sprite;
private cardType_Node_2:Node;
/**胜利方数据 */
private faqiData: any;
/**失败方数据 */
private beiFaqiData: any;
/**PK结果数据 */
private result: any;
@ -83,19 +88,36 @@ export class TeenPattieBiPaiSuccGamePanel extends Component {
this.cardType_Node_2.active = false;
this.result = TeenPattieCommData.getInstance().pkResult;
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){
this.bipai_faqi_cards.active = true;
this.bipai_beifaqi_cards.active = true;
}else{
this.bipai_faqi_cards.active = false;
this.bipai_beifaqi_cards.active = false;
}
this.timeLabel = 2;
this.clickNum = 1;
this.anumNum_1 = 0;
this.anumNum_2 = 0;
this.startEvnet();
}
private async onStartClose(){
this.timeLabel--;
if(this.timeLabel <= 0){
clearInterval(this.tid);
this.tid = null;
await Sleep(1000)
this.onClickBtn();
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){
if(this.anumNum_1 > 2 || this.anumNum_2 > 2){
clearInterval(this.tid);
this.tid = null;
await Sleep(1000)
this.onClickBtn();
}
}else{
this.onClickBtn();
}
}
}
private startEvnet() {
@ -106,17 +128,118 @@ export class TeenPattieBiPaiSuccGamePanel extends Component {
this.isFaqi();
this.vsSkele.setCompleteListener(()=>{
this.showWinPlayer();
})
if(this.result.compareCardGroups && this.result.compareCardGroups.length > 0){
console.log("******注册动画事件*******");
this.onSkeleEvent()
}else{
this.vsSkele.setCompleteListener(()=>{
this.showWinPlayer();
})
}
}
protected onDestroy(): void {
// this.closeBtn?.node?.off(Node.EventType.TOUCH_END,this.onClickBtn,this);
Message.remove(TeenPattieEventType.Reconnect, this.closeUI, this);
this.onDesSkeleEvent();
}
/**注册需要播放的动画事件 */
private onSkeleEvent(){
console.log("******背景动画播放开始*******");
let loadAnim = setTimeout(()=>{
clearTimeout(loadAnim);
loadAnim = null;
console.log("******背景动画播放完*******");
this.onloadAnimFunc();
},1000)
for(let i=0;i<this.cardAnim_1.length;i++){
this.cardAnim_1[i].on(Animation.EventType.FINISHED,this.cardAnimFunc_1,this)
}
for(let i=0;i<this.cardAnim_2.length;i++){
this.cardAnim_2[i].on(Animation.EventType.FINISHED,this.cardAnimFunc_2,this)
}
}
/**销毁需要播放的动画事件 */
private onDesSkeleEvent(){
for(let i=0;i<this.cardAnim_1.length;i++){
this.cardAnim_1[i]?.off(Animation.EventType.FINISHED,this.cardAnimFunc_1,this)
}
for(let i=0;i<this.cardAnim_2.length;i++){
this.cardAnim_2[i]?.off(Animation.EventType.FINISHED,this.cardAnimFunc_2,this)
}
}
/**开始动画播放完成 */
private onloadAnimFunc(){
this.cardAnim_1[this.anumNum_1].play()
this.cardAnim_2[this.anumNum_2].play()
}
private anumNum_1:number = 0;
private anumNum_2:number = 0;
private cardAnimFunc_1(){
if(this.anumNum_1 > 2) return
if(this.cardAnim_1[this.anumNum_1]){
this.cardAnim_1[this.anumNum_1].stop();
this.cardAnim_1[this.anumNum_1]=null;
}
this.setCardSprite_1(this.anumNum_1)
this.anumNum_1 += 1
if(this.anumNum_1 > 2) return
if( this.cardAnim_1[this.anumNum_1])this.cardAnim_1[this.anumNum_1].play()
}
private cardAnimFunc_2(){
if(this.anumNum_2 > 2) return
if(this.cardAnim_2[this.anumNum_2]){
this.cardAnim_2[this.anumNum_2].stop();
this.cardAnim_2[this.anumNum_2]=null;
}
this.setCardSprite_2(this.anumNum_2)
this.anumNum_2 += 1
if(this.anumNum_2 > 2){
this.animEnd();
return;
}
if(this.cardAnim_2[this.anumNum_2])this.cardAnim_2[this.anumNum_2].play()
}
/**动画结束 */
private animEnd(){
this.faqi_win.active = this.result.winSeatId == TeenPattieCommData.getInstance().playerData.SeatId;
this.beifaqi_win.active = this.result.winSeatId == TeenPattieCommData.getInstance().beiPlayerData.SeatId;
}
private clickNum:number=1
private onClickBtn(){
this.closeUI();
if(this.anumNum_1 > 2 || this.anumNum_2 > 2) this.clickNum++
if(this.clickNum > 1){
this.closeUI();
return
}else{
this.skipAnim()
this.clickNum++
}
}
private skipAnim(){
for(let i = 0;i<3;i++){
this.anumNum_1 = 3
this.setCardSprite_1(i)
}
for(let i = 0;i<3;i++){
this.anumNum_2 = 3
this.setCardSprite_2(i)
}
if(this.cardType_Node_1 && this.cardType_1.isValid)this.cardType_Node_1.active = true;
if(this.cardType_Node_2 && this.cardType_2.isValid)this.cardType_Node_2.active = true;
}
/**关闭UI */
@ -125,6 +248,9 @@ export class TeenPattieBiPaiSuccGamePanel extends Component {
this.tid=null
this.timeLabel = 3;
this.clickNum = 1;
this.anumNum_1 = 0;
this.anumNum_2 = 0;
Message.send(TeenPattieEventType.PkCardEnd);
TeenPattieCommTool.gamePause(GameStatus.Recover);
@ -140,25 +266,102 @@ export class TeenPattieBiPaiSuccGamePanel extends Component {
if(win && win.SeatId == TeenPattieCommData.getInstance().playerSeatId) AudioManager.getInstance().playEffect(GameSound.bipaiWin)
//发起方
this.initFaqiData(win);
const selfCardCard = TeenPattieCommData.getInstance().bipaiPlayerCardData;
this.initFaqiData(selfCardCard, win);
//被发起方
this.initBeiFaqiData(lost);
const beiPlayerCardCard = TeenPattieCommData.getInstance().beiBipaiPlayerCardData;
this.initBeiFaqiData(beiPlayerCardCard, lost);
}
/**发起方数据初始化 */
private initFaqiData(win: any) {
private initFaqiData(playerCard: any, win: any) {
this.faqiData = win;
TeenPattiePathTool.setAvatar(this.biPai_faqi_head, win.avatar);
TeenPattiePathTool.setAvatarFrame(this.biPai_faqi_frame, win.avatar_vip);
this.biPai_faqi_naicName.string = win.nickname;
if(!playerCard){
this.bipai_faqi_cards.active = false;
return
}
const cards = playerCard.Cards;
const cardsType = playerCard.CardType;
async function findCardsType(owner: TeenPattieBiPaiSuccGamePanel) {
let sp: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, `res/cardsType/${cardsType}/spriteFrame`, SpriteFrame) as SpriteFrame;
owner.cardType_1.spriteFrame = sp;
}
findCardsType(this);
this.cards_1 = cards
}
private cards_1:any
/**翻牌 1 */
private setCardSprite_1(num:number){
const cards = this.cards_1
if(!cards || !this.cardList_1) return;
//牌的花色
const suitType = cards[num].suit;
//牌的值
const suitValue = cards[num].value;
const anumNum = num
const path = TeenPattiePathTool.getCardPath(suitType,suitValue)
async function findSpriteFrame(owner: TeenPattieBiPaiSuccGamePanel) {
const url = path;
let spriteFrame: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, url, SpriteFrame) as SpriteFrame;
owner.cardList_1[anumNum].spriteFrame = spriteFrame;
}
findSpriteFrame(this);
if(anumNum >= 2){
this.cardType_Node_1.active = true;
}
}
/**被发起方数据初始化 */
private initBeiFaqiData(lost: any) {
private initBeiFaqiData(playerCard: any, lost: any) {
this.beiFaqiData = lost;
TeenPattiePathTool.setAvatar(this.biPai_beifaqi_head, lost.avatar);
TeenPattiePathTool.setAvatarFrame(this.biPai_beifaqi_frame, lost.avatar_vip);
this.biPai_beifaqi_naicName.string = lost.nickname;
this.beifaqi_win.active = this.result.winSeatId == lost.SeatId;
if(!playerCard){
this.bipai_beifaqi_cards.active = false;
return;
}
const cards = playerCard.Cards;
const cardsType = playerCard.CardType;
async function findCardsType(owner: TeenPattieBiPaiSuccGamePanel) {
let sp: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, `res/cardsType/${cardsType}/spriteFrame`, SpriteFrame) as SpriteFrame;
owner.cardType_2.spriteFrame = sp;
}
findCardsType(this);
this.cards_2 = cards
}
private cards_2:any
/**翻牌 2 */
private setCardSprite_2(num:number){
const cards = this.cards_2
if(!cards || !this.cardList_2) return;
//牌的花色
const suitType = cards[num].suit;
//牌的值
const suitValue = cards[num].value;
const anumNum = num
const path = TeenPattiePathTool.getCardPath(suitType,suitValue)
async function findSpriteFrame(owner: TeenPattieBiPaiSuccGamePanel) {
const url = path;
let spriteFrame: SpriteFrame = await LoaderManager.getInstance().getType(`${BundleName.BundleName}`, url, SpriteFrame) as SpriteFrame;
owner.cardList_2[anumNum].spriteFrame = spriteFrame;
}
findSpriteFrame(this);
if(anumNum >= 2){
this.cardType_Node_2.active = true;
}
}
/**动画播放完成后显示赢家 */
private showWinPlayer(){

10
assets/10001/src/game/logic/TeenPattiePkCardsLogic.ts

@ -38,6 +38,7 @@ export class TeenPattiePkCardsLogic extends Component {
this.pkData = value;
this.player = ow;
const allCards = TeenPattieCommData.getInstance().allKanPlayerCard;
const allQi = TeenPattieCommData.getInstance().allQipaiData || [];
const lostId = value.loseSeatId;
@ -72,6 +73,15 @@ export class TeenPattiePkCardsLogic extends Component {
}
}
}
//赢家和输家牌的数据
for(let i = 0;i<allCards.length;i++){
if(allCards[i].SeatId == value.winSeatId){
TeenPattieCommData.getInstance()._bipaiPlayerCardData = allCards[i];
}else if(allCards[i].SeatId == value.loseSeatId){
TeenPattieCommData.getInstance()._beiBipaiPlayerCardData = allCards[i];
}
}
//没有玩家自己
if (value.winSeatId != ow.playerSeatId && value.loseSeatId != ow.playerSeatId) {

9
assets/10001/src/game/logic/TeenPattiePlayerLogic.ts

@ -687,7 +687,7 @@ export class TeenPattiePlayerLogic extends Component {
this.bottom.isQiPaiBtnSp(false);
}
if(value.remainNum <= 2 && (value.winSeatId == this.data?.SeatId || value.loseSeatId == this.data?.SeatId)){
this.pkCards.ForceCompareResult(this);
// this.pkCards.ForceCompareResult(this);
}
this.pkCards.result(value, this);
}
@ -801,11 +801,8 @@ export class TeenPattiePlayerLogic extends Component {
private reStart() {
this.clearTimer();
this.refresh();
if (this.data?.SeatId == this.playerSeatId){
TeenPattieCommData.getInstance().isForceCard = false;
TeenPattieCommData.getInstance().isRegisthandle = false;
//开始下一把游戏或者刷新时推送消息处理 有时会进入两次或以上
}
TeenPattieCommData.getInstance().isForceCard = false;
TeenPattieCommData.getInstance().isRegisthandle = false;
}
/**刷新房间数据 */

84
assets/10001/src/game/system/TeenpattieGameProxySystem.ts

@ -9,6 +9,7 @@ import { GameNetCode, GamePanelConst, gameErrorCode } from "../../GameConst10001
import { TeenPattiePlayerLogic } from "../logic/TeenPattiePlayerLogic";
import { Game10001Res } from "../../comm/Game10001Res";
import { UserData } from "../../sdk/GameVO";
import { TeenPattiePathTool } from "../../tool/TeenPattiePathTool";
export class TeenpattieGameProxySystem extends Component {
/**当前出牌玩家ID */
@ -44,6 +45,8 @@ export class TeenpattieGameProxySystem extends Component {
Network.getInstance().registhandle(GameNetCode.ForceSeeCard, this.ForceSeeCard.bind(this));
Network.getInstance().registhandle(GameNetCode.ForceCompare, this.ForceCompare.bind(this));
Network.getInstance().registhandle(GameNetCode.RoomWait,this.roomWait.bind(this));
Network.getInstance().registhandle(GameNetCode.NotifyWatchToDown,this.notifyWatchToDown.bind(this));
Network.getInstance().registhandle(GameNetCode.NotifyDownToWatch,this.notifyDownToWatch.bind(this));
Message.add(UIWindowMessage.CloseUI, this.onCloseUI, this);
}
@ -82,6 +85,7 @@ export class TeenpattieGameProxySystem extends Component {
/**游戏等待开始 */
private onGameStart(value: any) {
this.resetAllPlayerSeatData();
this.pkData = null;
this.resData = null;
Message.send(TeenPattieEventType.GameMatchTips,false);
@ -192,12 +196,26 @@ export class TeenpattieGameProxySystem extends Component {
}
}
/**
*
*
*/
private isResetSeat:boolean = false;
/**
*
* @param userPlayer
*/
private resetAllPlayerSeatData(userPlayer:number){
private resetAllPlayerSeatData(){
if(!this.isResetSeat) return;
this.isResetSeat = false;
const allData:any[] = TeenPattieCommData.getInstance().allPlayerData;
for(const item of allData){
item.status = 1;
item.cards = null;
let index:number = this.getPlayerIndex(item?.SeatId);
this.setPlayerJoinData(index,item);
}
}
/**房间底注 */
@ -208,6 +226,7 @@ export class TeenpattieGameProxySystem extends Component {
private faPaiData: any;
//玩家发牌
private onGameFaPai(value: any) {
this.resetAllPlayerSeatData();
Message.send(TeenPattieEventType.NextGame);
this.pkData = null;
this.resData = null;
@ -304,6 +323,11 @@ export class TeenpattieGameProxySystem extends Component {
/**比牌结果 */
private pkCardData(value: any) {
console.warn("比牌结果数据:", value.data);
if(value.data.compareCardGroups && value.data.compareCardGroups.length > 0){
for(const item of value.data.compareCardGroups){
this.setPlayerSeeCardData(item);
}
}
const allCards = TeenPattieCommData.getInstance().allKanPlayerCard;
const allQi = TeenPattieCommData.getInstance().allQipaiData || [];
const remainNum:number = allCards.length - allQi.length;
@ -428,54 +452,58 @@ export class TeenpattieGameProxySystem extends Component {
/**通知玩家观战转坐下 */
private notifyWatchToDown(data:any){
console.warn("通知玩家观战转坐下")
this.watchToDown(data);
// this.watchToDown(data);
}
/**通知玩家坐下转观战 */
private notifyDownToWatch(data:any){
console.warn("通知玩家坐下转观战")
this.downToWatch(data.chairId);
// this.downToWatch(data.seatId);
}
/**主动观战转坐下 */
private watchToDown(data:any){
for(const [index,item] of TeenPattieCommData.getInstance().allWatchPlayerData.entries()){
if(item.uid == data.uid){
item.chairId = data.chairId;
item.SeatId = data.seatId;
TeenPattieCommData.getInstance().allPlayerId.push(item?.SeatId);
TeenPattieCommData.getInstance()._allPlayerData.push(item);
TeenPattieCommData.getInstance().allWatchPlayerData.splice(index,1);
if(data.uid == UserData.userId){
TeenPattieCommData.getInstance().playerSeatId = data.chairId;
const ind:number = this.getPlayerIndex(item?.SeatId);
this.setPlayerJoinData(ind,item);
if(item.uid == UserData.userId){
TeenPattieCommData.getInstance().playerSeatId = item.SeatId;
TeenPattieCommData.getInstance().isCurrWatch = false;
const userPlayer = item?.SeatId;
this.chagedIndex =userPlayer >= 3 ? -(userPlayer - 3) : (3 - userPlayer);
this.isResetSeat = true;
}else{
}
// const str:string = SIXABPathTool.formatString(I18Manager.getInstance().getString("game.sixab.JoinedGame"),item.nickname);
// window["Toast"]?.getInstance().showToast(str);
const str:string = TeenPattiePathTool.formatString(Game10001Res.getInstance().getString("game.tip.JoinedGame"),item.nickname);
window["Toast"]?.getInstance().showToast(str);
}
}
}
/**玩家坐下转观战 */
private downToWatch(chairId:number){
// for(const [index,item] of SIXABGame.commData.chairIdPlayerData.entries()){
// if(item.chairId == chairId){
// if(item.uid == UserData.userId){
// SIXABGame.commData.isCurrWatch = true;
// SIXABGame.commData.playerSelfSeatId == -1;
// }
// const data:NotifyGetOutGame = {
// chairId: chairId,
// leaveReason: 0
// }
// Message.send(SIXABEventType.NOTIFY_GETOUTGAME,data);
// item.chairId = -1;
// SIXABGame.commData.watchPlayerData.push(item);
// SIXABGame.commData.chairIdPlayerData.splice(index,1);
// const str:string = SIXABPathTool.formatString(I18Manager.getInstance().getString("game.sixab.WatchBattle"),item.nickname);
// window["Toast"]?.getInstance().showToast(str);
// }
// }
for(const [index,item] of TeenPattieCommData.getInstance().allPlayerData.entries()){
if(item.chairId == chairId){
if(item.uid == UserData.userId){
TeenPattieCommData.getInstance().isCurrWatch = true;
TeenPattieCommData.getInstance().playerSeatId = 0;
}
item.SeatId = 0;
TeenPattieCommData.getInstance().allWatchPlayerData.push(item);
TeenPattieCommData.getInstance()._allPlayerData.splice(index,1);
const str:string = TeenPattiePathTool.formatString(Game10001Res.getInstance().getString("game.tip.WatchBattle"),item.nickname);
window["Toast"]?.getInstance().showToast(str);
}
}
}
}

12
assets/10001/src/tool/TeenPattiePathTool.ts

@ -59,6 +59,18 @@ export class TeenPattiePathTool{
static getAvatarFramePath(id){
return `res/vip_txk/txk_${id || 1}/spriteFrame`;
}
/**
* {0},{1}
* @param template
* @param replacements
* @returns
*/
static formatString(template: string, ...replacements: string[]): string {
return template.replace(/\{(\d+)\}/g, function(match, group1) {
return replacements[parseInt(group1)];
});
}
/**
*

Loading…
Cancel
Save