123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- const interactInfo = require('../data/interactInfo');
- var { UserInteractionType, UserIntimacyType } = require('../utils/GameEnum');
- var UserInformationApi = require('../net/UserInformationApi');
- const DWTool = require('../utils/DWTool');
- const GameModule = require('../utils/GameModule');
- const interactImage = [
- {
- image: 'interact_1.png',
- title: '为你点了一杯咖啡,点击查收'
- },
- {
- image: 'interact_2.png',
- title: '这个礼物。。。你喜欢么?'
- },
- {
- image: 'interact_3.png',
- title: '五星级料理,你来我就请!'
- },
- ]
- cc.Class({
- extends: cc.Component,
- properties: {
- //互动次数已满提示
- interactionFullNode: cc.Node,
- //互动CD中提示
- interactionCDNode: cc.Node,
- timeLabel: cc.Label,
- //亲密度显示
- intimacyNode: cc.Node,
- //反抗成功
- revoltSuccessNode: cc.Node,
- //讨好成功
- playUpSuccessNode: cc.Node,
- //互动选项节点
- interactionSelectNode: cc.Node,
- interactionTitleRichText: cc.RichText,
- interactionCountLabel: cc.Label,
- //互动选项item
- interactionItemPrefab: cc.Prefab,
- },
- // LIFE-CYCLE CALLBACKS:
- init(uid, interactionInfo, userInformation) {
- this.node.parent = cc.find("Canvas");
- this.node.setContentSize(cc.view.getVisibleSize());
- this.node.active = false;
- this.uid = uid;
- this.userInformation = userInformation;
- this.interactionInfo = interactionInfo;
- },
- onLoad() {
- GameModule.homeGuide.on('Fire_state26', this.selectInteraction, this);
- GameModule.homeGuide.on('Fire_state27', this.playUpShare, this);
- },
- start() {
- },
- onDisable() {
- this.node.zIndex = 0;
- this.hideAllNode();
- //销毁选项
- for (let child of this.interactionSelectNode.children) {
- if (child.getComponent('UserInteractionItem') != undefined) {
- child.destroy();
- }
- }
- this.activeNode = null;
- },
- update(dt) {
- if (this.interactionCDNode.active === true) {
- var curTimestamp = parseInt(new Date().getTime());
- if ((this.cdEnd - curTimestamp) > 0) {
- this.timeLabel.string = DWTool.calculateTime((this.cdEnd - curTimestamp) / 1000);
- } else {
- this.showInteraction();
- }
- }
- },
- closeNodeAction() {
- // this.node.active = false;
- this.hideNodeAnimation();
- },
- hideAllNode() {
- this.interactionFullNode.active = false;
- this.interactionCDNode.active = false;
- this.intimacyNode.active = false;
- this.revoltSuccessNode.active = false;
- this.playUpSuccessNode.active = false;
- this.interactionSelectNode.active = false;
- },
- showNodeAnimation(showNode) {
- this.activeNode = showNode;
- showNode.setScale(0, 0);
- let scaleAnimation = cc.scaleTo(0.15, 1, 1);
- showNode.runAction(scaleAnimation);
- },
- hideNodeAnimation() {
- if (this.activeNode) {
- let scaleAnimation = cc.scaleTo(0.15, 0, 0);
- let finish = cc.callFunc(() => {
- this.node.active = false;
- }, this);
- let sequenceAcation = cc.sequence(scaleAnimation, finish);
- this.activeNode.runAction(sequenceAcation);
- } else {
- this.node.active = false;
- }
- },
- //亲密度显示
- showIntimacyInfo(isCommon) {
- this.node.zIndex += 1;
- this.node.active = true;
- this.hideAllNode();
- this.intimacyNode.active = true;
- this.showNodeAnimation(this.intimacyNode);
- this.intimacyMng = this.intimacyNode.getComponent('UserIntimacyInfo');
- this.intimacyMng.configIntimacyInfo(this.interactionInfo, true, isCommon);
- },
- //互动操作相关
- showInteraction(interactionType) {
- this.node.zIndex += 1;
- this.node.active = true;
- if (interactionType != undefined) {
- this.interactionType = interactionType;
- }
- if (this.interactionInfo.cnt >= 5) {
- this.interactionIsFull();
- return;
- }
- if (this.interactionIsCD() == true) {
- return;
- }
- this.hideAllNode();
- this.interactionSelectNode.active = true;
- this.showNodeAnimation(this.interactionSelectNode);
- if (this.interactionInfo.cnt) {
- this.interactionCountLabel.string = `剩余互动次数:${(5 - this.interactionInfo.cnt)}/5`;
- } else {
- this.interactionCountLabel.string = '剩余互动次数:5/5';
- }
- var originY = (this.interactionSelectNode.height / 2) - 120;
- switch (this.interactionType) {
- case UserInteractionType.Common:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>互 动</b></outline>";
- interactInfo.interactInfo5.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (16 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.PlayUp:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>讨 好</b></outline>";
- interactInfo.interactInfo1.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (16 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.Revolt:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>反 抗</b></outline>";
- interactInfo.interactInfo2.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (16 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- case UserInteractionType.Pacify:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>安 抚</b></outline>";
- interactInfo.interactInfo3.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (16 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state26');
- break;
- case UserInteractionType.Order:
- this.interactionTitleRichText.string = "<outline color=#e1596c width=3><b>使 唤</b></outline>";
- interactInfo.interactInfo4.forEach(item => {
- var itemNode = cc.instantiate(this.interactionItemPrefab);
- itemNode.parent = this.interactionSelectNode;
- itemNode.y = originY;
- originY -= (16 + 80);
- var itemMng = itemNode.getComponent('UserInteractionItem');
- itemMng.init(this);
- itemMng.configData(item);
- });
- break;
- }
- },
- selectInteraction() {
- UserInformationApi.postInteract(this.uid, this.interactionType, (responseData) => {
- this.interactionInfo = responseData;
- this.interactionResponse(responseData);
- this.userInformation.configIntimacy(responseData);
- }, (error) => {
- console.log('互动失败' + error);
- });
- },
- interactionResponse(responseData) {
- this.hideAllNode();
- switch (this.interactionType) {
- case UserInteractionType.Common:
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- break;
- case UserInteractionType.PlayUp:
- if (responseData.heart == UserIntimacyType.Full) {
- this.intimacyNode.active = true;
- this.showNodeAnimation(this.intimacyNode);
- this.intimacyMng = this.intimacyNode.getComponent('UserIntimacyInfo');
- this.intimacyMng.configIntimacyInfo(this.interactionInfo, true, false);
- } else {
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- }
- break;
- case UserInteractionType.Revolt:
- this.revoltSuccessNode.active = true;
- this.showNodeAnimation(this.revoltSuccessNode);
- break;
- case UserInteractionType.Pacify:
- if (responseData.heart == UserIntimacyType.Full) {
- this.intimacyNode.active = true;
- this.showNodeAnimation(this.intimacyNode);
- this.intimacyMng = this.intimacyNode.getComponent('UserIntimacyInfo');
- this.intimacyMng.configIntimacyInfo(this.interactionInfo, true, false);
- } else {
- this.playUpSuccessNode.active = true;
- this.showNodeAnimation(this.playUpSuccessNode);
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideStateNext('state26', 'state27');
- }
- break;
- case UserInteractionType.Order:
- this.revoltSuccessNode.active = true;
- this.showNodeAnimation(this.revoltSuccessNode);
- break;
- }
- this.interactionInfo.cd = responseData.cd;
- this.interactionInfo.cdEnd = responseData.cdEnd;
- this.interactionInfo.cnt = responseData.cnt;
- this.interactionInfo.heart = responseData.heart;
- this.interactionInfo.intimacy = responseData.intimacy;
- this.playUpSuccessMng = this.playUpSuccessNode.getComponent('UserIntimacyInfo');
- let isCommon = this.interactionType == UserInteractionType.Common ? true : false;
- this.playUpSuccessMng.configIntimacyInfo(this.interactionInfo, false, isCommon);
- },
- //当天互动次数已满
- interactionIsFull() {
- this.hideAllNode();
- this.interactionFullNode.active = true;
- this.showNodeAnimation(this.interactionFullNode);
- },
- //正在CD中
- interactionIsCD() {
- this.hideAllNode();
- var curTimestamp = parseInt(new Date().getTime()); //当前时间戳
- this.cdEnd = this.interactionInfo.cdEnd;
- if ((this.cdEnd - curTimestamp) > 0) {
- this.interactionCDNode.active = true;
- this.showNodeAnimation(this.interactionCDNode);
- this.timeLabel.string = DWTool.calculateTime((this.cdEnd - curTimestamp) / 1000);
- return true;
- } else {
- return false;
- }
- },
- //消耗钻石加速CD时间
- speedCDAction() {
- UserInformationApi.postSpeedInteraction(this.uid, (responseData) => {
- this.interactionInfo.cnt += 1;
- this.interactionInfo.cdEnd = 0;
- GameModule.userInfo.diamond -= 20;
- this.showInteraction();
- }, (errCode, errMsg) => {
- if (CC_WECHATGAME) {
- wx.showModal({
- title: "提示",
- content: errMsg
- });
- } else {
- alert(errMsg);
- }
- });
- },
- //讨好、安抚成功分享
- playUpShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- let shareItem = interactImage[Math.floor(Math.random() * 3)]
- var shareTitle = Global.user.nick + ':' + shareItem.title;
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'https://pub.dwstatic.com/wxgame/allstar/share/' + shareItem.image,
- success: (res) => {
- },
- fail: (res) => {
- }
- });
- },
- //反抗、使唤成功分享
- revoltShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- var shareTitle = '真解气,一起来反抗老板的剥削!';
- if (this.interactionType == UserInteractionType.Order) {
- shareTitle = '真爽,一起来使唤艺人!';
- }
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'https://pub.dwstatic.com/wxgame/allstar/share/share1.jpg',
- });
- },
- //邀请互动
- inviteInteractionShare() {
- if (!CC_WECHATGAME) {
- return;
- }
- var shareTitle = this.userInformation.userInfo.nick + '你今天还没有和我进行互动~快来一起玩';
- window.wx.shareAppMessage({
- title: shareTitle,
- imageUrl: 'https://pub.dwstatic.com/wxgame/allstar/share/interact_0.png',
- });
- }
- });
|