gameManager.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. import { _decorator, Component, Node, RigidBody, Vec3, Prefab, game, Game, BoxCollider, instantiate, find, Animation, director, sys, debug } from 'cc';
  2. import { AudioManager } from '../framework/audioManager';
  3. import { clientEvent } from '../framework/clientEvent';
  4. import { EffectManager } from '../framework/effectManager';
  5. import { playerData } from '../framework/playerData';
  6. import { poolManager } from '../framework/poolManager';
  7. import { resourceUtil } from '../framework/resourceUtil';
  8. import { StorageManager } from '../framework/storageManager';
  9. import { uiManager } from '../framework/uiManager';
  10. import { gameConstants } from './gameConstants';
  11. import { NumFont } from './numFont';
  12. import { Goods } from './goods';
  13. import * as i18n from '../../../extensions/i18n/assets/LanguageData'
  14. import { BondsdkIos } from './sdk/bondsdkIos';
  15. import { Bondsdk } from './sdk/bondsdk';
  16. import { GolabMemory } from './pack/GolabMemory';
  17. import { HttpHelp } from './HttpHelp';
  18. import { ResponseBase } from './pack/ResponseBase';
  19. import { CoinsBatchAwardVo, CoinsBatchAwardVoH } from './pack/CoinsBatchAwardVo';
  20. import { Md5 } from '../framework/Md5';
  21. import { GetAwardVo } from './pack/GetAwardVo';
  22. import { util } from '../framework/util';
  23. import { GamePanel } from '../ui/game/gamePanel';
  24. const { ccclass, property } = _decorator;
  25. /*
  26. 注意事项:
  27. 物理系统的具体选择可参考文档
  28. https://docs.cocos.com/creator/3.3/manual/zh/physics/physics-item.html
  29. ios:
  30. 1.阴影不支持1024*1024
  31. 2.物理使用physx,性能表现最好
  32. 网页:
  33. 1.阴影可修改为自己需要的具体参数
  34. 2.物理使用bullet(ammo),性能表现最好
  35. */
  36. //test
  37. const TEST_DROP_TIME = .3; //测试 金币自动下落时间
  38. const TEST_MAX_GOLD = 200; //测试 最大金币数
  39. //test
  40. @ccclass('gameManager')
  41. export class gameManager extends Component {
  42. @property(Node)
  43. ndPush: Node = null!; //推动层节点
  44. @property(Node)
  45. ndCoinParent: Node = null!; //金币父节点
  46. @property(Prefab)
  47. preCoin: Prefab = null!; //金币预制体
  48. @property(Node)
  49. ndTouchPlane: Node = null!; //点击平面节点
  50. @property(Node)
  51. preDrawWall: Node = null!; //绘制碰撞预制体
  52. @property(NumFont)
  53. scriptGoldNumFont: NumFont = null!; //金币的numfont脚本
  54. private _linearVelocity = new Vec3(0, 0, gameConstants.PUSH_LINEAR_VELOCITY_Z); //推动层线性速度
  55. private _checkGoodsIndex = 0; //金币分帧判断
  56. private _lastPresentIndex: number = -1; //上一个礼物id
  57. private _waitPresentTime: number = 0; //等待生成礼物时间
  58. private _waitPresentCheck: boolean = false; //是否一定时间后生成礼物
  59. private _delayCreatePresent: boolean = false; //延迟生成礼物
  60. private _createId: number = 0; //生成id
  61. public static scriptsBondsdk: any = null; //sdk脚本
  62. //test
  63. private _alwaysDropGold: boolean = false; //测试 是否一直自动掉落金币切不消耗金币池
  64. private _dropTime: number = 0; //测试 自动金币下落时间
  65. //test
  66. golabMemory: GolabMemory = new GolabMemory();
  67. static Instance: gameManager;
  68. onLoad() {
  69. gameManager.Instance = this;
  70. this._checkPlatform();
  71. this.onloadInit();
  72. //@ts-ignore
  73. if (window.cocosAnalytics) {
  74. //@ts-ignore
  75. window.cocosAnalytics.init({
  76. appID: "630610516", // 游戏ID
  77. version: '1.0.0', // 游戏/应用版本号
  78. storeID: sys.platform.toString(), // 分发渠道
  79. engine: "cocos", // 游戏引擎
  80. });
  81. }
  82. //音频初始化
  83. AudioManager.instance.init();
  84. //记录离线时间
  85. game.on(Game.EVENT_HIDE, () => {
  86. if (!playerData.instance.settings) {
  87. playerData.instance.settings = {};
  88. }
  89. this._saveStandsGoodsData();
  90. playerData.instance.settings.hideTime = Date.now();
  91. playerData.instance.saveAll();
  92. StorageManager.instance.save();
  93. })
  94. //摄像机移动结束后相关操作
  95. find('Main Camera')!.getComponent(Animation)!.once(Animation.EventType.FINISHED, () => {
  96. uiManager.instance.showDialog(gameConstants.PANEL_PATH_LIST.GAME);
  97. // if (this._delayCreatePresent) {
  98. // this._createPresent();
  99. // }
  100. //摄像机以外的两个灯条特效销毁
  101. const effParent = find('effParent');
  102. effParent?.getChildByName('board3')?.destroy();
  103. effParent?.getChildByName('board4')?.destroy();
  104. })
  105. this._initLanguage();
  106. }
  107. onloadInit() {
  108. const token = this.getBrowserValue("m");
  109. console.log("浏览器完成url:", window.location.href);
  110. console.log("浏览器参数:", window.location.search);
  111. console.log("获取指定浏览器参数:", token);
  112. if (token && token.length > 20) { //正式环境
  113. console.log("正式环境");
  114. this.golabMemory.isReplse = false;
  115. this.golabMemory.Token = token;
  116. } else {
  117. console.log("测试环境");
  118. this.golabMemory.isReplse = false;
  119. this.golabMemory.Token = "dttesteyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIzNjY2NDIzOCIsImlwIjoiMTgzLjI0OS44OS43MSIsIm9nIjoiMSIsImlhdCI6MTcyNjgxMDY2NX0.HRSb7o2CSlP2p1GJnKlSzF2nXdTiUuP6AfNA_ii1UXJG3OQOJInsMns1xxn1mv8mcc5fZo5iC51KXxTLjLbRdw";
  120. }
  121. this.GetBatchInfo();
  122. }
  123. /**
  124. * 获取场次信息
  125. */
  126. private GetBatchInfo() {
  127. let url = "coins/manage/getBatchInfo";
  128. HttpHelp.httpGet(url, this.GetBatchInfoBack, this.golabMemory.Token, this);
  129. gameManager.Instance.golabMemory.AwardInfos = new Map<string, CoinsBatchAwardVo>();
  130. }
  131. GetBatchInfoBack(data: any) {
  132. console.log("获得场次信息返回对象:", data)
  133. var obj: ResponseBase = JSON.parse(data);
  134. if (obj.code != 1) {
  135. if (obj.message) {
  136. uiManager.instance.showTips(obj.message);
  137. }
  138. console.error("请求成功,返回数据错误", data);
  139. return;
  140. }
  141. this.golabMemory.Chagnci = obj.data;
  142. console.log("得到的场次信息为:", this.golabMemory.Chagnci);
  143. if (!playerData.instance.userId) {
  144. console.log("没有玩家userid");
  145. }
  146. playerData.instance.generateRandomAccount(this.golabMemory.Chagnci?.uuid);
  147. console.log("玩家游戏id为:", playerData.instance.userId);
  148. playerData.instance.loadFromCache();
  149. if (!playerData.instance.playerInfo || !playerData.instance.playerInfo.createDate) {
  150. playerData.instance.createPlayerInfo({ gold: this.golabMemory.Chagnci?.gameCurrcy });
  151. }
  152. if (this.golabMemory.Chagnci?.gameCurrcy) {
  153. playerData.instance.setPlayMoney(this.golabMemory.Chagnci?.gameCurrcy);
  154. if (this.scriptGoldNumFont) {
  155. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  156. }
  157. }else{
  158. if (this.scriptGoldNumFont) {
  159. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  160. }
  161. }
  162. this._initGame();
  163. }
  164. /**
  165. * 从链接中获取对象
  166. * @param value
  167. * @returns
  168. */
  169. private getBrowserValue(value: string) {
  170. var query = window.location.search.substring(1);
  171. var vars = query.split("&");
  172. for (var i = 0; i < vars.length; i++) {
  173. var pair = vars[i].split("=");
  174. if (pair[0] == value) {
  175. return pair[1];
  176. }
  177. }
  178. return null;
  179. }
  180. /**
  181. * 判断平台
  182. */
  183. private _checkPlatform() {
  184. if (sys.platform === sys.Platform.IOS) {
  185. gameManager.scriptsBondsdk = BondsdkIos;
  186. } else {
  187. gameManager.scriptsBondsdk = Bondsdk;
  188. }
  189. gameManager.scriptsBondsdk.init();
  190. }
  191. /**
  192. * 初始化语言
  193. */
  194. private _initLanguage() {
  195. const nowLanguage = gameConstants.I18_LANGUAGE.CHINESE;
  196. i18n.init(nowLanguage);
  197. }
  198. /**
  199. * 事件初始化
  200. */
  201. private _initEvent() {
  202. clientEvent.on(gameConstants.EVENT_LIST.TOUCH_CREATE_GOLD, this._createCoin, this);
  203. clientEvent.on(gameConstants.EVENT_LIST.TOUCH_HIDE_TOUCHPLANE, this._hideTouchPlane, this);
  204. clientEvent.on(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE, this._updateGoldNum, this);
  205. }
  206. /**
  207. * 点击区域节点 显示删除
  208. */
  209. private _hideTouchPlane(isShow: boolean) {
  210. // if (isShow) {
  211. // this.ndTouchPlane.active = true;
  212. // } else {
  213. // this.ndTouchPlane.destroy();
  214. // }
  215. }
  216. /**
  217. * 初始化游戏
  218. */
  219. private _initGame() {
  220. // this._updateGoldNum();
  221. this.ndTouchPlane.active = false;
  222. //初始化推动层位置
  223. this.ndPush.setPosition(new Vec3(gameConstants.PUSH_INIT_POS_X, gameConstants.PUSH_INIT_POS_Y, gameConstants.PUSH_MIN_POS_Z));
  224. this._initSceneWall();
  225. this._initEvent();
  226. setTimeout(() => {
  227. //初始化台面物品
  228. if (playerData.instance.playerInfo.standsData &&
  229. playerData.instance.playerInfo.standsData.goldList) {
  230. //上次存储的数据
  231. const standsData = playerData.instance.playerInfo.standsData as
  232. {
  233. goldList: Array<{ pos: Array<number>, eul: Array<number> }>,
  234. // presentData: { index: number, pos: Array<number>, eul: Array<number> },
  235. presentData:Array<CoinsBatchAwardVoH>,
  236. }
  237. //初始化金币
  238. for (let i = 0; i < standsData.goldList.length; i++) {
  239. const nowData = standsData.goldList[i];
  240. this._createCoin(false,
  241. new Vec3(nowData.pos[0], nowData.pos[1], nowData.pos[2]),
  242. new Vec3(nowData.eul[0], nowData.eul[1], nowData.eul[2]));
  243. }
  244. //初始化礼物
  245. for(let i=0;i<standsData.presentData.length;i++){
  246. this._createPresentH(standsData.presentData[i]);
  247. }
  248. // if (standsData.presentData.index !== -1) {
  249. // this._createPresent(standsData.presentData);
  250. // } else {
  251. // this._delayCreatePresent = true;
  252. // }
  253. } else {
  254. this._createInitCoin();
  255. this._delayCreatePresent = true;
  256. }
  257. }, 0);
  258. setTimeout(() => {
  259. EffectManager.instance.playIdle();
  260. }, 2);
  261. }
  262. /**
  263. * 初始化平台上平铺的金币
  264. */
  265. private _createInitCoin() {
  266. this.ndCoinParent.destroyAllChildren();
  267. let x = 0;
  268. let z = gameConstants.GOLD_ON_STAND_POS_MIN_Z;
  269. let pos = new Vec3();
  270. let eul = new Vec3(0, 0, 0);
  271. let isOnColliderEvent = false;
  272. while (z < gameConstants.GOLD_ON_STAND_POS_MAX_Z) {
  273. if (x === 0) {
  274. pos.set(x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  275. this._createCoin(isOnColliderEvent, pos, eul);
  276. } else {
  277. pos.set(x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  278. this._createCoin(isOnColliderEvent, pos, eul);
  279. pos.set(-x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  280. this._createCoin(isOnColliderEvent, pos, eul);
  281. }
  282. x += gameConstants.GOLD_SIZE;
  283. if (x > gameConstants.GOLD_ON_STAND_POS_MAX_X) {
  284. x = 0;
  285. z += gameConstants.GOLD_SIZE;
  286. }
  287. }
  288. }
  289. /**
  290. * 创建一个金币
  291. * @param pos 坐标
  292. */
  293. private _createCoin(isOnColliderEvent: boolean, pos: Vec3, eul?: Vec3) {
  294. const itemCoin = poolManager.instance.getNode(this.preCoin, this.ndCoinParent) as Node;
  295. let scriptsGoods: any = itemCoin.getComponent('Goods');
  296. if (!scriptsGoods) {
  297. scriptsGoods = itemCoin.addComponent('Goods');
  298. }
  299. scriptsGoods.initGoods(isOnColliderEvent, this._getNewGoodsIndex(), "", pos, eul);
  300. }
  301. /**
  302. * 初始化等待掉落礼物参数
  303. */
  304. private _waitCreatePresent() {
  305. this._waitPresentCheck = true;
  306. this._waitPresentTime = 0;
  307. }
  308. /**
  309. * 创建一个礼物
  310. * @param lastPresentData
  311. */
  312. _createPresentH(data?: CoinsBatchAwardVoH) {
  313. let pos = new Vec3();
  314. let eul: any = null!;
  315. if (!data) {
  316. console.error("创建礼物数据为空,cao", data);
  317. return;
  318. }
  319. if (data && data.pos && data.eul) {
  320. //重置上一次的离线礼物
  321. pos.set(data.pos[0], data.pos[1], data.pos[2]);
  322. eul = new Vec3(data.eul[0], data.eul[1], data.eul[2]);
  323. }
  324. const idx = data.basicType ? data.basicType : 0;
  325. resourceUtil.loadModelRes(gameConstants.PRESENT_NAME_LIST[idx]).then((pre: any) => {
  326. const ndPresent = poolManager.instance.getNode(pre, this.ndCoinParent);
  327. let scriptsGoods = ndPresent.getComponent('Goods');
  328. if (!scriptsGoods) {
  329. scriptsGoods = ndPresent.addComponent('Goods');
  330. }
  331. scriptsGoods.initGoods(false, this._getNewGoodsIndex(), data.uuid, pos, eul);
  332. })
  333. }
  334. /**
  335. * 创建一个礼物
  336. * @param lastPresentData
  337. */
  338. _createPresent(data?: CoinsBatchAwardVo) {
  339. let pos = new Vec3();
  340. let eul: any = null!;
  341. pos.set(
  342. gameConstants.PRESENT_DROP_X + Math.random() * gameConstants.PRESENT_DROP_RANGE_X,
  343. gameConstants.PRESENT_DROP_Y,
  344. gameConstants.PRESENT_DROP_Z + Math.random() * gameConstants.PRESENT_DROP_RANGE_Z);
  345. // }
  346. if (!data) {
  347. console.error("创建礼物数据为空,cao", data);
  348. return;
  349. }
  350. const idx = data.basicType ? data.basicType : 0;
  351. resourceUtil.loadModelRes(gameConstants.PRESENT_NAME_LIST[idx]).then((pre: any) => {
  352. const ndPresent = poolManager.instance.getNode(pre, this.ndCoinParent);
  353. let scriptsGoods = ndPresent.getComponent('Goods');
  354. if (!scriptsGoods) {
  355. scriptsGoods = ndPresent.addComponent('Goods');
  356. }
  357. scriptsGoods.initGoods(false, this._getNewGoodsIndex(), data.uuid, pos, eul);
  358. })
  359. }
  360. /**
  361. * 获取当前的物品运行判断帧
  362. * @returns
  363. */
  364. private _getNewGoodsIndex() {
  365. this._checkGoodsIndex++;
  366. if (this._checkGoodsIndex > gameConstants.GOLD_CHECK_MAX_FRAME) {
  367. this._checkGoodsIndex = 2;
  368. }
  369. return this._checkGoodsIndex;
  370. }
  371. /**
  372. * 保存台面上的物品数据
  373. */
  374. private _saveStandsGoodsData() {
  375. let data = {
  376. goldList: [] as Array<{ pos: Array<number>, eul: Array<number> }>,
  377. presentData: [] as Array<CoinsBatchAwardVoH>,
  378. }
  379. for (let i = 0; i < this.ndCoinParent.children.length; i++) {
  380. const nowItem = this.ndCoinParent.children[i];
  381. if (nowItem.position.y < gameConstants.GOODS_CHECK_OTHER_STATE) continue; //当前金币在掉落过程中 不记录
  382. if (nowItem.name === gameConstants.GOLD_NAME) {
  383. data.goldList.push({
  384. pos: [nowItem.position.x, nowItem.position.y, nowItem.position.z],
  385. eul: [nowItem.eulerAngles.x, nowItem.eulerAngles.y, nowItem.eulerAngles.z],
  386. })
  387. } else {
  388. const goodjs:any=nowItem.getComponent('Goods');
  389. if(goodjs){
  390. const temp=new CoinsBatchAwardVoH();
  391. temp.uuid = goodjs.uuidstr;
  392. temp.basicType=nowItem.name=="key01"?0:1;
  393. temp.pos= [nowItem.position.x, nowItem.position.y, nowItem.position.z];
  394. temp.eul= [nowItem.eulerAngles.x, nowItem.eulerAngles.y, nowItem.eulerAngles.z];
  395. data.presentData.push(temp);
  396. }
  397. }
  398. }
  399. playerData.instance.playerInfo.standsData = data;
  400. }
  401. /**
  402. * 判断当前物品是否状态
  403. * @param frame
  404. * @param itemNode
  405. * @returns
  406. */
  407. private _checkAGoodsState(frame: number, itemNode: Node) {
  408. const goodsJs: any = itemNode.getComponent('Goods')!;
  409. if (frame % goodsJs.goodsIndex === 0) {
  410. //物品是否从台子上掉落
  411. if (itemNode.position.y >= gameConstants.GOODS_CHECK_OTHER_STATE) return;
  412. if (itemNode.position.y < gameConstants.GOODS_DESTROY_POS_Y) {
  413. //当前物品超出显示范围,移除
  414. goodsJs.putPoolGoods();
  415. } else if (itemNode.position.y < gameConstants.GOODS_GET_MIN_POS_Y) {
  416. //当前物品为可积分区域,并且未被积分过
  417. if (goodsJs.addGold !== 0) {
  418. if (itemNode.position.x > -gameConstants.GOODS_GET_MIN_POS_X &&
  419. itemNode.position.x < gameConstants.GOODS_GET_MIN_POS_X &&
  420. itemNode.position.z > gameConstants.GOODS_GET_MIN_POS_Z &&
  421. itemNode.position.z < gameConstants.GOODS_GET_MAX_POS_Z) {
  422. goodsJs.getGoods();
  423. } else {
  424. //不在可获得区域内的
  425. goodsJs.addGold = 0;
  426. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.INVALIDGOLD);
  427. }
  428. }
  429. //礼物掉下平台
  430. if (goodsJs.isPresent) {
  431. goodsJs.isPresent = false;
  432. this._waitCreatePresent();
  433. }
  434. }
  435. }
  436. }
  437. update() {
  438. const frame = director.getTotalFrames();
  439. //判断所有金币是否掉落
  440. for (let i = 0; i < this.ndCoinParent.children.length; i++) {
  441. this._checkAGoodsState(frame, this.ndCoinParent.children[i]);
  442. }
  443. //推动台线性速度
  444. const pushPos = this.ndPush.getPosition();
  445. if (pushPos.z <= gameConstants.PUSH_MIN_POS_Z) {
  446. this._linearVelocity.set(0, 0, gameConstants.PUSH_LINEAR_VELOCITY_Z);
  447. } else if (pushPos.z >= gameConstants.PUSH_MAX_POS_Z) {
  448. this._linearVelocity.set(0, 0, -gameConstants.PUSH_LINEAR_VELOCITY_Z);
  449. }
  450. this.ndPush.getComponent(RigidBody)?.setLinearVelocity(this._linearVelocity);
  451. }
  452. lateUpdate(dt: number) {
  453. //test 自动掉落金币
  454. if (this._alwaysDropGold) {
  455. if (this.ndCoinParent.children.length < TEST_MAX_GOLD) {
  456. this._dropTime += dt;
  457. if (this._dropTime > TEST_DROP_TIME) {
  458. this._dropTime = 0;
  459. this._createCoin(true, new Vec3(Math.random() * 3.5 * (Math.random() > 0.5 ? -1 : 1), gameConstants.GOLD_DROP_POS_Y, -8.5))
  460. }
  461. }
  462. }
  463. //test
  464. //一定时间后生成下一个礼物
  465. if (this._waitPresentCheck) {
  466. this._waitPresentTime += dt;
  467. if (this._waitPresentTime > gameConstants.PRESENT_WAIT_TIME) {
  468. this._waitPresentCheck = false;
  469. // this._createPresent();
  470. }
  471. }
  472. }
  473. /**
  474. * 获取当前wroker端id
  475. * @returns
  476. */
  477. private _getIndex() {
  478. this._createId++;
  479. return this._createId;
  480. }
  481. /**
  482. * 初始化场景中的墙相关刚体
  483. * @returns
  484. */
  485. private _initSceneWall() {
  486. this._createAllWallRigidBody();
  487. }
  488. /**
  489. * 创建所有墙面刚体
  490. */
  491. private _createAllWallRigidBody() {
  492. let v3_init = new Vec3();
  493. //墙面刚体和碰撞盒
  494. const ndWallBox = new Node('wallBox');
  495. this.node.addChild(ndWallBox);
  496. const wallRigidBodyData = gameConstants.INITSCENE_WALL_RIGIDBODY;
  497. for (let i = 0; i < gameConstants.INITSCENE_WALL_COLLIDER.length; i++) {
  498. const wallColliderData = gameConstants.INITSCENE_WALL_COLLIDER[i];
  499. const name = i === 0 ? gameConstants.WALL_NAME_DOWN_FLOOR : gameConstants.WALL_NAME;
  500. const ndWallItem = new Node(name);
  501. ndWallBox.addChild(ndWallItem);
  502. v3_init.set(wallColliderData.pos.x, wallColliderData.pos.y, wallColliderData.pos.z);
  503. v3_init.add3f(wallColliderData.center.x, wallColliderData.center.y, wallColliderData.center.z);
  504. ndWallItem.setPosition(v3_init);
  505. v3_init.set(wallColliderData.eul.x, wallColliderData.eul.y, wallColliderData.eul.z);
  506. ndWallItem.setRotationFromEuler(v3_init);
  507. let rigidBody = ndWallItem.addComponent(RigidBody);
  508. rigidBody.type = wallRigidBodyData.type;
  509. rigidBody.setGroup(wallRigidBodyData.group);
  510. rigidBody.setMask(wallRigidBodyData.mask);
  511. let collider = ndWallItem.addComponent(BoxCollider);
  512. v3_init.set(wallColliderData.size.x, wallColliderData.size.y, wallColliderData.size.z);
  513. collider.size = v3_init;
  514. // this._drawWallCollider(wallColliderData);
  515. }
  516. }
  517. /**
  518. * 绘制出当前配置的碰撞体位置
  519. * @param wallColliderData
  520. */
  521. private _drawWallCollider(wallColliderData: any) {
  522. let v3_init = new Vec3();
  523. const node = instantiate(this.preDrawWall);
  524. node.parent = this.node;
  525. v3_init.set(wallColliderData.pos.x, wallColliderData.pos.y, wallColliderData.pos.z);
  526. v3_init.add3f(wallColliderData.center.x, wallColliderData.center.y, wallColliderData.center.z);
  527. node.setPosition(v3_init)
  528. v3_init.set(wallColliderData.eul.x, wallColliderData.eul.y, wallColliderData.eul.z);
  529. node.setRotationFromEuler(v3_init)
  530. v3_init.set(wallColliderData.size.x, wallColliderData.size.y, wallColliderData.size.z);
  531. node.setScale(v3_init)
  532. }
  533. /**
  534. * 更新金币数量显示
  535. */
  536. private _updateGoldNum() {
  537. if (!this.scriptGoldNumFont) return;
  538. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  539. }
  540. DiaoLuoCallback(data: Goods) {
  541. console.log("掉落回调", data);
  542. let url = "coins/manage/getAward";
  543. let timenum = this.getTimestampInSeconds();
  544. let m: string = `uuid=${data.uuidstr}&time=${timenum}fxkj9999`;
  545. const md5: Md5 = new Md5();
  546. md5.appendStr(m);
  547. let str = md5.end()
  548. let parm = {
  549. time: timenum.toString(),
  550. uuid: data.uuidstr,
  551. sign: str
  552. };
  553. console.log("获得奖品发送数据", parm);
  554. HttpHelp.httpPost(url, JSON.stringify(parm), this.GetGoodsBack, this.golabMemory.Token, this);
  555. }
  556. GetGoodsBack(data: any) {
  557. console.log('获得物品回调:', data);
  558. var obj: ResponseBase = JSON.parse(data);
  559. if (obj.code != 1) {
  560. console.error("获取服务器信息出错", data);
  561. return;
  562. }
  563. const info: GetAwardVo = obj.data;
  564. if (info.gameCurrcy) {
  565. playerData.instance.setPlayMoney(info.gameCurrcy);
  566. clientEvent.dispatchEvent(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE);
  567. }
  568. if (info.id) {
  569. GamePanel.Instance.SetGoodsData(info);
  570. }
  571. }
  572. /**
  573. * 获得10位时间戳
  574. * @returns
  575. */
  576. getTimestampInSeconds(): number {
  577. return Math.floor(Date.now() / 1000);
  578. }
  579. }