gameManager.ts 23 KB

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