Home.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import Stage from "./stage/Stage";
  2. import Pack from "./pack/Pack";
  3. import ViewObject from "../../main/ViewObject";
  4. import { HttpStateType, ReveData } from "../../util/CHttp";
  5. import { AudioMgr, GameViewType } from "../../main/ViewManage";
  6. import ShopView from "./shop/ShopView";
  7. import Equip from "./equip/Equip";
  8. import FFCalAttr from "../data/FFCalAttr";
  9. import { PetAttr } from "../data/udata/Player";
  10. import RedPoint from "../data/RedPoint";
  11. import FirstPay from "./activity/FirstPay";
  12. import TopMenu from "./TopMenu";
  13. import Wish from "./activity/Wish";
  14. import Revenge from "./activity/Revenge";
  15. import CUtilTime from "../../util/CUtilTime";
  16. /**
  17. * 主页home
  18. */
  19. const { ccclass, property } = cc._decorator;
  20. @ccclass
  21. export default class Home extends ViewObject {
  22. @property(cc.Label)
  23. mZdl: cc.Label = null;
  24. @property(cc.Label)
  25. mPower: cc.Label = null;
  26. @property(cc.Label)
  27. mMoney: cc.Label = null;
  28. @property(cc.Label)
  29. mGold: cc.Label = null;
  30. @property(cc.Sprite)
  31. mIcon: cc.Sprite = null;
  32. @property(cc.Sprite)
  33. mFrame: cc.Sprite = null;
  34. @property(cc.Node)
  35. activityNode: cc.Node = null;
  36. @property(cc.Node)
  37. mEmailNode: cc.Node = null;
  38. @property(sp.Skeleton)
  39. mRole1: sp.Skeleton = null;
  40. @property(sp.Skeleton)
  41. mRole2: sp.Skeleton = null;
  42. @property(sp.Skeleton)
  43. mRole3: sp.Skeleton = null;
  44. @property(cc.Node)
  45. mEquipNode: cc.Node = null;
  46. @property(cc.Node)
  47. revengeBtn: cc.Node = null;
  48. public revengeTime: number = 0;
  49. public topMenu: TopMenu = null;
  50. public revengeView: Revenge = null;
  51. /**
  52. * 用户点击了冒险按钮回调
  53. */
  54. private mxCallback: () => void;
  55. onLoad() {
  56. //心跳60秒执行一次
  57. this.hit()
  58. this.schedule(this.hit, 15)
  59. this.flushActivity();
  60. this.topMenu = this.main.topNode.getComponent(TopMenu);
  61. this.topMenu.main = this.main;
  62. this.topMenu.home = this;
  63. this.main.topNode.active = true;
  64. this.main.playMusicByPath(AudioMgr.homeMusic);
  65. this.node.getChildByName("activity").getChildByName("1002").active = !this.main.player.isNew;
  66. this.getPay()
  67. }
  68. public hit() {
  69. this.main.gameHttp.sendJson('role/v1/resumePower', {}, (state, reve: ReveData) => { });
  70. }
  71. public onEnable() {
  72. this.flush()
  73. this.flushZdl()
  74. this.flushRole()
  75. this.flushEquipRedPoint();
  76. if (cc.sys.localStorage.getItem("showRevenge" + this.main.player.role.id) == 1) {
  77. this.activiteRevenge();
  78. } else {
  79. this.getRevengeData();
  80. }
  81. }
  82. private getPay() {
  83. let msg = {
  84. }
  85. this.main.gameHttp.sendJson('pay/v1/checkPay1', msg, (state, reve: ReveData) => {
  86. if (state == HttpStateType.SUCCESS) {
  87. if (reve.retCode == 0) {
  88. this.main.showReward(reve)
  89. }
  90. } else {
  91. }
  92. });
  93. }
  94. public flushZdl() {
  95. this.main.player.flushZdl(this.main)
  96. let role = this.main.player.role;
  97. this.mZdl.string = '' + role.zdl;
  98. }
  99. public flush() {
  100. let role = this.main.player.role;
  101. let roleIcon = this.main.sManage.getRoleIconById(role.icon)
  102. if (roleIcon) {
  103. cc.resources.load('icon/role_head/' + roleIcon.icon, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  104. if (err) {
  105. cc.error(err);
  106. } else {
  107. this.mIcon.spriteFrame = spriteFrame;
  108. }
  109. });
  110. }
  111. let roleFrame = this.main.sManage.getRoleIconById(role.frame)
  112. if (roleFrame) {
  113. cc.resources.load('icon/role_head/txk/' + roleFrame.icon, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
  114. if (err) {
  115. cc.error(err);
  116. } else {
  117. this.mFrame.spriteFrame = spriteFrame;
  118. }
  119. });
  120. }
  121. }
  122. public flushRole() {
  123. let pet1 = this.main.player.getPet(1)
  124. this.updateRole(pet1, this.mRole1);
  125. let pet2 = this.main.player.getPet(2)
  126. this.updateRole(pet2, this.mRole2);
  127. let pet3 = this.main.player.getPet(3)
  128. this.updateRole(pet3, this.mRole3);
  129. }
  130. public flushActivity() {
  131. this.main.gameHttp.sendJson(`firstPay/v1/data`, {}, (state, reve: ReveData) => {
  132. if (state == HttpStateType.SUCCESS) {
  133. if (reve.retCode == 0) {
  134. if (reve.data.firstPay.count == 3) {
  135. this.activityNode.getChildByName("1001").active = false;
  136. }
  137. } else {
  138. this.main.showTips(reve.message);
  139. }
  140. } else {
  141. this.main.showTips('网络异常');
  142. }
  143. });
  144. }
  145. private updateRole(pet: PetAttr, spine: sp.Skeleton) {
  146. if (pet == null) {
  147. spine.node.active = false
  148. } else {
  149. spine.node.active = true
  150. let mWeapon1: sp.spine.Bone = spine.findBone('control');
  151. if (mWeapon1) {
  152. // mWeapon1.data.rotation = 45;
  153. mWeapon1.rotation = -45;
  154. }
  155. // let attrData = FFCalAttr.getAttr(this.main, pet);
  156. // if (attrData.skin) {
  157. // spine.setSkin(attrData.skin)
  158. // }
  159. // if (attrData.weapon) {
  160. // Equip.chaneWeapon(spine, attrData.weapon)
  161. // }
  162. }
  163. }
  164. /**
  165. * 监听网络
  166. * @param reveData
  167. */
  168. public httpEvent(reveData: ReveData) {
  169. let data = reveData.data;
  170. if (data._role != undefined) {
  171. // this.flush();
  172. this.topMenu.refresh();
  173. }
  174. this.flushZdl();
  175. if (data._equip != undefined) {
  176. this.flushEquipRedPoint(true);
  177. }
  178. //['email']
  179. if (data._msgPush != undefined) {
  180. if (data._msgPush.indexOf('email') >= 0) {//有新邮件
  181. RedPoint.addRed(this.main, this.topMenu.mEmailNode, true)
  182. }
  183. }
  184. }
  185. /**
  186. * 刷新角色红点
  187. */
  188. public flushEquipRedPoint(force?: boolean) {
  189. if (RedPoint.petsRedPoint(this.main)) {
  190. RedPoint.addRed(this.main, this.mEquipNode, force)
  191. } else {
  192. RedPoint.removeRed(this.mEquipNode)
  193. }
  194. }
  195. /**
  196. * 角色查看
  197. */
  198. public onclickRoleIcon() {
  199. this.main.playerEffectByPath(AudioMgr.click);
  200. this.main.viewManage.loadFunc(GameViewType.tap_role, (viewObject: ViewObject) => {
  201. viewObject.show();
  202. });
  203. }
  204. public setMxCallback(callback: () => void) {
  205. this.mxCallback = callback
  206. }
  207. /**
  208. * 地图
  209. */
  210. public onclickMap() {
  211. this.main.playerEffectByPath(AudioMgr.click);
  212. let isNewGuide = false
  213. if (this.mxCallback) {
  214. this.mxCallback()
  215. isNewGuide = true
  216. }
  217. this.main.viewManage.loadFunc(GameViewType.stageView, (viewObject: ViewObject) => {
  218. let stage = viewObject as Stage;
  219. stage.load((result: number) => {
  220. if (result == 0) {
  221. if (isNewGuide) {
  222. stage.inGuide = 1
  223. }
  224. viewObject.show(this);
  225. } else {
  226. this.main.showTips('载入地图失败')
  227. }
  228. });
  229. });
  230. }
  231. /**
  232. * 背包
  233. */
  234. public onclickPack() {
  235. // if (Pack.instance) {
  236. // Pack.instance.flush();
  237. // Pack.instance.show();
  238. // } else {
  239. // }
  240. this.main.playerEffectByPath(AudioMgr.click);
  241. this.main.startLoad();
  242. this.main.viewManage.loadFunc(GameViewType.pack, (viewObject: ViewObject) => {
  243. viewObject.show(this);
  244. });
  245. }
  246. /**
  247. * 神卡
  248. */
  249. public onclickJitan() {
  250. this.main.playerEffectByPath(AudioMgr.click);
  251. this.main.viewManage.loadFunc(GameViewType.god_card, (viewObject: ViewObject) => {
  252. viewObject.show(this);
  253. });
  254. }
  255. /**
  256. * 装备
  257. */
  258. public onclickEquip() {
  259. this.main.playerEffectByPath(AudioMgr.click);
  260. this.main.startLoad();
  261. RedPoint.removeRed(this.mEquipNode)
  262. this.main.viewManage.loadFunc(GameViewType.equip, (viewObject: ViewObject) => {
  263. viewObject.show(this);
  264. });
  265. }
  266. /**
  267. * 魔盒
  268. */
  269. public onclickMohe() {
  270. this.main.playerEffectByPath(AudioMgr.click);
  271. this.main.viewManage.loadFunc(GameViewType.mohe, (viewObject: ViewObject) => {
  272. viewObject.show(this);
  273. });
  274. }
  275. /**
  276. * 商城
  277. */
  278. public openShop(eventTouch: cc.Event.EventTouch, data: string) {
  279. this.main.playerEffectByPath(AudioMgr.click);
  280. this.main.startLoad();
  281. this.main.viewManage.loadFunc(GameViewType.tap_shop, (viewObject: ViewObject) => {
  282. let shopView = viewObject as ShopView;
  283. shopView.init(Number(data));
  284. shopView.show();
  285. });
  286. }
  287. /**
  288. * 首冲
  289. */
  290. public openFirstPay(eventTouch: cc.Event.EventTouch, data: string) {
  291. this.main.playerEffectByPath(AudioMgr.click);
  292. this.main.startLoad();
  293. this.main.viewManage.loadFunc(GameViewType.firstPay, (viewObject: ViewObject) => {
  294. let firstPayView = viewObject as FirstPay;
  295. firstPayView.getFirstPayData("data");
  296. });
  297. }
  298. /**
  299. * 每日祝福
  300. */
  301. public openWish(eventTouch: cc.Event.EventTouch, data: string) {
  302. this.main.playerEffectByPath(AudioMgr.click);
  303. this.main.startLoad();
  304. this.main.viewManage.loadFunc(GameViewType.wish, (viewObject: ViewObject) => {
  305. let wishView = viewObject as Wish;
  306. wishView.getWishData();
  307. });
  308. }
  309. /**
  310. * 复仇礼包
  311. */
  312. public openRevenge() {
  313. this.main.playerEffectByPath(AudioMgr.click);
  314. this.main.startLoad();
  315. this.main.viewManage.loadFunc(GameViewType.revenge, (viewObject: ViewObject) => {
  316. let revengeView = viewObject as Revenge;
  317. this.revengeView = revengeView;
  318. revengeView.getRevengeData();
  319. revengeView.refreshTime(this.revengeTime);
  320. revengeView.setBuyClickFunc(() => {
  321. this.showRevengeBtn(false);
  322. })
  323. });
  324. }
  325. // 激活复仇礼包
  326. public activiteRevenge() {
  327. let msg = {
  328. id: 1001,
  329. };
  330. this.main.gameHttp.sendJson(`revenge/v1/open`, msg, (state, reve: ReveData) => {
  331. this.main.stopLoad();
  332. if (state == HttpStateType.SUCCESS) {
  333. if (reve.retCode == 0) {
  334. console.log("====复仇礼包激活成功===");
  335. this.getRevengeData();
  336. } else {
  337. this.main.showTips(reve.message);
  338. }
  339. } else {
  340. this.main.showTips('网络异常');
  341. }
  342. })
  343. }
  344. public getRevengeData() {
  345. let msg = {};
  346. let nowTime1 = CUtilTime.getNowTime();
  347. this.main.gameHttp.sendJson(`revenge/v1/data`, msg, (state, reve: ReveData) => {
  348. let nowTime2 = CUtilTime.getNowTime() - nowTime1;
  349. this.main.stopLoad();
  350. if (state == HttpStateType.SUCCESS) {
  351. if (reve.retCode == 0) {
  352. console.log("=home=reve=revengeData===", reve)
  353. let data = reve.data.data[reve.data.list[0].id];
  354. if (data) {
  355. if (data.value == 2) { // 购买过
  356. this.showRevengeBtn(false);
  357. return
  358. }
  359. let time = data.time;
  360. if (time > 0) {
  361. this.showRevengeBtn(true);
  362. this.revengeTime = time - nowTime2;
  363. this.revengeBtn.getChildByName("time").getComponent(cc.Label).string = `剩余 ${CUtilTime.getTimeString2(time - nowTime2)}`;
  364. } else {
  365. this.showRevengeBtn(false);
  366. }
  367. }
  368. if (cc.sys.localStorage.getItem("showRevenge" + this.main.player.role.id) == 1) {
  369. cc.sys.localStorage.setItem("showRevenge" + this.main.player.role.id, 2);
  370. this.main.viewManage.loadFunc(GameViewType.revenge, (viewObject: ViewObject) => {
  371. let revengeView = viewObject as Revenge;
  372. this.revengeView = revengeView;
  373. revengeView.revengeData = reve.data.list[0];
  374. revengeView.show();
  375. revengeView.initItem();
  376. revengeView.refreshTime(this.revengeTime);
  377. revengeView.setBuyClickFunc(() => {
  378. this.showRevengeBtn(false);
  379. })
  380. });
  381. }
  382. } else {
  383. this.main.showTips(reve.message);
  384. }
  385. } else {
  386. this.main.showTips('网络异常');
  387. }
  388. });
  389. }
  390. showRevengeBtn(show = false) {
  391. this.revengeBtn.active = show;
  392. }
  393. tempTime: number = 0;
  394. update(dt) {
  395. if (this.revengeTime <= 0) {
  396. this.showRevengeBtn(false);
  397. if (this.revengeView) {
  398. this.revengeView.exitDistroy();
  399. }
  400. return
  401. }
  402. this.tempTime += dt;
  403. if (this.tempTime >= 1) {
  404. this.revengeTime -= 1;
  405. this.revengeBtn.getChildByName("time").getComponent(cc.Label).string = `剩余 ${CUtilTime.getTimeString2(Math.floor(this.revengeTime))}`;
  406. this.tempTime = 0;
  407. if (this.revengeView) {
  408. this.revengeView.refreshTime(this.revengeTime);
  409. }
  410. }
  411. }
  412. }