JS - 私人医生(想看哪里点哪里)

/**
 * Created by lgy on 2020/10/14.
 */
var CustomGames = cc.Layer.extend({
    init:function(){
        this.bg = getUI(this, "bg");
        this.bg.setPositionY(SH/2);

        this.nTop = getUI(this, "nTop");
        this.nTop.setPositionY(SH);
        this.nTop.setBlangs(true);
        this.nodeTalk1 = getUI(this.nTop, "nodeTalk1");
        this.nodeTalk1.setVisible(false);
        this.nodeTalk2 = getUI(this.nTop, "nodeTalk2");
        this.nodeTalk2.setVisible(false);

        this.nContents = getUI(this,"nContents");
        this.cureText = getUI(this,"cureText");
        UIUtil.setOutline(this.cureText, ColorDefine.ARMOUR_OUTLINE_COLOR_1, ColorDefine.OUTLINE_SIZE_ONE_PIXEL);
        this.cureText.setString(G_S.CUSTOMGAME_JS_10);
        this.cureText.setVisible(false);

        this.nBottom = getUI(this, "nBottom");
        this.nBottom.setBlangs();
        this.sprTingZhenQi = getUI(this, "sprTingZhenQi");
        this.sprTingZhenQi.setVisible(false);

        this.timeNode = getUI(this,"timeNode");
        this.timeNode.setVisible(true);
        this.nCDTime = CountDown.getCom(this, "nCDTime");
        this.nCDTime.setMyTextColor(ColorDefine.ARMOUR_TEXT_COLOR_1,ColorDefine.ARMOUR_TEXT_COLOR_2);
        this.nCDTime.setMyOutline(ColorDefine.ARMOUR_OUTLINE_COLOR_1, ColorDefine.OUTLINE_SIZE_ICON_TXTNAME);

        var btInfo = getUI(this.nTop, "btInfo");
        btInfo.addClickEventListener(this.onIntroduce.bind(this));

        this.btBack = getUI(this.nTop, "btBack");
        this.btBack.addTouchEventListener(this.onClickBack.bind(this));

        TextureUtil.isNeedReleaseUIShenmiaoEffect = true;

        this.sprHeartBg = getUI(this, "sprHeartBg");
        this.sprHeartBg.setVisible(false);
        this.sptHeartBgHeight = this.sprHeartBg.getContentSize().height;
        this.txtHeart = getUI(this.sprHeartBg, "txtHeart");
        this.txtHeart.ignoreContentAdaptWithSize(true);
        this.heartNode = getUI(this.sprHeartBg, "heartNode");

        this.lightNode = getUI(this,"lightNode");

        this.ScrollView = getUI(this, "ScrollView");
        this.ScrollView.setPositionY(BOTTOM_H + this.sptHeartBgHeight);
        this.ScrollView.setContentSize(SW, SH-156-BLANGS_TOP-BOTTOM_H - this.sptHeartBgHeight);
        this.ScrollView.setScrollBarEnabled(false);
        this.ScrollView_Width = this.ScrollView.getContentSize().width;
        this.ScrollView_Height = this.ScrollView.getContentSize().height;
        this.ScrollView.setTouchEnabled(true);
        this.posSV = this.ScrollView.getPosition();
        // this.incoSVPosY = this.ScrollView.getInnerContainerPosition();

        this.nextClickType = -1;//下一个点击类型
        this.nextClickBody = -1;//下一个点击部位
        this.realClickCount = 0;//触发真实部位点击次数
        this.gameStatus = 0;//游戏状态 0:普通 1:克制 2:被克制
        this.armature_zi_aniname = "start6";
        this.iSendData = false;
        this.score = 0;//得分
        this.heartNum = 0;//心跳指数
        this.leftTime = 0;
        this.isAchieve = false;//是否完成
        this._armature_heart_name = "start13";
        this.fzSize = cc.size(640,1600);
    },

    showContents:function (){
        this.createCustomMaidSpine();//创建定制少女spine
        this.createConcubineTouch(); //给妃子添加点击效果
        this.showTipSpine();//播放提示spine
    },

    //给妃子添加点击效果
    createConcubineTouch: function () {
        this.createTouchLayer();//创建点击层
        this.createGrid();//创建栅格
        this.createTipEffect();//创建部位提示特效节点
    },

    createCustomMaidSpine: function () {
        this.feiZiEftNode = new cc.Node();
        this.feiZiEftNode.removeAllChildren();
        var girlInfo = DD[T.AIGirlInfo];
        var customMaidSpine = new CustomMaidSpine();
        // customMaidSpine.setSkinData(mCustomMaid.getPartSkinConfigs());
        customMaidSpine.setSkinData(mCustomMaid.getPartSkinConfigs({
            useHairstyle: girlInfo.useHairstyle,
            useMakeUp: girlInfo.useMakeUp,
            useShoes: girlInfo.useShoes,
            useUnderwear: girlInfo.useUnderwear}));
        this.feiZiEftNode.addChild(customMaidSpine);
    },

    showTipSpine:function() {
        var self = this;
        //start1听诊器点一点,start2听诊器长按,start3长按,start4点一点,start5手指点一点 start7向上箭头,start8向下箭头,start9精神不佳,start10身体不适
        //start13 心电图默认 start14 心电图暧昧 start15 心电图悸动 start16 心电图兴奋 start17 心电图痴迷
        var path = C_RES_SPINE + "spine_dingzhishaonv/spine_yiwushi_000/spine_yiwushi_000.json";
        // var path = C_RES_SPINE + "hongyan/hongyan001_a/hongyan001_a.json";
        preloadEffectsWithCallback([path], function () {
            self._armature_gesture = showEffect(self.touchControl, path, "start1", 1, null, self, null, cc.p(0, 0));
            self._armature_gesture.setVisible(false);
            self._armature_long = showEffect(self.touchControl, path, "start2", 1, null, self, null, cc.p(0, 0));
            self._armature_long.setVisible(false);
            self._armature_gesture_zi = showEffect(self, path, "start3", 1, null, self, null, cc.p(SW / 2, 360));
            self._armature_gesture_zi.setVisible(false);
            self._armature_upDown = showEffect(self, path, "start7", 1, null, self, null, cc.p(SW - 50, SH / 2));
            self._armature_upDown.setVisible(false);
            self._armature_zi = showEffect(self, path, "start9", 0, null, self, null, cc.p(SW / 2, COTENT_H - 70));
            self._armature_zi.setVisible(false);


            self._armature_heart = showEffect(self.heartNode, path, "start13", 1, null, self, null, cc.p(0, 0));
            var aniName = self.getCurAniName();
            if (aniName != "-1"){
                self._armature_heart_name = aniName;
                self._armature_heart.setVisible(true);
                self._armature_heart.setAnimation(0, aniName, 1);
            }else{
                self._armature_heart.setVisible(false);
            }


            //少女放大
            var path2 = "res/image/effects/eft_hougong_chongxing01/eft_hougong_chongxing01.ExportJson";
            preloadEffectsWithCallback([path2], function () {
                self._armature_light = showEffect(self.lightNode, path2, "start", 0, null, self, null, cc.p(0, SH / 2));
                self._armature_light.setVisible(false);
            });

        });
    },

    //创建栅格
    createGrid: function () {
        var lines = 28;              //栅格行
        var columns = 16;              //栅格列
        this.isFinish = true;           //点击效果是否全部展示完
        this.rectList = [];
        var rectWidth = this.ScrollView_Width / columns;
        var rectHeight = this.fzSize.height / lines;
        for (var i = 0; i < lines; i++) {
            for (var j = 0; j < columns; j++) {
                var posX = j * rectWidth;
                var posY = i * rectHeight;
                var rect = cc.rect(posX, posY, rectWidth, rectHeight);
                this.rectList.push(rect);
            }
        }
    },

    createTipEffect:function (){
        this.tipsEffectNode = [];
        for (var i in this.infoList){
            var eventCoordinates = this.infoList[i].eventCoordinates;
            var rect = this.getCoordinateRectById(parseInt(eventCoordinates));
            var node = new cc.Node();
            this.touchControl.addChild(node);
            node.setPosition(cc.p(rect.x,rect.y));
            this.tipsEffectNode.push(node);
        }
    },

    //创建点击层
    createTouchLayer: function () {
        var innerHeight = this.fzSize.height;
        if(innerHeight < this.ScrollView_Height){
            innerHeight = this.ScrollView_Height;
        }
        this.ScrollView.setInnerContainerSize(cc.size(this.ScrollView_Width, innerHeight));
        this.ScrollView.jumpToTop();

        this.touchControl = new ccui.Layout();
        this.touchControl.setBackGroundColorType(ccui.Layout.BG_COLOR_NONE);//BG_COLOR_SOLID
        this.touchControl.setBackGroundColor(ColorDefine.LOADLAYER_BACKGROUND_BGCOLOR);
        this.touchControl.setBackGroundColorOpacity(180);
        this.touchControl.setContentSize(cc.size(this.ScrollView_Width,innerHeight));
        this.touchControl.setTouchEnabled(true);
        this.touchControl.setSwallowTouches(false);
        this.touchControl.addTouchEventListener(this.onTouch, this);
        this.ScrollView.addChild(this.touchControl);
        this.touchControl.setAnchorPoint(cc.p(0.5,1.0));
        this.touchControl.setPosition(this.ScrollView_Width / 2, this.fzSize.height);

        this.feiZiEftNode.setPosition(cc.p(320,0));
        this.touchControl.addChild(this.feiZiEftNode);
        //栅格测试
        // this.createGrideTest();
    },

    //少女点击事件
    onConcubineTouch:function (clickType) {
        var sender = this.sender;
        this.touchData = null;
        var touchData = this.judgeTouchPosOfBody(sender);
        if(touchData.isTouch){
            this.touchData = touchData;
            this.showTouchEft(sender,touchData);
            this.playBodySound(touchData.info.partEffect);//部位音效
            var duiBaiData = this.getRandomDuiBaiIndex(touchData.info.partLine);//部位台词
            var normalDuiBai = Config.X3Duibai[duiBaiData.duiBaiId];
            var text = mCustomMaid.formatDuiBaiStringByCall(normalDuiBai.text);
            this._showTalk(text);
            this.onDiagnosis(clickType);
            this.isFinish = false;
        }
    },

    //判断点击了妃子哪个部位
    judgeTouchPosOfBody: function (sender) {
        // var touchWorldPos = sender.getTouchBeganPosition();
        // touchNodePos = this.touchControl.convertToNodeSpace(sender.getTouchEndPosition());
        touchNodePos = sender.convertToNodeSpace(sender.getTouchEndPosition());
        this.touchWorldPos = sender.getTouchEndPosition();
        this.touchNodePos = touchNodePos;
        var touchData = {};
        touchData.isTouch = false;                                  //是否点中了妃子有效部位
        for (var i in this.infoList) {
            var info = this.infoList[i];
            var bodyList = info.coordinate.split(";");
            for (var key in bodyList) {
                var touchRect = this.getCoordinateRectById(bodyList[key]);
                if (touchRect != null && cc.rectContainsPoint(touchRect, touchNodePos)) {
                    touchData.info = info;
                    touchData.isTouch = true;
                    return touchData;
                }
            }
        }
        return touchData;
    },

    getCoordinateRectById: function (id) {
        var curId = parseInt(id) - 1;
        var rect = null;
        for (var key in this.rectList) {
            if (parseInt(key) == curId) {
                rect = this.rectList[key];
                return rect;
            }
        }
        return rect;
    },

    //显示点击特效
    showTouchEft: function (sender,touchData) {
        var self = this;
        var pos = sender.convertToNodeSpace(sender.getTouchEndPosition());
        var path = "res/image/effects/eft_hougong_dianji/eft_hougong_dianji.ExportJson";
        preLoadEffect(path, null, function () {
            var node = showEffect(sender, path, "start", 0, null, null, true, cc.p(pos.x, pos.y));
            node.getAnimation().setMovementEventCallFunc(function (armature, movementType, movementID) {
                if (movementType == ccs.MovementEventType.complete) {
                    armature.removeFromParent();
                }
            }, self);
        });
    },

    _showTalk: function (sayInfo) {
        var self = this;
        var nodeTalk;
        if (Math.random() < 0.5) {
            nodeTalk = this.nodeTalk1;
            this.nodeTalk2.setVisible(false);
            this.nodeTalk1.setVisible(true);
        } else {
            nodeTalk = this.nodeTalk2;
            this.nodeTalk1.setVisible(false);
            this.nodeTalk2.setVisible(true);
        }

        if (!sayInfo)
            sayInfo = G_S.CUSTOMGAME_JS_9;

        nodeTalk.stopAllActions();
        nodeTalk.setScale(0.1);
        nodeTalk.setVisible(true);

        getUI(nodeTalk, "talkLabel").setString(sayInfo);
        nodeTalk.runAction(cc.sequence(cc.scaleTo(0.2, 1.2), cc.scaleTo(0.1, 1), cc.delayTime(3), cc.callFunc(function (node) {
            self.nodeTalk1.setVisible(false);
            self.nodeTalk2.setVisible(false);
        })))
    },

    /**
     * 处理诊断
     * @param clickType CLICK_TYPE_
     */
    onDiagnosis:function(clickType) {
        var offset = 5;
        var act = cc.sequence(
            cc.moveBy(0.05,cc.p(offset, offset)),
            cc.moveBy(0.05,cc.p(-offset, -offset)),
            cc.moveBy(0.05,cc.p(0, -offset)),
            cc.moveBy(0.05,cc.p(0, offset))
        );
        this.ScrollView.setPosition(this.posSV);
        this.ScrollView.stopAllActions();
        this.ScrollView.runAction(act.easing(cc.easeSineOut()));

        this.iSendData = true;
        this.curClickType = clickType;
        this.showGameStatus();
        this.diagnosisBody();//诊断身体
        this.unschedule(this.sendClickAIGirl);
        this.schedule(this.sendClickAIGirl,1.0);
    },

    sendClickAIGirl: function () {
        if(!this.iSendData) {
            return;
        }
        DC.wsData("ClickAIGirl/" + this.score + "/" + this.heartNum);
        cc.log("已经发送数据:score ,heartNum",this.score,this.heartNum);
        this.iSendData = false;
    },

    onIntroduce: function(){
        var data = {};
        data.title = G_S.CUSTOMGAME_JS_11;
        data.content = [

            G_S.CUSTOMGAME_JS_1,
            G_S.CUSTOMGAME_JS_2,
            G_S.CUSTOMGAME_JS_3,
            G_S.CUSTOMGAME_JS_4,
            G_S.CUSTOMGAME_JS_5
        ];
        data.isTouchEnable = true;
        HUD.showLayer(HUD_LIST.Tip_CommonRuleInfo, HUD.getTipLayer(), null ,true, function(tip){
            tip.setData(data);
        }, this);
    },

    onClickBack: function (sender, type) {
        var ok = touch_process_bt(sender, type);
        if(ok) {
            this.hide();
        }
    },

    /**
     * 添加划一划支持
     */
    createStreak:function(){
        if(this._streak != null)
            this._streak.removeFromParent();

        if (!(!cc.sys.isNative && cc._renderType == cc.game.RENDER_TYPE_CANVAS)) {

            this._streak = new cc.MotionStreak(0.5, 1, 20, ColorDefine.GODSEXPERIMENT_STREAK_COLOR, "res/image/ui/common/disable/streak.png");
            this.addChild(this._streak);
        }
    },


    onTouch:function (sender, type) {
        this.sender = sender;
        switch (type) {
            case ccui.Widget.TOUCH_BEGAN:
                this.ScrollView.setTouchEnabled(true);
                this.sprTingZhenQi.setVisible(false);
                this.pt1 = sender.getTouchBeganPosition();
                // this.createStreak();
                this._doStreak = false;//滑动
                this._doLongPress = false;//长按
                this.schedule(this.showLongPress, 0.2);
                break;
            case ccui.Widget.TOUCH_MOVED:
                var pt = sender.getTouchMovePosition();
                if(this._streak){
                    this._streak.setPosition(pt);
                }

                if( cc.pDistance(this.pt1, pt) > 10){
                    this.unschedule(this.showLongPress);
                    this.pt1 = pt;
                    this._doStreak = true;
                    //指引
                    this.showTipUpDown(0);//type 0:move 1:end
                }
                break;
            case ccui.Widget.TOUCH_ENDED:
                this.ScrollView.setTouchEnabled(true);
                this.unschedule(this.showLongPress);
                if ( !this._doStreak && !this._doLongPress) {
                    this.pt1 = sender.getTouchEndPosition();
                    this.onConcubineTouch(this.CLICK_TYPE_POLITE);
                }
                this._doLongPress = false;//长按
                this._armature_long.setVisible(false);
                //指引特效
                this.showTipUpDown(1);//type 1:move 0:end
                //部位特效
                this.showTipGesture();
                break;
            case ccui.Widget.TOUCH_CANCELED:
                break;
            default:
                break;
        }
    },

    showTipUpDown:function (type){
        if(this.nextClickBody != -1 && this._armature_heart_name != "-1"){
            var info = this.infoList[this.nextClickBody];
            var eventCoordinates = info.eventCoordinates;
            var rect = this.getCoordinateRectById(parseInt(eventCoordinates));
            var eftNode = this.tipsEffectNode[this.nextClickBody];
            var eftNodeWorldPos = eftNode.convertToWorldSpace(cc.p(0,0));
            var svNodePos = this.ScrollView.convertToNodeSpace(eftNodeWorldPos);
            var rect2 = cc.rect(eftNodeWorldPos.x, eftNodeWorldPos.y-rect.height, rect.width, rect.height*3);
            var isIntersect = cc.rectIntersectsRect(this.ScrollView.getBoundingBox(), rect2);
            var aniName;
            if (svNodePos.y <=0){
                aniName = "start8";
            }else{
                aniName = "start7";
            }
            if (type==1){
                this.isIntersect = isIntersect
                if (!isIntersect){
                    this._armature_upDown.setAnimation(0, aniName, true);
                    this._armature_upDown.setVisible(true);
                }else{
                    this._armature_upDown.setVisible(false);
                }
            }else{
                if(this.isIntersect != isIntersect){
                    this.isIntersect = isIntersect
                    if (!isIntersect){
                        this._armature_upDown.setAnimation(0, aniName, true);
                        this._armature_upDown.setVisible(true);
                    }else{
                        this._armature_upDown.setVisible(false);
                    }
                }
            }

        }else{
            this._armature_upDown.setVisible(false);
        }
    },

    showTipGesture:function (){
        if(this.nextClickBody != -1 && this._armature_heart_name != "-1"){
            this._armature_gesture.setVisible(true);
            var eftNode = this.tipsEffectNode[this.nextClickBody];
            var aniName;
            if (this.gameStatus == 1){//点击
                aniName = "start5";
            }else if(this.gameStatus == 2){//长按
                aniName = "start1";
            }
            if (this._armature_gesture.getPosition() != eftNode.getPosition() || this._armature_gesture_aniname != aniName){
                this._armature_gesture.setAnimation(0, aniName, true);
                this._armature_gesture.setPosition(eftNode.getPosition());
            }
        }else{
            this._armature_gesture.setVisible(false);
        }

        if (this.iHideNode){
            this._armature_gesture.setVisible(false);
        }
    },

    showLongPress:function(){
        this._doLongPress = true;//长按
        this.ScrollView.setTouchEnabled(false);
        // this.unschedule(this.showLongPress);
        this.onConcubineTouch(this.CLICK_TYPE_LONG);
    },

    showDiagnosisMessage:function(msg, fontSize, color){
        var node = new cc.Node();
        HUD.getTipLayer().addChild(node);
        var txt = createLabel(msg, UIUtil.getFontName(), fontSize, color, null, ColorDefine.OUTLINE_COLOR_GODSEXPERIMENT_HURTMESSAGE, ColorDefine.OUTLINE_SIZE_GODSEXPERIMENT_HURTMESSAGE);
        txt.setPosition(0, 0);

        node.addChild(txt);
        node.setPosition(cc.p(SW*0.5, SH*0.5));
        node.setOpacity(255);

        var moveTo = cc.moveBy(0.3, cc.p(0, 180));
        var fadeOut = cc.fadeOut(1);
        var act = cc.spawn(moveTo, fadeOut);
        var clean = cc.removeSelf();
        var actSeq = cc.sequence(act, clean);
        node.runAction(actSeq);
        node.setGlobalZOrder(100);
    },

    diagnosisBody: function(){
        if(!this.touchData || !this.touchData.isTouch) return;
        var info = this.touchData.info;
        var value, fontSize, msg, score,heartNum;
        var color = ColorDefine.GODSEXPERIMENT_HURTMESSAGE1_COLOR;
        switch (this._diagnosisType) {
            case this.GAME_STATUS.ORIDINART:
                fontSize = 36;
                msg = "";
                score = info.averageScore;//普攻得分
                heartNum = info.cardiacIndex;//普攻指数
                break;
            case this.GAME_STATUS.RESTRAINT:
                fontSize = 54;
                msg = G_S.CUSTOMGAME_JS_7.format(parseInt(info.restraintIndex));
                score = info.restraintScore;//克制得分
                heartNum = info.restraintIndex;//克制指数
                break;
            case this.GAME_STATUS.RESTRAINED:
                fontSize = 54;
                msg = G_S.CUSTOMGAME_JS_8.format(parseInt(info.unrestrainIndex));
                color = ColorDefine.GODSEXPERIMENT_HURTMESSAGE2_COLOR;
                score = info.unrestrainScore;//被克制得分
                heartNum = info.unrestrainIndex;//被克制指数
                break;
        }

        this.score += parseInt(score);
        this.heartNum += parseInt(heartNum);
        this.showDiagnosisMessage(msg, fontSize, color);
        this.showHeartEffect();
        this.showSpineBigger();

    },

    //播放点击部位音效
    playBodySound:function(soundStr){
        if(soundStr == null) return;
        if(this.BodyAudio){
            mAudio.stopEffect(this.BodyAudio);
            this.BodyAudio = null;
        }
        this.BodyAudio =  mAudio.playEffect(res_sound_root + "zhubo/" + soundStr + ".mp3");
    },

    playDelayEffect:function (){
        // mAudio.stopEffect(this.BodyAudio);
        this.BodyAudio = null;
    },

    //对白
    getRandomDuiBaiIndex: function (duibaiList) {

        if (!duibaiList || duibaiList == "") {
            cc.log("warning,getRandomDuiBaiIndex config data has no this duibai array");
            return null;
        }

        var duiBaiData = {};
        var dataList = [];
        dataList = duibaiList.split(";");
        if(dataList.length <= 0) return null
        var duiBaiIndex = GetRandomNum(0, (dataList.length - 1));
        duiBaiData.duiBaiId = dataList[duiBaiIndex];
        duiBaiData.duiBaiIndex = duiBaiIndex;
        return duiBaiData;
    },

    showGameStatus: function (){
        var status = this.getGameStatus();
        if (this.gameStatus != status){
            this.gameStatus = status;
        }
        var aniName1;
        var aniName2;
        var aniName3;
        switch (status) {
            case 0:
                this._armature_gesture.setVisible(false);
                this._armature_gesture_zi.setVisible(false);
                this._armature_zi.setVisible(false);
                break;
            case 1:
                aniName1 = "start5";
                aniName2 = "start4";
                aniName3 = "start9";
                this._armature_gesture.setVisible(true);
                this._armature_gesture_zi.setVisible(true);
                this._armature_zi.setVisible(true);
                break;
            case 2:
                aniName1 = "start1";
                aniName2 = "start3";
                aniName3 = "start10";
                this._armature_gesture.setVisible(true);
                this._armature_gesture_zi.setVisible(true);
                this._armature_zi.setVisible(true);
                break;
        }

        if(this._doLongPress){//长按
            var pos = this.touchControl.convertToNodeSpace(this.pt1);
            this._armature_long.setPosition(pos);
            this._armature_long.setVisible(true);
            this._armature_gesture.setVisible(false);
        }

        if(this._armature_gesture.isVisible() && this._armature_gesture_aniname != aniName1){
            this._armature_gesture_aniname = aniName1;
            this._armature_gesture.setAnimation(0, aniName1, true);
        }

        if(this._armature_gesture_zi.isVisible() && this._armature_gesture_zi_aniname != aniName2 ){
            this._armature_gesture_zi_aniname = aniName2;
            this._armature_gesture_zi.setAnimation(0, aniName2, true);
        }

        if(this._armature_zi.isVisible() && this._armature_zi_aniname != aniName2 ){
            this._armature_zi_aniname = aniName3;
            this._armature_zi.setAnimation(0, aniName3, true);
        }

    },

    getGameStatus: function () {
        var status = 0;
        if(!this.touchData || !this.touchData.isTouch) return status;
        if (this.nextClickBody != -1){
            this.realClickCount++;
            // cc.log("lgy1----------this.nextClickBody:this.realClickCount:",this.nextClickBody,this.realClickCount);
            if(this.touchData.info.id == this.infoList[this.nextClickBody].id && this.nextClickType == this.curClickType){
                this._diagnosisType = this.GAME_STATUS.RESTRAINT;//克制
            }else{
                this._diagnosisType = this.GAME_STATUS.RESTRAINED;//被克制
            }

            if (this.realClickCount >= parseInt(this.infoList[this.nextClickBody].eventNum)){
                this.realClickCount = 0;
                this.nextClickBody = -1;
                this.nextClickType = -1;
                status = 0;
            }else{
                status = this.gameStatus;
            }
        }else{
            status = 0;
            var info = this.touchData.info;
            var triggerEventWeight = info.triggerEventWeight;//触发事件权重
            var random1 = GetRandomNum(1,100);
            if (random1 <= triggerEventWeight){
                var ewList = info.eventWeight.split(";");//事件权重(点一点还是长按)
                var ewTotal = parseInt(ewList[0]) + parseInt(ewList[1]);
                var cur = 0;
                var bodyWeight = [];
                for (var i in this.infoList){
                    cur += parseInt(this.infoList[i].triggerPositionWeight);
                    bodyWeight.push(cur);//2,5,8,10
                }
                var random2 = GetRandomNum(1,bodyWeight[bodyWeight.length-1]);
                var idx;
                for (idx in bodyWeight) {
                    if (random2 <= bodyWeight[idx]) {
                        this.nextClickBody = parseInt(idx);//下一个点击部位
                        // cc.log("lgy2----------this.nextClickBody:this.realClickCount:",this.nextClickBody,this.realClickCount);
                        break;
                    }
                };
                var random3 = GetRandomNum(1,ewTotal);
                if(random3 <= parseInt(ewList[0])){//点一点
                    this.nextClickType = this.CLICK_TYPE_POLITE;//下一个点击类型
                    status = 1;
                }else{//长按
                    this.nextClickType = this.CLICK_TYPE_LONG;//下一个点击类型
                    status = 2;
                }
                // cc.log("lgy----------this.nextClickBody:",this.nextClickBody);
            }
            this._diagnosisType = this.GAME_STATUS.ORIDINART;//普通
        }

        return status;
    },

    randGodPractice: function (max) {
        var multiplier = Math.pow(5, 5);
        var moder = Math.pow(2, 35) - 31;
        var random_seed = 1;

        var next_seed = random_seed * multiplier % moder;
        var next_seed_int = Math.floor(next_seed);
        var ret = next_seed_int / moder;
        this.random_seed = parseInt(next_seed_int);

        ret = Math.ceil(ret*max);
        return parseInt(ret);
    },

    onEnter: function () {
        this._super();

        this.addCustomListener(P.TypeAIGirlDoctor, this.onAIGirlDoctor.bind(this));
        this.addCustomListener(P.TypeAIGirlDoctorResult, this.onAIGirlDoctorResult.bind(this));

        DC.wsData("GetAIGirlDoctor");


    },

    onExit: function () {
        this._super();
        this.releaseCustomListener();
    },

    cleanup:function(){

    },

    //显示心率
    showHeartEffect:function (){
        this.txtHeart.setString(G_S.CUSTOMGAME_JS_6.format(this.heartNum));
        var aniName = this.getCurAniName();
        if (this._armature_heart_name != aniName){
            this._armature_light.setVisible(true);
            this._armature_light.getAnimation().play("start",-1,0);
            if(aniName != "-1"){
                this._armature_heart.setAnimation(0, aniName, 1);
            }
        }
    },

    getCurAniName:function (){
        var heartNumTotal = parseInt(getConstValue(2000130));//定制少女心动指数最大值
        var percent = Math.floor(this.heartNum*100/heartNumTotal);
        var aniName = "start13";
        if (percent >= 100){
            aniName = "-1";
        }else if (percent >= 80){
            aniName = "start17";
        }else if (percent >= 60){
            aniName = "start16";
        }else if (percent >= 40){
            aniName = "start15";
        }else if (percent >= 20){
            aniName = "start14";
        }
        return aniName;
    },

    showSpineBigger:function() {
        var aniName = this.getCurAniName();
        if (this._armature_heart_name != aniName){
            this.unschedule(this.showLongPress);
            var innerPosition = this.ScrollView.getInnerContainerPosition();
            this.iHideNode = true;
            this._armature_heart_name = aniName;
            this.timeNode.setVisible(false);
            this.touchControl.setTouchEnabled(false);
            this.ScrollView.setTouchEnabled(false);
            this.ScrollView.setPositionY(BOTTOM_H);
            this.ScrollView.setContentSize(SW, SH-156-BLANGS_TOP-BOTTOM_H+70);
            this.sprHeartBg.setVisible(false);
            var scale = this.touchData.info.magnification;//点击部位缩放比例
            this.feiZiEftNode.setScale(scale);
            var centerPos = this.getTouchCenterPosByTouchPos();
            this.feiZiEftNode.setPosition(centerPos);

            if (aniName == "-1") {
                this._showTalk();
            }else{
                this.nodeTalk1.setVisible(false);
                this.nodeTalk2.setVisible(false);
            }

            var visible1 = this.nextClickBody != -1;
            var visible2 = this._armature_gesture_zi.isVisible();
            var visible3 = this._armature_zi.isVisible();
            var visible4 = this._armature_upDown.isVisible();

            this._armature_long.setVisible(false);
            this._armature_gesture.setVisible(false);
            this._armature_gesture_zi.setVisible(false);
            this._armature_zi.setVisible(false);
            this._armature_upDown.setVisible(false);
            this.scheduleOnce(function(){
                this.iHideNode = false;
                if (aniName == "-1"){
                    this.gameOver();
                }else{
                    this.timeNode.setVisible(true);
                    this.feiZiEftNode.setScale(1);
                    this.feiZiEftNode.setPosition(cc.p(320,0));
                    this.touchControl.setTouchEnabled(true);
                    this.ScrollView.setTouchEnabled(true);
                    this.ScrollView.setPositionY(BOTTOM_H + this.sptHeartBgHeight);
                    this.ScrollView.setContentSize(SW, SH-156-BLANGS_TOP-BOTTOM_H-this.sptHeartBgHeight);
                    this.sprHeartBg.setVisible(true);

                    this._armature_gesture.setVisible(visible1);
                    this._armature_gesture_zi.setVisible(visible2);
                    this._armature_zi.setVisible(visible3);
                    this._armature_upDown.setVisible(visible4);

                    this.ScrollView.setInnerContainerPosition(innerPosition);
                    this.showTipUpDown(1);
                }
            }.bind(this),4.0);
        }

    },

    //通过触摸点获取pine实际点放大后位于(ScrollView中心点或屏幕中心点)的位置
    getTouchCenterPosByTouchPos:function (){
        var info = this.touchData.info;
        var scale = info.magnification;//点击部位缩放比例
        var pos = this.feiZiEftNode.getPosition();
        var dx = this.touchNodePos.x - pos.x;
        var x = pos.x - dx * (scale - 1);
        var y = pos.y - this.touchNodePos.y * (scale - 1);
        var pos1 = cc.p(x, y);
        // var touchCenterPos = this.ScrollView.convertToNodeSpace(this.touchWorldPos);
        // var svCenterPos = cc.p(this.ScrollView.getContentSize().width/2,this.ScrollView.getContentSize().height/2);
        // var pos2 = cc.pSub(svCenterPos,touchCenterPos);
        var touchCenterPos = this.touchControl.convertToNodeSpace(cc.p(SW/2,SH/2));
        var pos2 = cc.pSub(touchCenterPos, this.touchNodePos);

        return cc.pAdd(pos1, pos2);
    },

    gameOver:function (){
        this.nextClickBody = -1;
        this.cureText.setVisible(true);
        this.timeNode.setVisible(true);
        this.ScrollView.removeAllChildren();
        HUD.showLayer(HUD_LIST.CustomGameReward, HUD.getTipLayer(), null, true,function(tip){
            tip.setData();
        },null,false);
    },

    onAIGirlDoctorResult: function () {

    },

    onAIGirlDoctor: function () {
        var data = DD[T.AIGirlDoctor];
        if (data){
            this.heartNum = data.heartNum;
            this.score = data.score;
            this.leftTime = data.leftTime;
            this.isAchieve = data.isAchieve;//是否完成
            this.nCDTime.setData(Math.floor(this.leftTime/1000));
            this.txtHeart.setString(G_S.CUSTOMGAME_JS_6.format(this.heartNum));
        }

        if (this.isAchieve){
            this.sprTingZhenQi.setVisible(false);
            this.sprHeartBg.setVisible(false);
            this.cureText.setVisible(true);
            this.timeNode.setVisible(true);
            this.ScrollView.removeAllChildren();
        }else{
            this.sprTingZhenQi.setVisible(true);
            this.sprHeartBg.setVisible(true);
            this.infoList = mCustomMaid.getCustomGameListByType(1);
            //创建妃子点击效果
            this.showContents();
        }

    },

    //栅格测试代码
    createGrideTest:function (){
        // 测试代码,点击妃子的栅格显示
        var lines = 28;              //栅格行
        var columns = 16;              //栅格列
        var rectWidth = this.ScrollView_Width / columns;
        var rectHeight = this.fzSize.height / lines;
        for (var i = 0; i < lines; i++) {
            var drawNode =new cc.DrawNode();
            drawNode.drawSegment(cc.p(0, i * rectHeight), cc.p(this.ScrollView_Width, i * rectHeight), 1, cc.color(255,0,0));
            drawNode.setPosition(cc.p(0, 0));
            this.touchControl.addChild(drawNode);
        }
        for (var i = 0; i < columns; i++) {
            var drawNode =new cc.DrawNode();
            drawNode.drawSegment(cc.p(i * rectWidth, 0), cc.p(i * rectWidth, this.fzSize.height), 1, cc.color(255,0,0));
            drawNode.setPosition(cc.p(0, 0));
            this.touchControl.addChild(drawNode);
        }
        var idx = 1;
        for (var i = 0; i < lines; i++) {
            for (var j = 0; j < columns; j++) {
                var posX = j * rectWidth;
                var posY = i * rectHeight;
                var txtIdx = new ccui.Text(idx, UIUtil.getFontName(), 18);
                UIUtil.setOutline(txtIdx, cc.color(0,0,0),2);
                txtIdx.setPosition(posX + rectWidth / 2, posY + rectHeight / 2);
                this.touchControl.addChild(txtIdx);
                ++idx;
            }
        }
    },

});

CustomGames.prototype.CLICK_TYPE_LONG = 1;  //长按

CustomGames.prototype.CLICK_TYPE_POLITE = 0;//点一点

CustomGames.prototype.GAME_STATUS = {
    ORIDINART: 0,  //普通
    RESTRAINT: 1,   //克制
    RESTRAINED: 2  //被克制
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值