SManage.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. import i18n from "../../../i18n/i18n";
  2. import { ReveData } from "../../../util/CHttp";
  3. import { FFAttr } from "../FFCalAttr";
  4. /**
  5. * 主角信息
  6. */
  7. export interface __RoleData {
  8. id: number,
  9. name: string,
  10. icon: string,
  11. act: string,
  12. post: number,
  13. group: number,
  14. atk: number,
  15. def: number,
  16. hp: number,
  17. sp: number,
  18. skill: number,
  19. }
  20. //头像/框/称号
  21. export interface __RoleIcon {
  22. id: number,
  23. type: number,
  24. name: string,
  25. icon: string,
  26. about: string,
  27. atk: number,
  28. def: number,
  29. hp: number,
  30. sp: number,
  31. }
  32. /**
  33. * 道具
  34. */
  35. export interface __GoodData {
  36. id: number,
  37. name: string,
  38. type: number,
  39. pz: number,
  40. icon: string,
  41. atk: number,
  42. def: number,
  43. hp: number,
  44. sp: number,
  45. water: number,
  46. fire: number,
  47. light: number,
  48. earth: number,
  49. dark: number,
  50. wind: number,
  51. thunder: number,
  52. howGet: number,
  53. about: string,
  54. sell: number,
  55. buy: number,
  56. }
  57. /**
  58. * 装备
  59. */
  60. export interface __EquipData {
  61. id: number,
  62. name: string,
  63. about: string,
  64. level: number,//当前最高强化等级
  65. icon: string,
  66. bulletEffect: string,
  67. pz: number,
  68. occ: number,
  69. atk: number,
  70. def: number,
  71. hp: number,
  72. sp: number,
  73. sd: number,
  74. type: number,
  75. suit: number
  76. skill: number
  77. qh_exp: number//消耗后获得的强化经验
  78. qh_max: number//强化突破次数
  79. }
  80. /**
  81. * 装备强化
  82. */
  83. export interface __EquipQHData {
  84. id: number
  85. type: number
  86. occ: number
  87. level: number
  88. exp: number
  89. atk: number
  90. def: number
  91. hp: number
  92. sp: number
  93. money: number
  94. }
  95. /**
  96. * 装备套装
  97. */
  98. export interface __EquipSuitData {
  99. id: number
  100. name: string
  101. about: string
  102. suitId: number
  103. effect: string
  104. value1_1: number
  105. value1_2: number
  106. value1_3: number
  107. value2_1: number
  108. value2_2: number
  109. value2_3: number
  110. }
  111. /**
  112. * 技能
  113. */
  114. export interface __SkillData {
  115. id: number,
  116. name: string,
  117. about: string,
  118. type: number
  119. icon: string,
  120. effect: string,
  121. time: number,
  122. value1: number,
  123. value2: number,
  124. value3: number
  125. value4: number
  126. }
  127. /**
  128. * 装备附加属性
  129. */
  130. export interface __EquipAttrData {
  131. id: number,
  132. name: string,
  133. }
  134. /**
  135. * 怪物
  136. */
  137. export interface __MonsterData {
  138. id: number,
  139. name: string,
  140. group: number,
  141. type: number,
  142. career: number,
  143. icon: string,
  144. act: string,
  145. level: number,
  146. atk: number,
  147. def: number,
  148. hp: number,
  149. sp: number,
  150. skill: number,
  151. }
  152. /**
  153. * 场景
  154. */
  155. export interface __SceneData {
  156. id: number,
  157. name: string,
  158. about: string,
  159. startIndex: number
  160. list: Array<__StageData>
  161. }
  162. /**
  163. * 关卡
  164. */
  165. export interface __StageData {
  166. id: number,
  167. zid: number,
  168. name: string,
  169. about: string,
  170. mapId: string,
  171. goodId1: number,
  172. goodCount1: number,
  173. goodId2: number,
  174. goodCount2: number,
  175. goodId3: number,
  176. goodCount3: number,
  177. taskText: string,
  178. music: string
  179. }
  180. /**
  181. * 任务
  182. */
  183. export interface __TaskData {
  184. id: number,
  185. name: string,
  186. reward: string,
  187. }
  188. /**
  189. * 神卡
  190. */
  191. export interface __GodCard {
  192. id: number
  193. name: string
  194. about: string
  195. type: number
  196. pz: number
  197. max_star: number
  198. goodId: number
  199. goodCount: number
  200. water: number
  201. fire: number
  202. wind: number
  203. thunder: number
  204. earth: number
  205. job: number
  206. atk: number
  207. def: number
  208. hp: number
  209. sp: number
  210. feature: string
  211. value1: number
  212. value2: number
  213. value3: number
  214. feature_about: string
  215. feature_max: string
  216. list: Array<__GodCardLevel>
  217. godReborn: __GodReborn
  218. }
  219. /**
  220. * 神卡升级
  221. */
  222. export interface __GodCardLevel {
  223. id: number
  224. godCardId: number
  225. star: number
  226. type: number
  227. attrType: number
  228. goodId1: number
  229. goodCount1: number
  230. goodId2: number
  231. goodCount2: number
  232. goodId3: number
  233. goodCount3: number
  234. water: number
  235. fire: number
  236. wind: number
  237. thunder: number
  238. earth: number
  239. job: number
  240. atk: number
  241. def: number
  242. hp: number
  243. sp: number
  244. }
  245. /**
  246. * 满星后重生
  247. */
  248. export interface __GodReborn {
  249. id: number
  250. godCardId: number
  251. goodId1: number
  252. goodCount1: number
  253. goodId2: number
  254. goodCount2: number
  255. water: number
  256. fire: number
  257. wind: number
  258. thunder: number
  259. earth: number
  260. job: number
  261. atk: number
  262. def: number
  263. hp: number
  264. sp: number
  265. }
  266. /**
  267. * 魔盒
  268. */
  269. export interface __MagicBox {
  270. id: number
  271. type: number
  272. icon: string
  273. name: string
  274. about: string
  275. consumeType: number
  276. goodId: number
  277. goodCount: number
  278. rewardId: number
  279. list: Array<__MagicBoxReward>
  280. maxPR: number
  281. }
  282. /**
  283. * 魔盒奖励
  284. */
  285. export interface __MagicBoxReward {
  286. id: number
  287. magicBoxId: number
  288. type: number
  289. value1: number
  290. value2: number
  291. value3: number
  292. PR: number
  293. }
  294. export interface __PayData {
  295. id: number,//商品编号
  296. type: number,//类型
  297. iosId: string,//苹果商品id
  298. googleId: string,//谷歌商店唯一id
  299. name: string,//商品名字
  300. rmb: string,//RMB
  301. usd: string,//美刀
  302. gold: number//兑换的钻石
  303. firstGive: number//首次充值额外奖励钻石
  304. }
  305. export interface __BuyCoinData {
  306. id: number,//商品编号
  307. name: string,//商品名字
  308. maxCount: number,//限购次数
  309. gold: number //花费钻石
  310. money: number // 获得
  311. gave: number // 赠送
  312. }
  313. export interface __BuyPowerData {
  314. id: number,//商品编号
  315. maxCount: number,//限购次数
  316. gold: number //花费钻石
  317. power: number // 获得
  318. }
  319. export interface __BuyPandoraData {
  320. id: number,//商品编号
  321. name: string, //名字
  322. adCount: number,//广告次数
  323. flushTime: number //刷新时间
  324. goodId: number // 花费紫水晶ID
  325. }
  326. export interface __FirstPayData {
  327. id: number,//商品编号
  328. name: string, //名字
  329. reward: string, // 奖励
  330. }
  331. export interface __FirstPayRewardData {
  332. icon: string,
  333. count: number,
  334. frame: number,
  335. }
  336. export interface __WishData {
  337. id: number, //商品编号
  338. name: string, //名字
  339. payId: string, //充值id
  340. maxCount: number //每日限购次数
  341. reward: string, //奖励
  342. }
  343. /**
  344. * 从服务器获取的奖励
  345. * type:0,
  346. icon:'icon/good/3001',
  347. count:data._role._money,
  348. id:0,
  349. pz:0,
  350. star:0
  351. */
  352. export interface RewardData {
  353. type: number,//0:money,1:gole,2:good
  354. icon: string,//图标
  355. count: number,//数量
  356. id: number,//道具对应的id
  357. pz: 0,
  358. star: 0
  359. PR: 0
  360. name: ''
  361. }
  362. /**
  363. * 系统数据管理
  364. */
  365. export default class SManage {
  366. /**
  367. * 角色数据
  368. */
  369. private roleDataMap: Map<number, __RoleData> = new Map();
  370. /**
  371. * 头像/框/称号
  372. */
  373. private roleIcons: Array<__RoleIcon> = [];
  374. /**
  375. * 道具
  376. */
  377. private goodMap: Map<number, __GoodData> = new Map();
  378. /**
  379. * 装备
  380. */
  381. private equipMap: Map<number, __EquipData> = new Map();
  382. /**
  383. * 装备强化
  384. * key : int 装备类型
  385. * vaule: list 强化数据列表
  386. */
  387. private equipQHMap: Map<string, Array<__EquipQHData>> = new Map();
  388. /**
  389. * 附属性
  390. */
  391. private attrMap: Map<number, __EquipAttrData> = new Map();
  392. /**
  393. * 技能
  394. */
  395. private skillMap: Map<number, __SkillData> = new Map();
  396. /**
  397. * 怪物
  398. */
  399. private monsterMap: Map<number, __MonsterData> = new Map();
  400. /**
  401. * 关卡数据
  402. */
  403. private sceneLists: Array<__SceneData> = null;
  404. private stageLists: Array<__StageData> = null;
  405. /**
  406. * 神卡
  407. */
  408. public godCards: Array<__GodCard> = null;
  409. /**
  410. * 魔盒
  411. */
  412. public magicBoxs: Array<__MagicBox> = null;
  413. /**
  414. * 充值数据
  415. */
  416. public payDatas: Array<__PayData> = null;
  417. /**
  418. * 任务列表
  419. */
  420. private taskLists: Array<__TaskData> = null;
  421. constructor(data) {
  422. this.initRoleData(data.roleData);
  423. this.roleIcons = data.roleIcon;
  424. this.initGood(data.good);
  425. this.initEquip(data.equip);
  426. this.initEquipQH(data.equipQH);
  427. this.initEquipAttr(data.eAttr);
  428. this.initSkillData(data.skill);
  429. this.initMonster(data.monster);
  430. this.sceneLists = data.scene;
  431. this.stageLists = data.stage;
  432. this.initScene();
  433. this.initGodCard(data.godCard)
  434. this.initGodCardLevel(data.godCardLevel)
  435. this.initGodReborn(data.godReborn)
  436. this.magicBoxs = data.magicBox
  437. this.initMaigcBoxReward(data.magicBoxReward)
  438. this.payDatas = data.payData
  439. this.taskLists = data.task;
  440. }
  441. private initMaigcBoxReward(list: Array<__MagicBoxReward>) {
  442. for (let i = 0; i < this.magicBoxs.length; i++) {
  443. const element = this.magicBoxs[i];
  444. for (let j = 0; j < list.length; j++) {
  445. const tmp = list[j];
  446. if (tmp.magicBoxId == element.rewardId) {
  447. if (element.list == undefined) {
  448. element.list = []
  449. }
  450. element.list.push(tmp)
  451. }
  452. }
  453. }
  454. }
  455. private initGodReborn(list: Array<__GodReborn>) {
  456. list.forEach(element => {
  457. let godCard = this.getGodCardById(element.godCardId)
  458. godCard.godReborn = element
  459. });
  460. }
  461. private initGodCardLevel(list: Array<__GodCardLevel>) {
  462. for (let i = 0; i < list.length; i++) {
  463. const element = list[i];
  464. let godCard = this.getGodCardById(element.godCardId)
  465. if (!godCard.list) {
  466. godCard.list = []
  467. }
  468. godCard.list.push(element)
  469. }
  470. }
  471. private initGodCard(list: Array<__GodCard>) {
  472. this.godCards = list
  473. }
  474. private initSkillData(list: Array<__SkillData>) {
  475. list.forEach(element => {
  476. this.skillMap.set(element.id, element);
  477. });
  478. }
  479. public getRoleIconById(id) {
  480. for (let i = 0; i < this.roleIcons.length; i++) {
  481. const element = this.roleIcons[i];
  482. if (element.id == id) {
  483. return element;
  484. }
  485. }
  486. }
  487. private initRoleData(roleDataLists: Array<__RoleData>) {
  488. roleDataLists.forEach(element => {
  489. this.roleDataMap.set(element.id, element);
  490. });
  491. }
  492. private initGood(lists: Array<__GoodData>) {
  493. lists.forEach(element => {
  494. this.goodMap.set(element.id, element);
  495. });
  496. }
  497. private initEquipAttr(lists: Array<__EquipAttrData>) {
  498. lists.forEach(element => {
  499. this.attrMap.set(element.id, element);
  500. });
  501. }
  502. private initEquip(lists: Array<__EquipData>) {
  503. lists.forEach(element => {
  504. this.equipMap.set(element.id, element);
  505. });
  506. }
  507. private initEquipQH(lists: Array<__EquipQHData>) {
  508. lists.forEach(element => {
  509. let key = element.occ + '@' + element.type
  510. let list = this.equipQHMap.get(key)
  511. if (list) {
  512. list.push(element)
  513. } else {
  514. list = []
  515. list.push(element)
  516. this.equipQHMap.set(key, list)
  517. }
  518. });
  519. }
  520. private initMonster(monsters: Array<__MonsterData>) {
  521. monsters.forEach(element => {
  522. this.monsterMap.set(element.id, element);
  523. });
  524. }
  525. private initScene() {
  526. for (let i = 0; i < this.stageLists.length; i++) {
  527. const element = this.stageLists[i];
  528. let scene = this.getSceneById(element.zid);
  529. if (scene.list == null) {
  530. scene.list = [];
  531. scene.startIndex = i;
  532. }
  533. scene.list.push(element);
  534. }
  535. }
  536. public getGodCardById(id): __GodCard {
  537. for (let i = 0; i < this.godCards.length; i++) {
  538. const element = this.godCards[i];
  539. if (element.id == id) {
  540. return element;
  541. }
  542. }
  543. }
  544. public getSceneById(id) {
  545. for (let i = 0; i < this.sceneLists.length; i++) {
  546. const element = this.sceneLists[i];
  547. if (element.id == id) {
  548. return element;
  549. }
  550. }
  551. }
  552. public getSceneByStage(stage: __StageData) {
  553. if (stage == null) {
  554. return this.sceneLists[this.sceneLists.length - 1];
  555. }
  556. return this.getSceneById(stage.zid);
  557. }
  558. public getScene() {
  559. return this.sceneLists;
  560. }
  561. public getStage() {
  562. return this.stageLists;
  563. }
  564. /**
  565. * 获取关卡
  566. * @param index
  567. */
  568. public getStageByIndex(index: number) {
  569. if (index >= this.stageLists.length) {
  570. return null;
  571. }
  572. return this.stageLists[index];
  573. }
  574. /**
  575. * 获取怪物数据
  576. * @param id
  577. */
  578. public getMonsterData(id: number): FFAttr {
  579. let monsterData = this.monsterMap.get(id);
  580. let fd1 = {
  581. id: id,
  582. type: monsterData.type,
  583. post: monsterData.career,
  584. path: "prefab/monster/" + monsterData.act,
  585. atk: monsterData.atk,
  586. def: monsterData.def,
  587. hp: monsterData.hp,
  588. sp: monsterData.sp,
  589. water: 0,
  590. fire: 0,
  591. wind: 0,
  592. thunder: 0,
  593. earth: 0,
  594. sd: 500,
  595. weaponSkill: 0,
  596. suitId: 0,
  597. suitCount: 0,
  598. attrs: [],
  599. zdl: 1,
  600. skin: null,
  601. weapon: null,
  602. bullet: null
  603. };
  604. return fd1;
  605. }
  606. public getGoodById(id: string) {
  607. return this.goodMap.get(parseInt(id));
  608. }
  609. public getGoodById1(id: number) {
  610. return this.goodMap.get(id);
  611. }
  612. public getEquipById(id): __EquipData {
  613. return this.equipMap.get(id);
  614. }
  615. public getEquipAttrById(id) {
  616. return this.attrMap.get(id);
  617. }
  618. public getSkillById(id: number) {
  619. return this.skillMap.get(id);
  620. }
  621. public getRoleById(id: number) {
  622. return this.roleDataMap.get(id);
  623. }
  624. public getRoleIcon() {
  625. return this.roleIcons
  626. }
  627. /**
  628. * 获取某个类型的强化数据
  629. * @param type
  630. */
  631. public getEquipQHByType(equipData: __EquipData): Array<__EquipQHData> {
  632. return this.equipQHMap.get(equipData.occ + '@' + equipData.type)
  633. }
  634. /**
  635. * 从接收的数据中分离出奖励数据
  636. * @param reve
  637. */
  638. public getRewards(reveData: ReveData): Array<RewardData> {
  639. let list = [];
  640. let data = reveData.data;
  641. if (data._role != undefined) {
  642. if (data._role._money != undefined) {
  643. if (data._role._money > 0) {
  644. let rewardData = {
  645. type: 0,
  646. icon: 'icon/good/3001',
  647. count: data._role._money,
  648. id: 0,
  649. pz: 4,
  650. star: 0,
  651. name: i18n.t('金币')
  652. }
  653. list.push(rewardData);
  654. }
  655. }
  656. if (data._role._gold != undefined) {
  657. if (data._role._gold > 0) {
  658. let rewardData = {
  659. type: 1,
  660. icon: 'icon/good/3002',
  661. count: data._role._gold,
  662. id: 0,
  663. pz: 5,
  664. star: 0,
  665. name: i18n.t('钻石')
  666. }
  667. list.push(rewardData);
  668. }
  669. }
  670. if (data._role._power != undefined) {
  671. if (data._role._power > 0) {
  672. let rewardData = {
  673. type: 1,
  674. icon: 'icon/good/3003',
  675. count: data._role._power,
  676. id: 0,
  677. pz: 5,
  678. star: 0,
  679. name: i18n.t('体力')
  680. }
  681. list.push(rewardData);
  682. }
  683. }
  684. }
  685. //道具
  686. if (data._pack != undefined) {
  687. for (let i = 0; i < data._pack.length; i++) {
  688. const element = data._pack[i];
  689. if (element.count > 0) {
  690. let good = this.getGoodById1(element.id);
  691. let rewardData = {
  692. type: 2,
  693. icon: 'icon/good/' + good.icon,
  694. count: element.count,
  695. id: element.id,
  696. pz: good.pz,
  697. star: 0,
  698. name: i18n.t(good.name)
  699. }
  700. list.push(rewardData);
  701. }
  702. }
  703. }
  704. //装备
  705. if (data._equip != undefined) {
  706. for (let i = 0; i < data._equip.length; i++) {
  707. const element = data._equip[i];
  708. let equip = this.getEquipById(element.id);
  709. let rewardData = {
  710. type: 3,
  711. icon: 'icon/equip/' + equip.icon,
  712. count: 0,
  713. id: element.id,
  714. pz: equip.pz,
  715. PI: element.PI,
  716. star: element.star,
  717. _data: equip,
  718. name: i18n.t(equip.name)
  719. }
  720. list.push(rewardData);
  721. }
  722. }
  723. if (data._godCard != undefined) {
  724. for (let i = 0; i < data._godCard.length; i++) {
  725. const element = data._godCard[i];
  726. let rewardData = {
  727. type: 4,
  728. data: element,
  729. name: i18n.t('神卡')
  730. }
  731. list.push(rewardData);
  732. }
  733. }
  734. return list;
  735. }
  736. /**
  737. * 从接收的数据中分离出奖励数据
  738. * @param reve
  739. */
  740. public getRewardViews(rewards: Array<__MagicBoxReward>): Array<RewardData> {
  741. let list = [];
  742. for (let i = 0; i < rewards.length; i++) {
  743. const element = rewards[i];
  744. if (element.type == 1) {
  745. let rewardData = {
  746. type: 0,
  747. icon: 'icon/good/3001',
  748. count: element.value1,
  749. id: 0,
  750. pz: 3,
  751. star: 0,
  752. PR: element.PR
  753. }
  754. list.push(rewardData);
  755. } else if (element.type == 2) {
  756. let rewardData = {
  757. type: 1,
  758. icon: 'icon/good/3002',
  759. count: element.value1,
  760. id: 0,
  761. pz: 5,
  762. star: 0,
  763. PR: element.PR
  764. }
  765. list.push(rewardData);
  766. } else if (element.type == 3) {
  767. let good = this.getGoodById1(element.value1);
  768. let rewardData = {
  769. type: 2,
  770. icon: 'icon/good/' + good.icon,
  771. count: element.value2,
  772. id: element.id,
  773. pz: good.pz,
  774. star: 0,
  775. PR: element.PR
  776. }
  777. list.push(rewardData);
  778. } else if (element.type == 4) {
  779. let equip = this.getEquipById(element.value1);
  780. let rewardData = {
  781. type: 3,
  782. icon: 'icon/equip/' + equip.icon,
  783. count: 0,
  784. id: element.id,
  785. pz: equip.pz,
  786. PI: element.value3,
  787. star: 0,
  788. _data: equip,
  789. PR: element.PR
  790. }
  791. list.push(rewardData);
  792. }
  793. }
  794. return list;
  795. }
  796. }