gameManager.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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.eyJqdGkiOiI0MjMzMjciLCJpcCI6IjE4My4yNDkuMTEzLjIxNyIsIm9nIjoiMSIsImlhdCI6MTcyNDEzOTE3M30.oZCzn0JH4gfeIXP8nAWe3I91Fn9USK0GKnR0iFLPz6csv4prJMobd9EsHPWz8q9O6pFE9cPQKL73INxm0FLXJQ";
  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. console.error("请求成功,返回数据错误", data);
  136. return;
  137. }
  138. this.golabMemory.Chagnci = obj.data;
  139. console.log("得到的场次信息为:", this.golabMemory.Chagnci);
  140. if (!playerData.instance.userId) {
  141. console.log("没有玩家userid");
  142. }
  143. playerData.instance.generateRandomAccount(this.golabMemory.Chagnci?.uuid);
  144. console.log("玩家游戏id为:", playerData.instance.userId);
  145. playerData.instance.loadFromCache();
  146. if (!playerData.instance.playerInfo || !playerData.instance.playerInfo.createDate) {
  147. playerData.instance.createPlayerInfo({ gold: this.golabMemory.Chagnci?.gameCurrcy });
  148. }
  149. if (this.golabMemory.Chagnci?.gameCurrcy) {
  150. playerData.instance.setPlayMoney(this.golabMemory.Chagnci?.gameCurrcy);
  151. if (this.scriptGoldNumFont) {
  152. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  153. }
  154. }else{
  155. if (this.scriptGoldNumFont) {
  156. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  157. }
  158. }
  159. this._initGame();
  160. }
  161. /**
  162. * 从链接中获取对象
  163. * @param value
  164. * @returns
  165. */
  166. private getBrowserValue(value: string) {
  167. var query = window.location.search.substring(1);
  168. var vars = query.split("&");
  169. for (var i = 0; i < vars.length; i++) {
  170. var pair = vars[i].split("=");
  171. if (pair[0] == value) {
  172. return pair[1];
  173. }
  174. }
  175. return null;
  176. }
  177. /**
  178. * 判断平台
  179. */
  180. private _checkPlatform() {
  181. if (sys.platform === sys.Platform.IOS) {
  182. gameManager.scriptsBondsdk = BondsdkIos;
  183. } else {
  184. gameManager.scriptsBondsdk = Bondsdk;
  185. }
  186. gameManager.scriptsBondsdk.init();
  187. }
  188. /**
  189. * 初始化语言
  190. */
  191. private _initLanguage() {
  192. const nowLanguage = gameConstants.I18_LANGUAGE.CHINESE;
  193. i18n.init(nowLanguage);
  194. }
  195. /**
  196. * 事件初始化
  197. */
  198. private _initEvent() {
  199. clientEvent.on(gameConstants.EVENT_LIST.TOUCH_CREATE_GOLD, this._createCoin, this);
  200. clientEvent.on(gameConstants.EVENT_LIST.TOUCH_HIDE_TOUCHPLANE, this._hideTouchPlane, this);
  201. clientEvent.on(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE, this._updateGoldNum, this);
  202. }
  203. /**
  204. * 点击区域节点 显示删除
  205. */
  206. private _hideTouchPlane(isShow: boolean) {
  207. // if (isShow) {
  208. // this.ndTouchPlane.active = true;
  209. // } else {
  210. // this.ndTouchPlane.destroy();
  211. // }
  212. }
  213. /**
  214. * 初始化游戏
  215. */
  216. private _initGame() {
  217. // this._updateGoldNum();
  218. this.ndTouchPlane.active = false;
  219. //初始化推动层位置
  220. this.ndPush.setPosition(new Vec3(gameConstants.PUSH_INIT_POS_X, gameConstants.PUSH_INIT_POS_Y, gameConstants.PUSH_MIN_POS_Z));
  221. this._initSceneWall();
  222. this._initEvent();
  223. setTimeout(() => {
  224. //初始化台面物品
  225. if (playerData.instance.playerInfo.standsData &&
  226. playerData.instance.playerInfo.standsData.goldList) {
  227. //上次存储的数据
  228. const standsData = playerData.instance.playerInfo.standsData as
  229. {
  230. goldList: Array<{ pos: Array<number>, eul: Array<number> }>,
  231. // presentData: { index: number, pos: Array<number>, eul: Array<number> },
  232. presentData:Array<CoinsBatchAwardVoH>,
  233. }
  234. //初始化金币
  235. for (let i = 0; i < standsData.goldList.length; i++) {
  236. const nowData = standsData.goldList[i];
  237. this._createCoin(false,
  238. new Vec3(nowData.pos[0], nowData.pos[1], nowData.pos[2]),
  239. new Vec3(nowData.eul[0], nowData.eul[1], nowData.eul[2]));
  240. }
  241. //初始化礼物
  242. for(let i=0;i<standsData.presentData.length;i++){
  243. this._createPresentH(standsData.presentData[i]);
  244. }
  245. // if (standsData.presentData.index !== -1) {
  246. // this._createPresent(standsData.presentData);
  247. // } else {
  248. // this._delayCreatePresent = true;
  249. // }
  250. } else {
  251. this._createInitCoin();
  252. this._delayCreatePresent = true;
  253. }
  254. }, 0);
  255. setTimeout(() => {
  256. EffectManager.instance.playIdle();
  257. }, 2);
  258. }
  259. /**
  260. * 初始化平台上平铺的金币
  261. */
  262. private _createInitCoin() {
  263. this.ndCoinParent.destroyAllChildren();
  264. let x = 0;
  265. let z = gameConstants.GOLD_ON_STAND_POS_MIN_Z;
  266. let pos = new Vec3();
  267. let eul = new Vec3(0, 0, 0);
  268. let isOnColliderEvent = false;
  269. while (z < gameConstants.GOLD_ON_STAND_POS_MAX_Z) {
  270. if (x === 0) {
  271. pos.set(x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  272. this._createCoin(isOnColliderEvent, pos, eul);
  273. } else {
  274. pos.set(x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  275. this._createCoin(isOnColliderEvent, pos, eul);
  276. pos.set(-x, gameConstants.GOLD_ON_STAND_POS_Y, z)
  277. this._createCoin(isOnColliderEvent, pos, eul);
  278. }
  279. x += gameConstants.GOLD_SIZE;
  280. if (x > gameConstants.GOLD_ON_STAND_POS_MAX_X) {
  281. x = 0;
  282. z += gameConstants.GOLD_SIZE;
  283. }
  284. }
  285. }
  286. /**
  287. * 创建一个金币
  288. * @param pos 坐标
  289. */
  290. private _createCoin(isOnColliderEvent: boolean, pos: Vec3, eul?: Vec3) {
  291. const itemCoin = poolManager.instance.getNode(this.preCoin, this.ndCoinParent) as Node;
  292. let scriptsGoods: any = itemCoin.getComponent('Goods');
  293. if (!scriptsGoods) {
  294. scriptsGoods = itemCoin.addComponent('Goods');
  295. }
  296. scriptsGoods.initGoods(isOnColliderEvent, this._getNewGoodsIndex(), "", pos, eul);
  297. }
  298. /**
  299. * 初始化等待掉落礼物参数
  300. */
  301. private _waitCreatePresent() {
  302. this._waitPresentCheck = true;
  303. this._waitPresentTime = 0;
  304. }
  305. /**
  306. * 创建一个礼物
  307. * @param lastPresentData
  308. */
  309. _createPresentH(data?: CoinsBatchAwardVoH) {
  310. let pos = new Vec3();
  311. let eul: any = null!;
  312. if (!data) {
  313. console.error("创建礼物数据为空,cao", data);
  314. return;
  315. }
  316. if (data && data.pos && data.eul) {
  317. //重置上一次的离线礼物
  318. pos.set(data.pos[0], data.pos[1], data.pos[2]);
  319. eul = new Vec3(data.eul[0], data.eul[1], data.eul[2]);
  320. }
  321. const idx = data.basicType ? data.basicType : 0;
  322. resourceUtil.loadModelRes(gameConstants.PRESENT_NAME_LIST[idx]).then((pre: any) => {
  323. const ndPresent = poolManager.instance.getNode(pre, this.ndCoinParent);
  324. let scriptsGoods = ndPresent.getComponent('Goods');
  325. if (!scriptsGoods) {
  326. scriptsGoods = ndPresent.addComponent('Goods');
  327. }
  328. scriptsGoods.initGoods(false, this._getNewGoodsIndex(), data.uuid, pos, eul);
  329. })
  330. }
  331. /**
  332. * 创建一个礼物
  333. * @param lastPresentData
  334. */
  335. _createPresent(data?: CoinsBatchAwardVo) {
  336. let pos = new Vec3();
  337. let eul: any = null!;
  338. pos.set(
  339. gameConstants.PRESENT_DROP_X + Math.random() * gameConstants.PRESENT_DROP_RANGE_X,
  340. gameConstants.PRESENT_DROP_Y,
  341. gameConstants.PRESENT_DROP_Z + Math.random() * gameConstants.PRESENT_DROP_RANGE_Z);
  342. // }
  343. if (!data) {
  344. console.error("创建礼物数据为空,cao", data);
  345. return;
  346. }
  347. const idx = data.basicType ? data.basicType : 0;
  348. resourceUtil.loadModelRes(gameConstants.PRESENT_NAME_LIST[idx]).then((pre: any) => {
  349. const ndPresent = poolManager.instance.getNode(pre, this.ndCoinParent);
  350. let scriptsGoods = ndPresent.getComponent('Goods');
  351. if (!scriptsGoods) {
  352. scriptsGoods = ndPresent.addComponent('Goods');
  353. }
  354. scriptsGoods.initGoods(false, this._getNewGoodsIndex(), data.uuid, pos, eul);
  355. })
  356. }
  357. /**
  358. * 获取当前的物品运行判断帧
  359. * @returns
  360. */
  361. private _getNewGoodsIndex() {
  362. this._checkGoodsIndex++;
  363. if (this._checkGoodsIndex > gameConstants.GOLD_CHECK_MAX_FRAME) {
  364. this._checkGoodsIndex = 2;
  365. }
  366. return this._checkGoodsIndex;
  367. }
  368. /**
  369. * 保存台面上的物品数据
  370. */
  371. private _saveStandsGoodsData() {
  372. let data = {
  373. goldList: [] as Array<{ pos: Array<number>, eul: Array<number> }>,
  374. presentData: [] as Array<CoinsBatchAwardVoH>,
  375. }
  376. for (let i = 0; i < this.ndCoinParent.children.length; i++) {
  377. const nowItem = this.ndCoinParent.children[i];
  378. if (nowItem.position.y < gameConstants.GOODS_CHECK_OTHER_STATE) continue; //当前金币在掉落过程中 不记录
  379. if (nowItem.name === gameConstants.GOLD_NAME) {
  380. data.goldList.push({
  381. pos: [nowItem.position.x, nowItem.position.y, nowItem.position.z],
  382. eul: [nowItem.eulerAngles.x, nowItem.eulerAngles.y, nowItem.eulerAngles.z],
  383. })
  384. } else {
  385. const goodjs:any=nowItem.getComponent('Goods');
  386. if(goodjs){
  387. const temp=new CoinsBatchAwardVoH();
  388. temp.uuid = goodjs.uuidstr;
  389. temp.basicType=nowItem.name=="key01"?0:1;
  390. temp.pos= [nowItem.position.x, nowItem.position.y, nowItem.position.z];
  391. temp.eul= [nowItem.eulerAngles.x, nowItem.eulerAngles.y, nowItem.eulerAngles.z];
  392. data.presentData.push(temp);
  393. }
  394. }
  395. }
  396. playerData.instance.playerInfo.standsData = data;
  397. }
  398. /**
  399. * 判断当前物品是否状态
  400. * @param frame
  401. * @param itemNode
  402. * @returns
  403. */
  404. private _checkAGoodsState(frame: number, itemNode: Node) {
  405. const goodsJs: any = itemNode.getComponent('Goods')!;
  406. if (frame % goodsJs.goodsIndex === 0) {
  407. //物品是否从台子上掉落
  408. if (itemNode.position.y >= gameConstants.GOODS_CHECK_OTHER_STATE) return;
  409. if (itemNode.position.y < gameConstants.GOODS_DESTROY_POS_Y) {
  410. //当前物品超出显示范围,移除
  411. goodsJs.putPoolGoods();
  412. } else if (itemNode.position.y < gameConstants.GOODS_GET_MIN_POS_Y) {
  413. //当前物品为可积分区域,并且未被积分过
  414. if (goodsJs.addGold !== 0) {
  415. if (itemNode.position.x > -gameConstants.GOODS_GET_MIN_POS_X &&
  416. itemNode.position.x < gameConstants.GOODS_GET_MIN_POS_X &&
  417. itemNode.position.z > gameConstants.GOODS_GET_MIN_POS_Z &&
  418. itemNode.position.z < gameConstants.GOODS_GET_MAX_POS_Z) {
  419. goodsJs.getGoods();
  420. } else {
  421. //不在可获得区域内的
  422. goodsJs.addGold = 0;
  423. AudioManager.instance.playSound(gameConstants.SOUND_NAME_LIST.INVALIDGOLD);
  424. }
  425. }
  426. //礼物掉下平台
  427. if (goodsJs.isPresent) {
  428. goodsJs.isPresent = false;
  429. this._waitCreatePresent();
  430. }
  431. }
  432. }
  433. }
  434. update() {
  435. const frame = director.getTotalFrames();
  436. //判断所有金币是否掉落
  437. for (let i = 0; i < this.ndCoinParent.children.length; i++) {
  438. this._checkAGoodsState(frame, this.ndCoinParent.children[i]);
  439. }
  440. //推动台线性速度
  441. const pushPos = this.ndPush.getPosition();
  442. if (pushPos.z <= gameConstants.PUSH_MIN_POS_Z) {
  443. this._linearVelocity.set(0, 0, gameConstants.PUSH_LINEAR_VELOCITY_Z);
  444. } else if (pushPos.z >= gameConstants.PUSH_MAX_POS_Z) {
  445. this._linearVelocity.set(0, 0, -gameConstants.PUSH_LINEAR_VELOCITY_Z);
  446. }
  447. this.ndPush.getComponent(RigidBody)?.setLinearVelocity(this._linearVelocity);
  448. }
  449. lateUpdate(dt: number) {
  450. //test 自动掉落金币
  451. if (this._alwaysDropGold) {
  452. if (this.ndCoinParent.children.length < TEST_MAX_GOLD) {
  453. this._dropTime += dt;
  454. if (this._dropTime > TEST_DROP_TIME) {
  455. this._dropTime = 0;
  456. this._createCoin(true, new Vec3(Math.random() * 3.5 * (Math.random() > 0.5 ? -1 : 1), gameConstants.GOLD_DROP_POS_Y, -8.5))
  457. }
  458. }
  459. }
  460. //test
  461. //一定时间后生成下一个礼物
  462. if (this._waitPresentCheck) {
  463. this._waitPresentTime += dt;
  464. if (this._waitPresentTime > gameConstants.PRESENT_WAIT_TIME) {
  465. this._waitPresentCheck = false;
  466. // this._createPresent();
  467. }
  468. }
  469. }
  470. /**
  471. * 获取当前wroker端id
  472. * @returns
  473. */
  474. private _getIndex() {
  475. this._createId++;
  476. return this._createId;
  477. }
  478. /**
  479. * 初始化场景中的墙相关刚体
  480. * @returns
  481. */
  482. private _initSceneWall() {
  483. this._createAllWallRigidBody();
  484. }
  485. /**
  486. * 创建所有墙面刚体
  487. */
  488. private _createAllWallRigidBody() {
  489. let v3_init = new Vec3();
  490. //墙面刚体和碰撞盒
  491. const ndWallBox = new Node('wallBox');
  492. this.node.addChild(ndWallBox);
  493. const wallRigidBodyData = gameConstants.INITSCENE_WALL_RIGIDBODY;
  494. for (let i = 0; i < gameConstants.INITSCENE_WALL_COLLIDER.length; i++) {
  495. const wallColliderData = gameConstants.INITSCENE_WALL_COLLIDER[i];
  496. const name = i === 0 ? gameConstants.WALL_NAME_DOWN_FLOOR : gameConstants.WALL_NAME;
  497. const ndWallItem = new Node(name);
  498. ndWallBox.addChild(ndWallItem);
  499. v3_init.set(wallColliderData.pos.x, wallColliderData.pos.y, wallColliderData.pos.z);
  500. v3_init.add3f(wallColliderData.center.x, wallColliderData.center.y, wallColliderData.center.z);
  501. ndWallItem.setPosition(v3_init);
  502. v3_init.set(wallColliderData.eul.x, wallColliderData.eul.y, wallColliderData.eul.z);
  503. ndWallItem.setRotationFromEuler(v3_init);
  504. let rigidBody = ndWallItem.addComponent(RigidBody);
  505. rigidBody.type = wallRigidBodyData.type;
  506. rigidBody.setGroup(wallRigidBodyData.group);
  507. rigidBody.setMask(wallRigidBodyData.mask);
  508. let collider = ndWallItem.addComponent(BoxCollider);
  509. v3_init.set(wallColliderData.size.x, wallColliderData.size.y, wallColliderData.size.z);
  510. collider.size = v3_init;
  511. // this._drawWallCollider(wallColliderData);
  512. }
  513. }
  514. /**
  515. * 绘制出当前配置的碰撞体位置
  516. * @param wallColliderData
  517. */
  518. private _drawWallCollider(wallColliderData: any) {
  519. let v3_init = new Vec3();
  520. const node = instantiate(this.preDrawWall);
  521. node.parent = this.node;
  522. v3_init.set(wallColliderData.pos.x, wallColliderData.pos.y, wallColliderData.pos.z);
  523. v3_init.add3f(wallColliderData.center.x, wallColliderData.center.y, wallColliderData.center.z);
  524. node.setPosition(v3_init)
  525. v3_init.set(wallColliderData.eul.x, wallColliderData.eul.y, wallColliderData.eul.z);
  526. node.setRotationFromEuler(v3_init)
  527. v3_init.set(wallColliderData.size.x, wallColliderData.size.y, wallColliderData.size.z);
  528. node.setScale(v3_init)
  529. }
  530. /**
  531. * 更新金币数量显示
  532. */
  533. private _updateGoldNum() {
  534. if (!this.scriptGoldNumFont) return;
  535. this.scriptGoldNumFont.updateShow(playerData.instance.playerInfo['gold']);
  536. }
  537. DiaoLuoCallback(data: Goods) {
  538. console.log("掉落回调", data);
  539. let url = "coins/manage/getAward";
  540. let timenum = this.getTimestampInSeconds();
  541. let m: string = `uuid='${data.uuidstr}'&time='${timenum}'fxkj9999`;
  542. const md5: Md5 = new Md5();
  543. md5.appendStr(m);
  544. let parm = {
  545. time: timenum.toString(),
  546. uuid: data.uuidstr,
  547. sign: md5.end()
  548. };
  549. console.log("获得奖品发送数据", parm);
  550. HttpHelp.httpPost(url, JSON.stringify(parm), this.GetGoodsBack, this.golabMemory.Token, this);
  551. }
  552. GetGoodsBack(data: any) {
  553. console.log('获得物品回调:', data);
  554. var obj: ResponseBase = JSON.parse(data);
  555. if (obj.code != 1) {
  556. console.error("获取服务器信息出错", data);
  557. return;
  558. }
  559. const info: GetAwardVo = obj.data;
  560. if (info.gameCurrcy) {
  561. playerData.instance.setPlayMoney(info.gameCurrcy);
  562. clientEvent.dispatchEvent(gameConstants.EVENT_LIST.GOLD_SHOW_UPDATE);
  563. }
  564. if (info.id) {
  565. GamePanel.Instance.SetGoodsData(info);
  566. }
  567. }
  568. /**
  569. * 获得10位时间戳
  570. * @returns
  571. */
  572. getTimestampInSeconds(): number {
  573. return Math.floor(Date.now() / 1000);
  574. }
  575. }