123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- var GamePlayer = require("GamePlayer");
- var Define = require("Define");
- var ProtocolGameServer = require("ProtocolGameServer");
- var BRTPSoundFun = require("BRTPSoundFun");
- var Global = require("Global");
- var UIHelper = require("UIHelper");
- import { CServerItem } from 'CServerItem'
- var voice = {
- localId: "",
- serverId: "",
- };
- cc.Class({
- extends: GamePlayer,
- //extends: cc.Component,
- properties: {
- sprHeadIcon:cc.Sprite,
- sprVipIcon:cc.Sprite, // VIP框
- btnHead:cc.Button,
- sprEmptyHeadIcon:cc.Sprite,
- labScoreWin:cc.Label,
- labScoreLose:cc.Label,
- labName:cc.Label,
- sprOffineFlag:cc.Sprite,
- sprScoreBg:cc.Sprite,
- spriteFrame:{
- default:null,
- type:cc.SpriteFrame
- },
-
- //牌的显示和操作
- cardNode: {
- default:null,
- type:cc.Node
- },
- goldPrefabArr: { //金豆预制数组
- default: [],
- type: [cc.Prefab]
- },
- iIndex:-1,
- _myScore:0,
- _chairID:-1,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function() {
- this.sprVipIcon.sizeMode = cc.Sprite.SizeMode.CUSTOM;
- this.sprVipIcon.node.width = 120;
- this.sprVipIcon.node.height = 120;
- this.sprVipIcon.node.scale = 1;
- },
- init: function(index) {
-
- },
- resetCard:function()
- {
- this.node.getChildByName("scoreAni").active = false;
- this.node.getChildByName("bombOpenAniNode").active = false;
- this.node.getChildByName("bomb").active = false;
- },
- resetView: function() {
-
- this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").active = false;
- this.node.getChildByName("scoreAni").active = false;
- this.node.stopAllActions();
- },
- hideVoice: function() {
- this.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = false;
- },
- addScore: function(lScore,bAni)
- {
- this.node.getChildByName("addInfoNode").active = true;
- var pos = this.node.getChildByName("addInfoNode").getPosition();
- var goldNode = this.node.getChildByName("addInfoNode").getChildByName("goldNode");
- var posDe = goldNode.getPosition();
- var scoreNode = this.node.getChildByName("addInfoNode").getChildByName("scoreNode");
- if(bAni)
- {
- //音效
- BRTPSoundFun.playEffectEX(BRTPSoundFun.EX_SCORE);
- if (CServerItem.get().mGameServer.ServerType == 1) //金豆场金豆
- {
- var count_10w = parseInt(lScore/100000);
- var count_1w = parseInt((lScore-count_10w*100000)/10000);
- var count_1000 = parseInt((lScore-count_10w*100000-count_1w*10000)/1000);
- var count_100 = parseInt((lScore-count_10w*100000-count_1w*10000-count_1000*1000)/100);
- for(let i=0; i<count_10w;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[4]);
- gold.parent = goldNode;
- gold.setPosition(cc.v2(-pos.x,-pos.y));
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
- gold.runAction(moveto);
- }
- for(let i=0; i<count_1w;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[3]);
- gold.parent = goldNode;
- gold.setPosition(cc.v2(-pos.x,-pos.y));
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
- gold.runAction(moveto);
- }
- for(let i=0; i<count_1000;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[2]);
- gold.parent = goldNode;
- gold.setPosition(cc.v2(-pos.x,-pos.y));
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
- gold.runAction(moveto);
- }
- for(let i=0; i<count_100;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[1]);
- gold.parent = goldNode;
- gold.setPosition(cc.v2(-pos.x,-pos.y));
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- let moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
- gold.runAction(moveto);
- }
- }
- else
- {
- for(let i=0; i<lScore; i++)
- {
- var gold = cc.instantiate(this.goldPrefabArr[0]);
- gold.parent = goldNode;
- gold.setPosition(cc.v2(-pos.x,-pos.y));
-
- var randx = Math.floor(Math.random() * 70);
- var randy = Math.floor(Math.random() * 50);
- var moveto = cc.moveTo(0.3,cc.v2(posDe.x+randx,posDe.y+randy));
-
- gold.runAction(moveto);
- }
- }
- var isshow = CServerItem.get().mGameServer.ServerType != 1;
-
- this.node.runAction(cc.sequence(cc.delayTime(0.3), cc.callFunc(() => {
- scoreNode.getChildByName("score").getComponent(cc.Label).string = lScore;
- scoreNode.active = true;
- scoreNode.getChildByName("fen").active = isshow;
- }, this)));
- }
- else
- {
- if (CServerItem.get().mGameServer.ServerType == 1) //金豆场金豆
- {
- var count_10w = parseInt(lScore/100000);
- var count_1w = parseInt((lScore-count_10w*100000)/10000);
- var count_1000 = parseInt((lScore-count_10w*100000-count_1w*10000)/1000);
- var count_100 = parseInt((lScore-count_10w*100000-count_1w*10000-count_1000*1000)/100);
- for(let i=0; i<count_10w;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[4]);
- gold.parent = goldNode;
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
- }
- for(let i=0; i<count_1w;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[3]);
- gold.parent = goldNode;
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
- }
- for(let i=0; i<count_1000;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[2]);
- gold.parent = goldNode;
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
- }
- for(let i=0; i<count_100;i++)
- {
- let gold = cc.instantiate(this.goldPrefabArr[1]);
- gold.parent = goldNode;
- let randx = Math.floor(Math.random() * 70);
- let randy = Math.floor(Math.random() * 50);
- gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
- }
- }
- else
- {
- for(let i=0; i<lScore; i++)
- {
- var gold = cc.instantiate(this.goldPrefabArr[0]);
- gold.parent = goldNode;
- var randx = Math.floor(Math.random() * 70);
- var randy = Math.floor(Math.random() * 50);
- gold.setPosition(cc.v2(posDe.x+randx,posDe.y+randy));
- }
- }
-
- var isshow = CServerItem.get().mGameServer.ServerType != 1;
- scoreNode.getChildByName("score").getComponent(cc.Label).string = lScore;
- scoreNode.active = true;
- scoreNode.getChildByName("fen").active = isshow;
- }
- },
- playerEnter: function() {
- this.labName.node.active = true;
- this.sprEmptyHeadIcon.node.active = false;
- this.sprHeadIcon.node.active = true;
- //百人场 不需要显示金豆,昵称
- this.btnHead.node.userID = this.getUserID();
- this.btnHead.node.gameID = this.getGameID();
- },
- playerLeave:function() {
- // this.node.active = false;
- // this.sprVipIcon.node.active = false;
- },
- upPlayerState: function() {
- this.setOffline(this.getUserStatus() == Define.US_OFFLINE);
- if (this.getUserStatus() == Define.US_OFFLINE) {
- //置灰
- // this.sprHeadIcon.node.color = cc.Color.GRAY;
- }
- else {
- //复原
- this.sprHeadIcon.node.color = cc.Color.WHITE;
- }
- },
- upPlayerInfo: function() {
- if (this.getNickName() != "") {
- var str = this.getNickName();
- this.labName.string = str;//Global.subStr(str);
- }
- if (CServerItem.get().mGameServer.ServerType == 1)
- {
- this.setScore(this.getUserScore());
- }
- // vip 头像框
- let vipID = this.getVIPLevel();
- let node = this.sprVipIcon;
- Global.print("upPlayerHead")
- if(vipID >= 4 && vipID <= 7) {
- // if(this.iIndex == 0) {
- node.getComponent(cc.Sprite).spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
- node.active = true;
- // }
- }else{
- node.active = false;
- }
- },
- setChairID: function(chairID){
- this._chairID = chairID
- },
- getChairID: function(){
- return this._chairID;
- },
- getnickName: function()
- {
- return this.labName.string
- },
- upPlayerHead: function() {
- var self=this;
- if (this.getHeadHttp() != "") {
- // 设置头像
- this.sprHeadIcon.getComponent("urlSpriteFrame").loadAvatar(this.getHeadHttp(),null, {width:100, height:100});
- } else {
- this.sprHeadIcon.spriteFrame = this.spriteFrame;
- this.sprHeadIcon.node.width = 100;
- this.sprHeadIcon.node.height = 100;
- }
- let vipID = this.getVIPLevel();
- if(vipID >= 4 && vipID <= 7) {
- this.sprVipIcon.spriteFrame = cc.vv.globalUserInfo.getVIPSpriteFrameByFaceID(vipID);
- this.sprVipIcon.node.active = true;
- }else{
- this.sprVipIcon.node.active = false;
- }
- },
- getHeadIcon: function(ret) {
- if(ret)
- {
- return this.sprHeadIcon.spriteFrame;
- }
- if (this.getHeadHttp() != "") {
- return this.sprHeadIcon.spriteFrame;
- }
- return null;
- },
- showTalkState: function(data) {
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TALK_TYPE) {
-
- }
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD) {
- this.runPaoMaDeng(data.String);
- }
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_DEFINE) {
- var strArr = data.String.split(":",2);
- BRTPSoundFun.playEffectDefineString(strArr[0]);
- this.runPaoMaDeng(strArr[1]);
- }
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING) {
- this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").active = true;
- var cpgAni = this.node.getChildByName("ChatNode").getChildByName("BiaoqingNode").getComponent(sp.Skeleton);
- var aniName = data.String.substr(0,2);
- cpgAni.setAnimation(0,aniName,false);
- }
- },
- showVoice: function(data) {
- this.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = true;
- var self = this;
- var voice1 = this.node.getChildByName("ChatNode").getChildByName("VoiceNode").getChildByName("Voice1");
- var voice2 = this.node.getChildByName("ChatNode").getChildByName("VoiceNode").getChildByName("Voice2");
- voice1.active = false;
- voice2.active = false;
- var time = 0;
- var Voice1Visible = function() {
- voice1.active = true;
- voice1.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice1NoVisible)));
- }
- var Voice2Visible = function() {
- time += 0.6;
- voice2.active = true;
- voice2.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice2NoVisible)));
- }
- var Voice1NoVisible = function() {
- if (time > 5)
- {
- return;
- }
- voice1.active = false;
- voice1.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice1Visible)));
- }
- var Voice2NoVisible = function() {
- time += 0.6;
- if (time > 5)
- {
- self.node.getChildByName("ChatNode").getChildByName("VoiceNode").active = false;
- }
- else
- {
- voice2.active = false;
- voice2.runAction(cc.sequence(cc.delayTime(0.6),cc.callFunc(Voice2Visible)));
- }
-
- }
- voice.serverId = data.SerVerID;
- voice1.runAction(cc.callFunc(Voice1Visible));
- voice2.runAction(cc.sequence(cc.delayTime(0.3),cc.callFunc(Voice2Visible)));
- },
- runPaoMaDeng: function(content) {
- var chatBubble = this.node.getChildByName("ChatNode").getChildByName("ChatBubble");
- chatBubble.active = true;
- chatBubble.opacity = 255;
- chatBubble.stopAllActions();
-
- var label = chatBubble.getChildByName("msg");
- label.active = true;
- label.getComponent(cc.Label).string = content;
- chatBubble.height = label.height + 33;
- var fadeOut = cc.sequence(cc.delayTime(4),cc.fadeOut(2.0));
- chatBubble.runAction(fadeOut);
- },
- setScore: function(score)
- {
- this._myScore = score;
- var ScoreImagic = this.node.getChildByName("PlayerInfo").getChildByName("ScoreImagic");
- var strScore = this.changeScore(Global.formatString2Score(score));
- ScoreImagic.getChildByName("Score").getComponent(cc.Label).string = strScore;
- },
- getScore: function() {
- return this._myScore;
- },
- addScoreAni: function(score)
- {
- if(score == 0){
- return;
- }
- var s = Math.abs(score);
- var strScore = this.changeScore(s);
- var scoreAni = this.node.getChildByName("scoreAni");
- if(score < 0)
- {
- scoreAni.getChildByName("scoreWinLabel").active = false;
- scoreAni.getChildByName("scoreLoseLabel").active = true;
- scoreAni.getChildByName("scoreLoseLabel").getChildByName("label").getComponent(cc.Label).string = "-"+strScore;
- }
- else if(score > 0)
- {
- scoreAni.getChildByName("scoreWinLabel").active = true;
- scoreAni.getChildByName("scoreLoseLabel").active = false;
- scoreAni.getChildByName("scoreWinLabel").getChildByName("label").getComponent(cc.Label).string = "+"+strScore;
- }
-
- scoreAni.active = true;
- scoreAni.getComponent(cc.Animation).play("showScoreAni");
- },
- setHost: function(isHost) {
- this.sprHostFlag.node.active = isHost;
- },
- setStatusHu: function(isHu) {
- this.node.getChildByName("Status_Hu").active = isHu;
- },
- setOffline: function(isOffline) {
- // this.sprOffineFlag.node.active = isOffline;
- },
- setReady: function(isReady) {
- this.sprReadyFlag.node.active = isReady;
- },
- resetSeatPos: function(pos) {
- this.node.getChildByName("PlayerHead").position = pos;
- },
- playMoveAction: function(pos) {
- var moveto = cc.moveTo(1,pos);
- this.node.getChildByName("PlayerHead").runAction(moveto);
- },
- startGameNoTime: function(pos) {
- this.node.getChildByName("PlayerHead").setPosition(pos);
- },
- playWinAni: function() {
- const aniNode = this.node.getChildByName("WinAni");
- if(aniNode) {
- aniNode.active = true;
- aniNode.getComponent(sp.Skeleton).setAnimation(0, "a1", false);
- // aniNode.getComponent(sp.Skeleton).setTrackCompleteListener(
- // () => {
- // aniNode.active = false;
- // }
- // );
- }
- },
- changeScore (score,isEnglish) {
- var strScore = score.toString();
- if(score >= 100000000000) //千亿
- {
- strScore = strScore.slice(0,4);
- // strScore = parseInt(strScore) / 10;
- if(isEnglish)
- {
- strScore = strScore + "y"
- }
- else
- {
- strScore = strScore + "亿"
- }
- }
- else if(score >= 10000000000) //百亿
- {
- strScore = strScore.slice(0,3);
- // strScore = parseInt(strScore) / 10;
- if(isEnglish)
- {
- strScore = strScore + "y"
- }
- else
- {
- strScore = strScore + "亿"
- }
- }
- else if(score >= 1000000000) //十亿
- {
- strScore = strScore.slice(0,3);
- strScore = parseInt(strScore) / 10;
- if(isEnglish)
- {
- strScore = strScore + "y"
- }
- else
- {
- strScore = strScore + "亿"
- }
- }
- else if(score >= 100000000) //亿
- {
- strScore = strScore.slice(0,3);
- strScore = parseInt(strScore) / 100;
- if(isEnglish)
- {
- strScore = strScore + "y"
- }
- else
- {
- strScore = strScore + "亿"
- }
- }
- else if(score >= 10000000) //千万
- {
- strScore = strScore.slice(0,4);
- if(isEnglish)
- {
- strScore = strScore + "w"
- }
- else
- {
- strScore = strScore + "万"
- }
- }
- /*else if(score >= 1000000) //百万
- {
- strScore = strScore.slice(0,3);
- if(isEnglish)
- {
- strScore = strScore + "w"
- }
- else
- {
- strScore = strScore + "万"
- }
- }*/
- // else if(score >= 100000) //十万
- // {
- // strScore = strScore.slice(0,3);
- // strScore = parseInt(strScore) / 10;
- // if(isEnglish)
- // {
- // strScore = strScore + "w"
- // }
- // else
- // {
- // strScore = strScore + "万"
- // }
- // }
- else
- {
- strScore = parseFloat(score).toFixed(2);
- }
- return strScore;
- },
- });
|