| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- cc.Class({
- extends: cc.Component,
- properties: {
- BDebug: {
- default: true,
- serializable: true,
- },
- ActionPowerlabel: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- GameConfig: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- onLoad () {
- this.ActionPower = 99;
- this.Coin = 5000;
- this.Diamond = 40;
- this.Fans=0;
- this.FavorableImpression=0;
- this.TalentRemainTime = 0;
- this.BTalentFinished = 0;
- this.MakeUpRemainTime = 0;
- this.BMakeUpFinished = 0;
- this.EloquenceRemainTime = 0;
- this.BEloquenceFinished = 0;
- this.FashionRemainTime = 0;
- this.BFashionFinished = 0;
- this.DanceRemainTime = 0;
- this.BDanceFinished = 0;
- //Event
- this.VarietyShowRemainTime = 0;
- this.BVarietyShowFinished = 0;
- this.InterviewRemainTime = 0;
- this.BInterviewFinished = 0;
- this.MovieRemainTime = 0;
- this.BMovieFinished = 0;
- this.HangOutRemainTime = 0;
- this.BHangOutFinished = 0;
- this.GirlAnimations = ['Idle'];
- },
- start () {
- this.GameConfigScript = this.GameConfig.getComponent('GameConfig');
- },
- //actionPower
- GetActionPower () {
- if(!this.BDebug) this.GetValueFromServer('ActionPower');
- return this.ActionPower;
- },
- SetActionPower (ActionPower) {
- this.SetValueFromServer('ActionPower',ActionPower);
- },
- PlusActionPower (Num,bUpdate) {
- let CurrentNum = this.ActionPower;
- let NewNum =CurrentNum + Num;
- if(bUpdate) this.SetValueFromServer('ActionPower',NewNum);
- this.ActionPowerScript = this.ActionPowerlabel.getComponent('ValueChange');
- this.ActionPowerScript.PlusOrMinusValue(CurrentNum,Num);
- },
- //Coin
- GetCoin () {
- if(!this.BDebug) this.GetValueFromServer('Coin');
- return this.Coin;
- },
- SetCoin (Coin) {
- this.SetValueFromServer('Coin',Coin);
- },
- PlusCoin (Num,bUpdate) {
- let CurrentNum = this.Coin;
- let NewNum =CurrentNum + Num;
- if(bUpdate) this.SetValueFromServer('Coin',NewNum);
- // this.ActionPowerScript = this.ActionPowerlabel.getComponent('ValueChange');
- // this.ActionPowerScript.PlusOrMinusValue(CurrentNum,Num);
- },
- //diamond
- GetDiamond () {
- if(!this.BDebug) this.GetValueFromServer('Diamond');
- return this.Diamond;
- },
- SetDiamond (Diamond) {
- this.SetValueFromServer('Diamond',Diamond);
- },
- PlusDiamond (Num,bUpdate) {
- let CurrentNum = this.Diamond;
- let NewNum =CurrentNum + Num;
- if(bUpdate) this.SetValueFromServer('Diamond',NewNum);
- // this.ActionPowerScript = this.ActionPowerlabel.getComponent('ValueChange');
- // this.ActionPowerScript.PlusOrMinusValue(CurrentNum,Num);
- },
- //fans
- GetFans () {
- if(!this.BDebug) this.GetValueFromServer('Fans');
- return this.Fans;
- },
- SetFans (Fans) {
- this.SetValueFromServer('Fans',Fans);
- },
- PlusFans (Num,bUpdate) {
- let CurrentNum = this.Fans;
- let NewNum =CurrentNum + Num;
- if(bUpdate) this.SetValueFromServer('Fans',NewNum);
- // this.ActionPowerScript = this.ActionPowerlabel.getComponent('ValueChange');
- // this.ActionPowerScript.PlusOrMinusValue(CurrentNum,Num);
- },
- //favorableImpression
- GetFavorableImpression () {
- if(!this.BDebug) this.GetValueFromServer('FavorableImpression');
- return this.FavorableImpression;
- },
- SetFavorableImpression (FavorableImpression) {
- this.SetValueFromServer('FavorableImpression',FavorableImpression);
- },
- PlusFavorableImpression (Num,bUpdate) {
- let CurrentNum = this.FavorableImpression;
- let NewNum =CurrentNum + Num;
- if(bUpdate) this.SetValueFromServer('FavorableImpression',NewNum);
- // this.ActionPowerScript = this.ActionPowerlabel.getComponent('ValueChange');
- // this.ActionPowerScript.PlusOrMinusValue(CurrentNum,Num);
- },
- GetValueFromServer(Key)
- {
- let URL = this.GameConfigScript.Host+'GameStates/Get'+Key+'/?Openid='+ cc.sys.localStorage.getItem('Openid');
- let XHR = new XMLHttpRequest();
- let Self = this;
- XHR.onreadystatechange = function () {
- if (XHR.readyState == 4 && (XHR.status >= 200 && XHR.status < 400)) {
- let response = XHR.responseText;
- Self.SaveValueFromServer(Key,response);
- // console.log(response);
- }
- };
- XHR.open("GET", URL, false);
- XHR.setRequestHeader("Content-Type" , "application/json");
- XHR.send();
- },
- SetValueFromServer(Key,Value)
- {
- let Data = 'Openid='+ cc.sys.localStorage.getItem('Openid')+'&'+'Value='+Value;
- let URL = this.GameConfigScript.Host+'GameStates/Set'+Key+'/';
- let XHR = new XMLHttpRequest();
- var Self =this;
- XHR.onreadystatechange = function ()
- {
- if (XHR.readyState == 4 && (XHR.status >= 200 && XHR.status < 400))
- {
- let response = XHR.responseText;
- // console.log(response);
- Self.SaveValueFromServer(Key,response);
- }
- };
- XHR.open("POST", URL, false);
- XHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
- XHR.send(Data);
- },
- SaveValueFromServer(Key,Value)
- {
- if(Key=='ActionPower')
- {
- this.ActionPower = Number(Value);
- }
- else if(Key=='Coin')
- {
- this.Coin = Number(Value);
- }
- else if(Key=='Diamond')
- {
- this.Diamond = Number(Value);
- }
- else if(Key=='Fans')
- {
- this.Fans = Number(Value);
- }
- else if(Key=='FavorableImpression')
- {
- this.FavorableImpression = Number(Value);
- }
- }
- });
|