123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- var GamePlayer = require("GamePlayer");
- var Define = require("Define");
- var Global = require("Global");
- var UIHelper = require("UIHelper");
- import { CServerItem } from 'CServerItem'
- import ScenceManager from 'HNScenceManager'
- var BaseDefine = require("BaseDefine");
- var SoundFun = require("CachetaSoundFun");
- var GameProtocol = require("CachetaGameProtocol");
- var ProtocolGameServer = require("ProtocolGameServer")
- cc.Class({
- extends: GamePlayer,
- //extends: cc.Component,
- editor: {
- menu: 'Game/Cacheta/GamePlayer'
- },
- properties: {
- sprHeadIcon:cc.Sprite, //头像
- sprVipIcon:cc.Sprite, // VIP框
- btnHead:cc.Button,
- btnGift:cc.Button,
- sprEmptyHeadIcon:cc.Sprite,
- labScore:cc.Label, //分数
- labName:cc.Label, //昵称
- infoNode: cc.Node,
- cardsNode: cc.Node,
- huAniNode: cc.Node,
- OffineFlag:cc.Node, //离线标记
- TrusteeFlag: cc.Node,
- readyNode:cc.Node,
- labScoreW:cc.Label,
- labScoreL:cc.Label,
- iIndex:-1,
- _CurGameScene:null,
- _myScore:0,
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad: function() {
- this.handCardPos = [
- cc.v2(-500,-440),
- cc.v2(-750,120),
- cc.v2(-177,447),
- cc.v2(750,120)];
- this.endCardPos = [
- cc.v2(-500,-440),
- cc.v2(-750,120),
- cc.v2(-200,400),
- cc.v2(750,120)];
- this.endCoinPos = [
- cc.v2(-478,-323),
- cc.v2(-574,0),
- cc.v2(0,181),
- cc.v2(574,7)];
- this.beizeOutMidPos = [
- cc.v2(0,0),
- cc.v2(0,555),
- cc.v2(555,555),
- cc.v2(0,555)];
- this.beizePickMidPos = [
- cc.v2(555,555),
- cc.v2(0,555),
- cc.v2(555,555),
- cc.v2(0,555)];
- this._isGameEnd = false;
- this._tenCardPosX = 724;
- this.infoNode.active = false;
- this.huAniNode.active = false;
- this.needPlayScoreAni = false;
- this.trusteeState = 0;
- // this.sprVipIcon.node.width = 118;
- // this.sprVipIcon.node.height = 118;
- this.sprVipIcon.node.scale = 0.25;
- this.myHandCards = [];
- this.hideHandCard();
- },
-
- init: function(index) {
-
- },
- playerEnter: function(){
- Global.print("用户playerEnter")
- this.node.getChildByName("PlayerHead").active = true;
- // this.sprEmptyHeadIcon.node.active = false;
- this.sprHeadIcon.node.active = true;
- this.btnHead.node.userID = this.getUserID();
- this.btnHead.node.gameID = this.getGameID();
- this.btnGift.node.userID = this.getUserID();
- this.btnGift.node.gameID = this.getGameID();
- this.node.active = true;
- this.infoNode.active = true;
- this.needPlayScoreAni = false;
- this.changeTrusteeState(0);
- this.setScore(this.getUserScore());
- // this.trusteeState = 0;
- this.hideWinLoseAni();
- this.hideHuAni();
- this.hideTimeNode();
- this.node.getChildByName("AndroidTip").active = (this.getAndroidTip()==1 && BaseDefine.LOCALTEST);
- },
- playerLeave:function() {
- this.labName.string = "";
- this.sprEmptyHeadIcon.node.active = true;
- this.sprHeadIcon.node.active = false;
- this.infoNode.active = false;
-
- this.node.getChildByName("AndroidTip").active = false;
- this.hideTimeNode();
- this.upPlayerInfo();
- this.upPlayerHead();
- this.upPlayerState();
- this.showWarning(false);
- Global.print("用户离开了")
- this.sprVipIcon.node.active = false;
- this.node.active = false;
- },
- upPlayer:function(show)
- {
- this.upPlayerInfo();
- this.upPlayerHead();
- this.node.active = show;
- },
- upPlayerState: function() {
- this.setOffline(this.getUserStatus() == Define.US_OFFLINE);
- },
- upPlayerInfo: function() {
- if (this.getNickName() != "") {
- var str = this.getNickName();
- let len = 6;
- this.labName.string = Global.subStr(str,len);
- }
- // this.setScore(this.getUserScore());
- },
- setNameLabelActive:function(show){
- this.infoNode.active = show;
- },
- setVIPActive:function(show){
- this.sprVipIcon.node.active = show;
- },
- getnickName: function()
- {
- return this.labName.string
- },
- upPlayerHead: function() {
- 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;
- }
- this.sprHeadIcon.node.active = true;
- 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;
- }
- },
- getHeadSpriteFrame() {
- return this.sprHeadIcon.spriteFrame;
- },
- getVIPSpriteFrame() {
- return this.sprVipIcon.spriteFrame;
- },
- //游戏结束,隐藏VIP框
- hideVIP() {
- this.sprVipIcon.node.active = false;
- },
- getHeadIcon: function(ret) {
- if(ret)
- {
- return this.sprHeadIcon.spriteFrame;
- }
- if (this.getHeadHttp() != "") {
- return this.sprHeadIcon.spriteFrame;
- }
- return null;
- },
- getIndex: function() {
- return this.iIndex;
- },
- setScore: function(score) {
- this._myScore = score;
- var strScore = this.changeScore(Global.formatString2Score(score));
- this.labScore.string = strScore;
- },
- getScore: function() {
- return this._myScore;
- },
- setOffline: function(isOffline) {
- this.OffineFlag.active = isOffline;
- if (isOffline) {
- //置灰
- this.sprHeadIcon.node.color = cc.Color.GRAY;
- }
- else {
- //复原
- this.sprHeadIcon.node.color = cc.Color.WHITE;
- }
- },
- setEndGameState(bbb) {
- this.needPlayScoreAni = bbb;
- },
- getEndGameState() {
- return this.needPlayScoreAni;
- },
- setEndGameScore(score) {
- this.needPlayScore = score;
- },
- getEndGameScore() {
- return this.needPlayScore;
- },
- changeTrusteeState(state) {
- this.trusteeState = state;
- this.TrusteeFlag.active = state;
- this.labName.node.active = !state;
- },
- showWarning: function(isReady) {
- if(this.readyNode.active == isReady) return;
- this.readyNode.active = isReady;
- if(isReady) {
- SoundFun.playEffectEX(SoundFun.WARNING);
- let ani = this.readyNode.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- ani.addAnimation(0, "a1", false);
- ani.addAnimation(0, "a1", false);
- ani.addAnimation(0, "a2", true);
- }
- },
- playTimeAction: function(SystemLeftTime,UserLeftTime){
- this.node.getChildByName("TimeNode").active = true;
- this.node.getChildByName("TimeNode").getComponent("CachetaTimePointer").playTimeAction(SystemLeftTime,UserLeftTime,this.iIndex==0);
- },
- hideTimeNode:function(){
- this.node.getChildByName("TimeNode").active = false;
- this.node.getChildByName("TimeNode").getComponent("CachetaTimePointer").stopTimeSchedule();
- },
- showHuAni() {
- this.huAniNode.active = true;
- let ani = this.huAniNode.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "a1", false);
- },
- hideHuAni() {
- this.huAniNode.active = false;
- },
- hideWinLoseAni() {
- this.node.getChildByName("ani").active = false;
- this.node.getChildByName("scoreAni").active = false;
- },
- playWinOrLoseAni(bWin, addScore) {
- let aniNode = this.node.getChildByName("ani");
- aniNode.active = true;
- let scoreNode = this.node.getChildByName("scoreAni");
- let ani = aniNode.getComponent(sp.Skeleton);
- ani.clearTracks();
- if(bWin) {
- ani.setAnimation(0, "b1", false);
- ani.addAnimation(0, "b2", true);
- scoreNode.getChildByName("winNode").active = true;
- scoreNode.getChildByName("loseNode").active = false;
- this.labScoreW.string = Global.formatString2Score('+'+addScore);
- }else{
- ani.setAnimation(0, "b3", false);
- ani.addAnimation(0, "b4", true);
- scoreNode.getChildByName("winNode").active = false;
- scoreNode.getChildByName("loseNode").active = true;
- this.labScoreL.string = Global.formatString2Score(addScore);
- }
- scoreNode.active = true;
- scoreNode.getComponent(cc.Animation).play("showScoreAni");
- this.setScore(this.getUserScore());
- },
- playLiuJuAni() {
- let aniNode = this.node.getChildByName("ani");
- aniNode.active = true;
- let scoreNode = this.node.getChildByName("scoreAni");
- let ani = aniNode.getComponent(sp.Skeleton);
- ani.clearTracks();
- ani.setAnimation(0, "b3", false);
- ani.addAnimation(0, "b4", true);
- scoreNode.getChildByName("winNode").active = true;
- scoreNode.getChildByName("loseNode").active = false;
- this.labScoreW.string = '+0.00';
- scoreNode.active = true;
- scoreNode.getComponent(cc.Animation).play("showScoreAni");
- },
- start () {
-
- },
- showTalkState: function(data){
- if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TALK_TYPE){
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_WORD){
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_DEFINE){
- }else if (data.Type == ProtocolGameServer.CMD_GR_C_TableTalk.TYPE_BIAOQING)
- {
- if(data.String == ""){
- return;
- }
- let memeIdx = data.String;
- if(memeIdx <=0 || memeIdx >= 13){
- return;
- }
- this.node.getChildByName("GameMeme").active = true;
- var Ani = this.node.getChildByName("GameMeme").getComponent(sp.Skeleton);
- Ani.setAnimation(0,"a"+memeIdx,false);
- }
- },
- rePlayHandCardShow() {
- if(this.iIndex <= 0) return;
- this.cardsNode.active = true;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].position = this.handCardPos[this.iIndex];
- this.cardsNode.children[i].scale = 0.6;
- this.cardsNode.children[i].angle = 0;
- this.cardsNode.children[i].getComponent("CachetaCard").setId(0,0);
- this.cardsNode.children[i].active = true;
- }
- },
- getEndCoinPos() {
- return this.endCoinPos[this.iIndex];
- },
- getHandCardPos() {
- return this.handCardPos[this.iIndex];
- },
- getEndCardPos() {
- return this.endCardPos[this.iIndex];
- },
- hideHandCard() {
- if(!this.cardsNode) return;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].x = -160;
- this.cardsNode.children[i].y = 38;
- this.cardsNode.children[i].scale = 0.8;
- if(this.cardsNode.children[i].is3DNode) {
- this.cardsNode.children[i].eulerAngles = cc.v3(0,0,0);
- }else{
- this.cardsNode.children[i].angle = 0;
- }
- this.cardsNode.children[i].color = cc.color(255,255,255);
- this.cardsNode.children[i].getComponent("CachetaCard").setId(0,0);
- this.cardsNode.children[i].active = false;
- }
- this.cardsNode.active = true;
- this.huAniNode.active = false;
- this.myHandCards.splice(0);
- },
- resetHandCardPos() {
- if(!this.cardsNode) return;
- this.cardsNode.active = true;
- for(let i = 0; i < this.cardsNode.childrenCount; ++i) {
- this.cardsNode.children[i].x = -160;
- this.cardsNode.children[i].y = 38;
- this.cardsNode.children[i].scale = 0.8;
- if(this.cardsNode.children[i].is3DNode) {
- this.cardsNode.children[i].eulerAngles = cc.v3(0,0,0);
- }else{
- this.cardsNode.children[i].angle = 0;
- }
- // this.cardsNode.children[i].angle = 0;
- // this.cardsNode.children[i].zIndex = 10-i;
- // this.cardsNode.children[i].active = false//i > 0;
- }
- },
- pickLixoToMyHandCard(cardData, callback, endCall) {
- if(this.iIndex > 0) return;
- let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
- if(card) {
- card.getComponent("CachetaCard").setId(cardData, 0);
- card.active = true;
- card.position = cc.v2(167, 5);
- card.scale = 0.8;
- card.zIndex = 100;
- if(callback) {
- callback();
- }
- let endPos = cc.v2(this._tenCardPosX, -480);
- let midPos = this.beizePickMidPos[this.iIndex];
- let moveTime = 0.5;
- var opts1 = Object.create(null);
- opts1.progress = (start, end, current, t)=> {
- current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
- current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
- return current;
- }
- card.stopAllActions();
- cc.tween(card)
- .parallel(
- cc.tween().to(moveTime, {position: endPos}, opts1),
- cc.tween().to(moveTime, {scale: 1.2})
- )
- .call(()=>{
- if(endCall) {
- endCall();
- }
- })
- .start()
- }
- },
- pickMonteToMyHandCard(cardData, magicCards, callback) {
- if(this.iIndex > 0) return;
- let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
- if(card) {
- card.getComponent("CachetaCard").setId(0,0);
- card.active = true;
- card.position = cc.v2(-160, 5);
- card.scale = 0.8;
- card.zIndex = 100;
- let endPos = cc.v2(this._tenCardPosX, -480);
- let midPos = this.beizePickMidPos[this.iIndex];
- let moveTime = 0.5;
- var opts1 = Object.create(null);
- opts1.progress = (start, end, current, t)=> {
- current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
- current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
- return current;
- }
- card.stopAllActions();
- cc.tween(card)
- .parallel(
- cc.tween().to(moveTime, {position: endPos}, opts1),
- cc.tween().to(moveTime, {scale: 1.2})
- )
- .to(0.2, {eulerAngles: cc.v3(0,90,0)})
- .call(()=>{
- card.getComponent("CachetaCard").setId(cardData, magicCards);
- })
- .to(0.2, {eulerAngles: cc.v3(0,0,0)})
- .call(()=>{
- if(callback) {
- callback();
- }
- })
- .start()
- }
- },
- pickOneCardToHandCard(isDark, cardData, callback, endCall) {
- if(this.iIndex <= 0) return;
- let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
- if(card) {
- card.active = true;
- card.scale = 0.8;
- card.zIndex = 100;
- card.position = cc.v2(-160, 5);
- let cardd = 0;
- if(!isDark) {
- card.x = 167;
- cardd = cardData;
- if(callback) {
- callback();
- }
- }
- card.getComponent("CachetaCard").setId(cardd,0);
- let endPos = this.handCardPos[this.iIndex];
- let midPos = this.beizePickMidPos[this.iIndex];
- let moveTime = 0.5;
- var opts1 = Object.create(null);
- opts1.progress = (start, end, current, t)=> {
- current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
- current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
- return current;
- }
- card.stopAllActions();
- cc.tween(card)
- .parallel(
- cc.tween().to(moveTime, {position: endPos}, opts1),
- cc.tween().to(moveTime, {scale: 0.6})
- )
- .call(()=>{
- card.active = false;
- if(endCall) {
- endCall();
- }
- })
- .start()
- }
- },
- throwOneCardToLixo(cardId,magiccards,callback) {
- if(this.iIndex <= 0) return;
- let card = this.cardsNode.children[GameProtocol.HAND_CARD_COUNT];
- if(card) {
- card.getComponent("CachetaCard").setId(0,0);
- card.active = true;
- card.position = this.handCardPos[this.iIndex];
- card.scale = 0.6;
- let endPos = cc.v2(167, 5);
- let midPos = this.beizeOutMidPos[this.iIndex];//cc.v2(555,555);
- let moveTime = 0.5;
- var opts1 = Object.create(null);
- opts1.progress = (start, end, current, t)=> {
- current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
- current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
- return current;
- }
- card.stopAllActions();
- cc.tween(card)
- .parallel(
- cc.tween().to(moveTime, {position: endPos}, opts1),
- cc.tween().to(moveTime, {scale: 0.8})
- )
- .call(()=>{
- SoundFun.playEffectEX(SoundFun.FLIPCARD);
- })
- .to(0.15, {eulerAngles: cc.v3(0,90,0)})
- .call(()=>{
- card.getComponent("CachetaCard").setId(cardId,magiccards);
- })
- .to(0.15, {eulerAngles: cc.v3(0,0,0)})
- .call(()=>{
- if(callback) {
- callback();
- }
- card.active = false;
- })
- .start()
- }
- },
- throwMyCardToLixo(card, callback) {
- if(this.iIndex > 0) return;
- if(!card) return;
- card.active = true;
- card.color = cc.color(255,255,255);
- let endPos = cc.v2(167, 5);
- let midPos = this.beizeOutMidPos[this.iIndex];//cc.v2(555,555);
- let moveTime = 0.5;
- var opts1 = Object.create(null);
- opts1.progress = (start, end, current, t)=> {
- current.x = (1-t)*(1-t)*start.x+2*t*(1-t)*midPos.x+t*t*end.x;
- current.y = (1-t)*(1-t)*start.y+2*t*(1-t)*midPos.y+t*t*end.y;
- return current;
- }
- card.stopAllActions();
- cc.tween(card)
- .parallel(
- cc.tween().to(moveTime, {position: endPos}, opts1),
- cc.tween().to(moveTime, {scale: 0.8})
- )
- .call(()=>{
- card.active = false;
- if(callback) {
- callback();
- }
-
- })
- .start()
- },
- setHandCards(cards) {
- for(let i = 0; i < cards.length; ++i) {
- if(cards[i] > 0) {
- this.myHandCards.push(cards[i]);
- }
- }
- this.upSelfTrusteeState();
- },
- addOneCard(cardid) {
- if(cardid > 0) {
- this.myHandCards.push(cardid);
- this.upSelfTrusteeState();
- }
- },
- outOneCard(cardid) {
- for(let i = 0; i < this.myHandCards.length; ++i) {
- if(this.myHandCards[i] == cardid) {
- this.myHandCards.splice(i, 1);
- this.upSelfTrusteeState();
- return;
- }
- }
- },
- getHandCards() {
- return this.myHandCards;
- },
- upSelfTrusteeState() {
- if(this.iIndex > 0) return;
- if(!this.trusteeState) return;
- let maskW = this.myHandCards.length < 10 || this.myHandCards[9] == 0 ? 793 : 875;
- let jsGameSence = ScenceManager.Instance().getGameComponent();
- jsGameSence.upTrusteeMask(maskW);
- },
- });
|