123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- import {game,AudioClip,Prefab,Component, _decorator, Game ,director,Node} from "cc";
- import { ClientEvent } from "./clientEvent";
- import ItemDataConfig, { itemData } from "./config/ItemDataConfig";
- import { Constant, item_type } from "./constant";
- import GBoardChess from "./Game/ChessGame/GBoardChess";
- import { http } from "./Game/http";
- import UIDialog from "./Game/UIDialog";
- import ADSDK from "./gcommon/AdSdk/ADSDK";
- import ScenceMng from "./gcommon/ScenceMng";
- import UILoading from "./gcommon/UILoading";
- import { UIManager } from "./gcommon/UIManager";
- import { native_manager } from "./native_manager";
- import gameSocket from "./socket/gameSocket";
- import { msgManager } from "./socket/msgManager";
- import { Tools } from "./Tools";
- import { activityData } from "./UserData/activityData";
- import { bagData } from "./UserData/bagData";
- import { emailData } from "./UserData/emailData";
- import { privacyData } from "./UserData/privacyData";
- import { roomData } from "./UserData/roomData";
- import { userData } from "./UserData/userData";
- import { wearData } from "./UserData/wearData";
- import { welfareData } from "./UserData/welfareData";
- export const enum quit_chess_show_view{
- renji, //跳转人机选择界面
- haoyou,//跳转创建好友对战
- jifen,//跳转积分界面
- login,//登陆
- beitichu,
- }
- var check_status = 'wait';
- const { ccclass, property } = _decorator;
- @ccclass
- export class GameMng extends Component {
- // @property({ type: Prefab })
- // public chessselCell: Prefab | null = null;
- @property({ type: Prefab })
- public uiloading: Prefab | null = null;
- // @property({ type: Prefab })
- // public uisetting: Prefab | null = null;
- @property({ type: Prefab })
- public uitips: Prefab | null = null;
- @property({ type: Prefab })
- public uiduizhan: Prefab | null = null;
- @property({ type: Prefab })
- public uiDialog: Prefab | null = null;
- @property({ type: Prefab })
- public uiWaitView: Prefab | null = null;
- @property({ type: Prefab })
- public uiuserinfo: Prefab | null = null;
- @property({ type: Prefab })
- public uiSettingView: Prefab | null = null;
- @property({ type: Prefab })
- public uiChessSettingView: Prefab | null = null;
- @property(AudioClip)
- mainbgm: AudioClip = null;
- @property(AudioClip)
- buttonclick: AudioClip = null;
- @property(AudioClip)
- startclip: AudioClip = null;
- @property(AudioClip)
- winclip: AudioClip = null;
- @property(AudioClip)
- failclip: AudioClip = null;
- @property(AudioClip)
- eatclip: AudioClip = null;
- @property(AudioClip)
- pickclip: AudioClip = null;
- @property(AudioClip)
- putclip: AudioClip = null;
- @property(AudioClip)
- kingclip: AudioClip = null;
- @property(AudioClip)
- kill: AudioClip = null;
- @property(AudioClip)
- gamebgm: AudioClip = null;
- // @property({ type: Prefab })
- // public canjuCell: Prefab | null = null;
- @property({ type: Prefab })
- public createFirend: Prefab | null = null;
- @property({ type: Prefab })
- public joinRoom: Prefab | null = null;
- @property({ type: Prefab })
- public shop_view: Prefab | null = null;
- @property({ type: Prefab })
- public bag_view: Prefab | null = null;
- @property({ type: Prefab })
- public email_view: Prefab | null = null;
- @property({ type: Prefab })
- public activity_view: Prefab | null = null;
- @property({ type: Prefab })
- public welfare_view: Prefab | null = null;
- @property({ type: Prefab })
- public music_setting_view: Prefab | null = null;
- @property({ type: Prefab })
- public privacy_setting_view: Prefab | null = null;
- @property({ type: Prefab })
- public about_view: Prefab | null = null;
- @property({ type: Prefab })
- public self_info_view: Prefab | null = null;
- @property({ type: Prefab })
- public invite_firend_view: Prefab | null = null;
- @property({ type: Prefab })
- public send_firend_duizhan: Prefab | null = null;
- @property({ type: Prefab })
- public recv_firend_duizhan: Prefab | null = null;
-
- static Instance:GameMng=null;
- static _userData:userData = null;
- public loadingLayer: Node | null = null;
- public quit_view: quit_chess_show_view | null = null;
- static isFirstRunApp:boolean = false;
- static UserDataInstance(){
- if(GameMng._userData==null){
- GameMng._userData = new userData();
- }
- return GameMng._userData;
- }
- static getBagItemList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.dao_ju){
- list.push(element)
- }
- }
- return list
- }
- static getFirendList():userData[]{
- return GameMng._userData.firend_list
- }
- static getEmailList():emailData[]{
- return GameMng._userData.email_list
- }
- static getWelfareList():welfareData[]{
- let list = [];
- for (let index = 0; index < 10; index++) {
- list.push(new welfareData)
- }
- return list
- }
- static getActivityList():activityData[]{
- let list = [];
- for (let index = 0; index < 10; index++) {
- list.push(new activityData)
- }
- return list
- }
- static getBagQiPanList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.qi_pan){
- list.push(element)
- }
- }
- return list
- }
- static getBagQiZiList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.qi_zi){
- list.push(element)
- }
- }
- return list
- }
- static getBagTouXiangKuangList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.tou_xiang_kuang){
- list.push(element)
- }
- }
- return list
- }
- static getBagJiShiQiList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.ji_shi_qi){
- list.push(element)
- }
- }
- return list
- }
- static getBagQiPaoList():itemData[]{
- var list:itemData[] =[]
- for (let index = 0; index < GameMng._userData.bag.item_list.length; index++) {
- const element = GameMng._userData.bag.item_list[index];
- if(element.item_type===item_type.qi_pao){
- list.push(element)
- }
- }
- return list
- }
- static setUserData(_json:userData){
- // let str = JSON.stringify(_json)
- // let obj = JSON.parse(str)
- // GameMng._userData = obj as userData
- GameMng._userData = _json
- GameMng.temp();
- }
- /** @deprecated 💥临时调试使用。记得后面删掉 */
- static temp(){
- if(GameMng._userData.privacy==null||GameMng._userData.privacy==undefined){ //
- GameMng._userData.privacy = new privacyData()
- }
- if(GameMng._userData.bag==null||GameMng._userData.bag==undefined){ //
- GameMng._userData.bag = new bagData()
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("1001"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("1002"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("1003"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("4000"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("5000"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("6000"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("2000"))
- GameMng._userData.bag.item_list.push(ItemDataConfig.Instance.getItemById("3000"))
- }
- if(GameMng._userData.wear==null||GameMng._userData.wear==undefined){ //
- GameMng._userData.wear = new wearData()
- }
- if(GameMng._userData.firend_list==null||GameMng._userData.firend_list==undefined){ //
- GameMng._userData.firend_list = []
- for (let index = 1; index <=10; index++) {
- let u = new userData()
- u.user_name = index+"号测试人员"
- GameMng._userData.firend_list.push(u)
- }
- }
- if(GameMng._userData.email_list==null||GameMng._userData.email_list==undefined){ //
- GameMng._userData.email_list = []
- for (let index = 1; index <=10; index++) {
- let u = new emailData()
- u.title = index+"号测试人员"
- GameMng._userData.email_list.push(u)
- }
- }
- }
- static add_chat_history(id){
- if(GameMng._userData.room!=null){
- if(GameMng._userData.room.chat_history_list===null||GameMng._userData.room.chat_history_list===undefined){
- GameMng._userData.room.chat_history_list = []
- }
- GameMng._userData.room.chat_history_list.push(id)
- }
- }
- static updateRoomData(room:roomData){
- if(GameMng._userData!=null){
- if(GameMng._userData.room==null){
- GameMng._userData.room = new roomData()
- }
- if(room.rival==null){
- GameMng._userData.room.rival =null;
- }
- // if(room.chess==null){
- // GameMng._userData.room.chess =null;
- // }
- for (const key in room) {
- if (Object.prototype.hasOwnProperty.call(room, key)) {
- const element = room[key];
- GameMng._userData.room[key] = element;
- }
- }
- }
-
- }
- onLoad(){
- director.addPersistRootNode(this.node);
- var self = this;
- GameMng.Instance=this;
- self.unschedule(self.tick)
- self.schedule(self.tick,2.5)
- game.on(Game.EVENT_HIDE, function () {
- console.log("游戏进入后台");
- }, this);
- game.on(Game.EVENT_SHOW, function(){
- console.log("游戏进入前台");
- native_manager.check_jump_info()
- ClientEvent.dispatchEvent(Constant.EVENT_TYPE.MSG_HEART_BEAT)
- //ADSDK.ShareCallBack();
- },this);
- if(!GameMng.isFirstRunApp){
- GameMng.isFirstRunApp = true;
- native_manager.check_jump_info()
- }
- ClientEvent.on(Constant.EVENT_TYPE.MSG_EXTRUSION_LINE,this.extrusion_line,this)
- ClientEvent.on(Constant.EVENT_TYPE.MSG_HEART_BEAT,this.startTick,this)
- }
- extrusion_line(obj:any){
- let name = obj.type===0?"你的账号正在被登陆,是否重新登陆?":"请重新登陆"
- let isSHow = obj.type===0? true:false
- gameSocket.Instance.stopConnected = true;
- gameSocket.Instance.close()
- UIDialog.Show(()=>{
- GameMng.Instance.quit_view = quit_chess_show_view.login
- ScenceMng.Instance.load('GameLaunch');
- },()=>{
- },name,null,isSHow)
- console.log("被挤掉线",obj.type)
- }
- startTick(){
- this.unschedule(this.tick)
- if(GameMng._userData!=null){
- check_status = 'wait';
- gameSocket.Instance.is_online_status = false;
- this.heartbeat()
- this.loadingLayer = UILoading.deley_show(2.5)
- this.scheduleOnce(()=>{
- this.heartbeat()
- if(!gameSocket.Instance.is_online_status){
- }else{
- console.log("what the fuck?")
- UIManager.removeLoadingLayer()
- this.loadingLayer = null;
- }
- },1)
- }
- this.schedule(this.tick,2.5)
- }
-
- heartbeat(){
- if(check_status==='wait'){
- gameSocket.Instance.heartbeat();
- check_status = 'send'
- }else{
- if(check_status ==='send'){
- check_status = 'wait'
- if(this.check_heartbeat_succeed()){
- console.log("心跳成功")
- gameSocket.Instance.is_online_status = true;
- }else{
- gameSocket.Instance.is_online_status = false;
- console.log("心跳失败")
- // gameSocket.Instance.close()
- }
- }
- // this.scheduleOnce(()=>{
-
-
- // },2.5)
- }
- }
- check_heartbeat_succeed():boolean{
- return gameSocket.Instance.check_heartbeat_succeed;
- }
- tick(){
- console.log("schedule reConnect",gameSocket.Instance.is_connected)
- if(!gameSocket.Instance.is_connected||!gameSocket.Instance.is_online_status){
- if(this.loadingLayer ===null){
- this.loadingLayer = UIManager.AddPrefab(GameMng.Instance.uiloading)
- }else{
- if(gameSocket.Instance.stopConnected){
- this.loadingLayer.active = false;
- }
- }
- }else{
- if(this.loadingLayer&&gameSocket.Instance.is_online_status){
- UIManager.removeLoadingLayer()
- this.loadingLayer = null;
- }
- }
- if(gameSocket.Instance.is_connected){
- this.heartbeat()
- }else{
-
- msgManager.reConnect()
- }
- }
- }
|