GlobalManager.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /** @format */
  2. import {ccUtils} from '../utils/ccUtils'
  3. import {Data, Mgr} from '../GameControl'
  4. import {BaseUI} from '../ui/BaseUI'
  5. import {card, equip, hero, idNum} from '../proto/typedef'
  6. import {RoleConfig} from '../config/RoleConfig'
  7. import {CardSkillConfig} from '../config/CardSkillConfig'
  8. import {CardConsumeConfig} from '../config/CardConsumeConfig'
  9. import {RoleQualityConfig} from '../config/RoleQualityConfig'
  10. import {ArmorConfig} from '../config/ArmorConfig'
  11. import {EquipmentQualityConfig} from '../config/EquipmentQualityConfig'
  12. import {TalentConfig} from '../config/TalentConfig'
  13. import {EntryConfig} from '../config/EntryConfig'
  14. import {
  15. ATTR_NAME,
  16. BUILDING,
  17. CONDITION_FUNC,
  18. ENTRY,
  19. GAME_TYPE,
  20. GOODS,
  21. GOODS_TYPE,
  22. LANGUAGE_TYPE,
  23. LOCAL,
  24. MOD,
  25. PREFAB_TYPE,
  26. PROFESSION,
  27. RECRUIT_TYPE,
  28. ROLE_TYPE,
  29. } from '../enums/Enum'
  30. import {IAdStatus, IBaseAttr, ICard, ICardDebris, ICastleSkill, IEquip, IRole} from '../interface/GlobalInterface'
  31. import {FunctionsConfig} from '../config/FunctionsConfig'
  32. import {StageInfoConfig} from '../config/StageInfoConfig'
  33. import {UI} from '../enums/UI'
  34. import {ConstValue} from '../data/ConstValue'
  35. import {GoodsConfig} from '../config/GoodsConfig'
  36. import {boxGetAward} from '../proto/game'
  37. import {msgCmd} from '../proto/msg_cmd'
  38. import {ItemUICfg} from '../interface/UIInterface'
  39. import UserGuide from '../userguide/UserGuide'
  40. import value = cc.js.value
  41. import {CastleSkillConfig} from '../config/CastleSkillConfig'
  42. import {MonsterManualConfig} from '../config/MonsterManualConfig'
  43. import {IZumaConfig} from '../config/ZumaConfig'
  44. export class GlobalManager {
  45. userGuideCom: UserGuide
  46. curGuideStep: number = 0
  47. lastPower: number
  48. adInfoStorage: any
  49. startPoint: cc.Vec2 //开始触摸的位置
  50. curPoint: cc.Vec2 //触摸的当前位置
  51. moveOverstepPx: number = 30 //触摸物品后移动超过多少像素就不弹出详细信息
  52. reset() {
  53. this.adInfoStorage = null
  54. this.curGuideStep = 0
  55. }
  56. getItemNode(parent, type: PREFAB_TYPE, url: string, baseUI: BaseUI) {
  57. let pool = Data.main.itemsPoolMap.get(`${type}_${url}`)
  58. if (!pool) {
  59. pool = new cc.NodePool()
  60. Data.main.itemsPoolMap.set(`${type}_${url}`, pool)
  61. }
  62. parent.children.forEach(child => {
  63. if (PREFAB_TYPE[type] && child.name != `${type}_${url}`) {
  64. Data.main.itemsPoolMap.get(child.name)?.put(child)
  65. }
  66. })
  67. let node = cc.find(`${type}_${url}`, parent)
  68. if (!node) {
  69. node = pool.size() ? pool.get() : cc.instantiate(Data.main.itemsPrefabMap.get(type))
  70. baseUI.itemsNodes.push(node)
  71. }
  72. node.parent = parent
  73. node.name = `${type}_${url}`
  74. node['uiID'] = baseUI.uiID
  75. return node
  76. }
  77. initRoleItem(iRole: IRole, parent: cc.Node, baseUI: BaseUI, cfg?: ItemUICfg) {
  78. let node = this.initCfgRoleItem(iRole.cfg, parent, baseUI, cfg)
  79. ccUtils.setLabel(cfg && cfg.hideLv ? '' : `lv.${iRole.hero.lv}`, node, 'lv')
  80. }
  81. initCfgRoleItem(
  82. {quality, qualityType, profession, url, type, ID, cost},
  83. parent: cc.Node,
  84. baseUI: BaseUI,
  85. cfg?: ItemUICfg,
  86. ): cc.Node {
  87. let node = this.getItemNode(parent, PREFAB_TYPE.role, `${ID}_${qualityType}`, baseUI)
  88. baseUI.loadNotRefTexImg(`Public/goodsQuality/item_frame${qualityType}`, node, 'item_frame')
  89. baseUI.loadNotRefTexImg(`Public/role/icon/${url}`, node, 'icon')
  90. let professionNode = cc.find('role_type', node)
  91. professionNode.active = !cfg || !cfg.hideProfession
  92. baseUI.loadNotRefTexImg(`Public/role/role_type_${profession}`, professionNode)
  93. let maxGrade = Data.user.maxGradeArr[qualityType - 1]
  94. // let grade = cc.find('grade', node)
  95. let gradeNum = Data.user.gradeArr[quality - 1]
  96. let stars = cc.find('stars', node)
  97. if (stars) {
  98. stars.active = maxGrade > 0 && gradeNum > 0
  99. ccUtils.instantChildren(stars.children[0], gradeNum)
  100. // if (gradeNum > 0) {
  101. // baseUI.loadNotRefTexImg(`Public/role/grade_${qualityType}`, grade)
  102. // ccUtils.setLabel(gradeNum.toString(), grade, 'lv')
  103. // }
  104. }
  105. let isOnly = type == ROLE_TYPE.only
  106. let special = cc.find('item_special', node)
  107. if (special) {
  108. special.active = isOnly
  109. if (special.active) baseUI.loadNotRefTexImg(`Public/role/item_special_frame${qualityType}`, special)
  110. }
  111. ccUtils.setLabel('', node, 'lv')
  112. let costNode = cc.find('cost', node)
  113. if (costNode) {
  114. costNode.active = cost > 0 && !cfg?.hideCost
  115. if (cost > 0) ccUtils.setLabel(cost.toString(), costNode, 'lb')
  116. }
  117. return node
  118. }
  119. initRoleSpine(iRole: IRole, node: cc.Node, childUrl?: string) {
  120. if (childUrl) {
  121. node = cc.find(childUrl, node)
  122. }
  123. if (!node['_originScale']) {
  124. node['_originScale'] = node.scale
  125. }
  126. node.scale = (node['_originScale'] * iRole.cfg.uiScale) / 100
  127. let skeleton: sp.Skeleton = node.getComponent(sp.Skeleton)
  128. skeleton.skeletonData = Data.main.roleSpineMap.get(iRole.cfg.url)
  129. skeleton.setAnimation(0, 'stand', true)
  130. }
  131. initRoleSpineByName(name: string, node: cc.Node, childUrl?: string) {
  132. if (childUrl) {
  133. node = cc.find(childUrl, node)
  134. }
  135. let skeleton: sp.Skeleton = node.getComponent(sp.Skeleton)
  136. skeleton.skeletonData = Data.main.roleSpineMap.get(name)
  137. skeleton.setAnimation(0, 'stand', true)
  138. }
  139. initCardItem(iCard: ICard, parent: cc.Node, baseUI: BaseUI, cfg?: ItemUICfg) {
  140. let node = this.getItemNode(parent, PREFAB_TYPE.card, `${iCard.card.id}_${iCard.cfg.qualityType}`, baseUI)
  141. ccUtils.setLabel(
  142. `lv.${iCard.card.lv}${cfg && cfg.lvMax ? '/' + RoleQualityConfig[iCard.cfg.quality].maxLv : ''}`,
  143. node,
  144. 'lv',
  145. )
  146. baseUI.loadNotRefTexImg(`Public/goodsQuality/item_frame${iCard.cfg.qualityType}`, node, 'item_frame')
  147. baseUI.loadNotRefTexImg(`Public/card/icon/${iCard.cfg.url}`, node, 'icon')
  148. let maxGrade = Data.user.maxGradeArr[iCard.cfg.qualityType - 1]
  149. let grade = cc.find('grade', node)
  150. if (grade) {
  151. grade.active = maxGrade > 0 && iCard.grade > 0
  152. if (iCard.grade > 0) {
  153. baseUI.loadNotRefTexImg(`Public/role/grade_${iCard.cfg.qualityType}`, grade)
  154. ccUtils.setLabel(iCard.grade.toString(), grade, 'lv')
  155. }
  156. }
  157. }
  158. initCardDebrisItem(card: ICardDebris, parent: cc.Node, baseUI: BaseUI): cc.Node {
  159. let node = this.getItemNode(parent, PREFAB_TYPE.cardDebris, `${card.id}_${card.cfg.qualityType}`, baseUI)
  160. baseUI.loadNotRefTexImg(`Public/goodsQuality/item_frame${card.cfg.qualityType}`, node, 'item_frame')
  161. baseUI.loadNotRefTexImg(`Public/card/icon/${card.cfg.url}`, node, 'icon')
  162. ccUtils.setSpriteGray(true, node, 'icon')
  163. cc.find('debris', node).active = true
  164. return node
  165. }
  166. detailsTouchStart(flag, event) {
  167. this.startPoint = event.getLocation()
  168. this.curPoint = event.getLocation() //如果不移动的话当前位置会是空、所以默认给开始位置
  169. }
  170. detailsTouchMove(flag, event) {
  171. this.curPoint = event.getLocation()
  172. }
  173. showGoodsDetails(goodID: number) {
  174. let isXOverstep = Math.abs(this.curPoint.x - this.startPoint.x) <= this.moveOverstepPx
  175. let isYOverstep = Math.abs(this.curPoint.y - this.startPoint.y) <= this.moveOverstepPx
  176. if (isXOverstep && isYOverstep) {
  177. Mgr.ui.show(UI.ItemDetailsUI, Mgr.goods.getGoodShowInfo(goodID))
  178. }
  179. }
  180. initEquipItem(equip: IEquip, parent: cc.Node, baseUI: BaseUI, cfg: ItemUICfg = {showDetails: false}) {
  181. let node = Mgr.global.getItemNode(
  182. parent,
  183. PREFAB_TYPE.equip,
  184. `${equip.equip.id}_${equip.cfg.qualityType}`,
  185. baseUI,
  186. )
  187. node.targetOff(this)
  188. if (cfg && cfg.showDetails) {
  189. node.on(cc.Node.EventType.TOUCH_START, this.detailsTouchStart.bind(this, true), this)
  190. node.on(cc.Node.EventType.TOUCH_END, this.showGoodsDetails.bind(this, equip.equip.id), this)
  191. node.on(cc.Node.EventType.TOUCH_MOVE, this.detailsTouchMove.bind(this, false), this)
  192. }
  193. ccUtils.setLabel(
  194. `lv.${equip.equip.lv}${cfg && cfg.lvMax ? '/' + EquipmentQualityConfig[equip.cfg.quality]?.maxLv : ''}`,
  195. node,
  196. 'lv',
  197. )
  198. baseUI.loadNotRefTexImg(`Public/goodsQuality/item_frame${equip.cfg.qualityType}`, node, 'item_frame')
  199. baseUI.loadNotRefTexImg(`Public/equip/type_base${equip.cfg.qualityType}`, node, 'type_base')
  200. baseUI.loadNotRefTexImg(`Public/equip/type_icon${equip.cfg.type}`, node, 'type_base/type_icon')
  201. baseUI.loadNotRefTexImg(`Public/equip/icon/${equip.cfg.icon}`, node, 'icon')
  202. let maxGrade = Data.user.maxGradeArr[equip.cfg.qualityType - 1]
  203. let grade = cc.find('grade', node)
  204. if (grade) {
  205. grade.active = maxGrade > 0 && equip.grade > 0
  206. if (equip.grade > 0) {
  207. baseUI.loadNotRefTexImg(`Public/role/grade_${equip.cfg.qualityType}`, grade)
  208. ccUtils.setLabel(equip.grade.toString(), grade, 'lv')
  209. }
  210. }
  211. }
  212. getPowerByAttr(baseAttr: IBaseAttr): number {
  213. //比例值(万分比)
  214. let rate = Data.game.rateNum
  215. // 物理防御系数 1 - 物理防御/(物理防御+防御常数)
  216. let defenseCoe = +(
  217. 1 / +(1 - baseAttr.defense / (baseAttr.defense + Data.game.defenseConst)).toFixed(2)
  218. ).toFixed(2)
  219. defenseCoe = defenseCoe || 0
  220. // 法术防御系数 1 - 法术防御/(法术防御+防御常数)
  221. let spellDefenseCoe = +(
  222. 1 / +(1 - baseAttr.spellDefense / (baseAttr.spellDefense + Data.game.defenseConst)).toFixed(2)
  223. ).toFixed(2)
  224. spellDefenseCoe = spellDefenseCoe || 0
  225. //攻速系数 攻速/比例值
  226. let attackSpeedCoe = +(baseAttr.attackSpeed / rate).toFixed(2)
  227. attackSpeedCoe = attackSpeedCoe || 0
  228. //暴击系数 暴击伤害倍数/比例值 * 暴击率/比例值 * 2
  229. let critCoe = +(baseAttr.critNum / rate).toFixed(2) * +(baseAttr.attackCrit / rate).toFixed(2) * 2
  230. critCoe = critCoe || 0
  231. //命中系数 1/攻击CD/比例值 * 命中率/比例值
  232. let hitCoe = +(1 / +(baseAttr.attackSpeed / rate).toFixed(2)).toFixed(2) * +(baseAttr.hit / rate).toFixed(2)
  233. hitCoe = hitCoe || 0
  234. //闪避系数 1/(1-闪避率/比例值)
  235. let dodgeCoe = +(1 / +(1 - baseAttr.dodge / rate).toFixed(2)).toFixed(2)
  236. dodgeCoe = dodgeCoe || 0
  237. let power =
  238. baseAttr.attack * (1 + attackSpeedCoe + critCoe + hitCoe) * 2 +
  239. baseAttr.spellAttack * (1 + attackSpeedCoe + critCoe + hitCoe) * 2 +
  240. baseAttr.HP * (1 + defenseCoe + spellDefenseCoe + dodgeCoe) * 0.8
  241. return Math.floor(power)
  242. }
  243. buildIRole(hero: hero, role?: IRole): IRole {
  244. let iRole: IRole
  245. if (hero.id > 0 && !RoleConfig[hero.id]) {
  246. console.error('没有这个英雄')
  247. return
  248. }
  249. if (role) {
  250. iRole = role
  251. iRole.cfg = RoleConfig[hero.id]
  252. iRole.hero = hero
  253. iRole.grade = Data.user.gradeArr[iRole.cfg.quality - 1]
  254. } else {
  255. let baseAttr = this.buildIBaseAttr(RoleConfig[hero.id])
  256. iRole = {
  257. ...baseAttr,
  258. cfg: RoleConfig[hero.id],
  259. grade: Data.user.gradeArr[RoleConfig[hero.id].quality - 1],
  260. hero: hero,
  261. power: 0,
  262. isAlter: false,
  263. equips: new Array(Data.main.equipMaxNum).fill(null),
  264. }
  265. hero.equip.forEach(equip => {
  266. let iEquip = Data.user.equips.find(value => value.equip.sid == equip)
  267. if (iEquip) iRole.equips[iEquip.cfg.type - 1] = iEquip
  268. })
  269. }
  270. iRole.isAlter = Data.user.altarInfoList.findIndex(item => item.sid === iRole.hero.sid) != -1
  271. //等级加成 1 + 等级/100
  272. let lvAdd = 1 + +((iRole.hero.lv - 1) / 100).toFixed(2)
  273. this.setIBaseAttr(iRole, iRole.cfg, lvAdd, iRole.equips)
  274. iRole.power = this.getPowerByAttr(iRole)
  275. return iRole
  276. }
  277. buildHeroByCfg(id: number): IRole {
  278. if (id > 0 && !RoleConfig[id]) {
  279. console.error('没有这个英雄')
  280. return
  281. }
  282. let iHero: hero = {
  283. sid: '',
  284. id: id,
  285. lv: 0,
  286. equip: new Array(Data.main.equipMaxNum).fill(null),
  287. }
  288. return this.buildIRole(iHero)
  289. }
  290. buildICard(card: card, iCardObj?: ICard): ICard {
  291. let iCard: ICard
  292. if (card.id > 0 && !CardSkillConfig[card.id]) {
  293. console.error('没有这个卡牌')
  294. return
  295. }
  296. if (iCardObj) {
  297. iCard = iCardObj
  298. iCard.cfg = CardSkillConfig[card.id]
  299. iCard.card = card
  300. iCard.debrisCfg = Object.values(CardConsumeConfig).find(
  301. item => item.card == Math.floor(iCard.cfg.ID / 100) * 100 + 1,
  302. )
  303. iCard.grade = Data.user.gradeArr[iCard.cfg.quality - 1]
  304. } else {
  305. let baseAttr = this.buildIBaseAttr(CardSkillConfig[card.id])
  306. iCard = {
  307. ...baseAttr,
  308. cfg: CardSkillConfig[card.id],
  309. grade: Data.user.gradeArr[CardSkillConfig[card.id].quality - 1],
  310. card: card,
  311. power: 0,
  312. debrisCfg: Object.values(CardConsumeConfig).find(
  313. item => item.card == Math.floor(CardSkillConfig[card.id].ID / 100) * 100 + 1,
  314. ),
  315. }
  316. }
  317. // -----卡牌战斗力不受装备,天赋加成----
  318. //等级加成 1 + 等级/比例值
  319. let lvAdd = 1 + +((iCard.card.lv - 1) / 100).toFixed(2)
  320. this.setIBaseAttr(iCard, iCard.cfg, lvAdd, [])
  321. iCard.power = this.getPowerByAttr(iCard)
  322. return iCard
  323. }
  324. buildCardByCfg(id: number): ICard {
  325. if (id > 0 && !CardSkillConfig[id]) {
  326. console.error('没有这个卡牌')
  327. return
  328. }
  329. let iCard: card = {
  330. sid: '',
  331. id: id,
  332. lv: 0,
  333. }
  334. return this.buildICard(iCard)
  335. }
  336. buildICardDebris(idNum: idNum, iCardDebrisObj?: ICardDebris): ICardDebris {
  337. let iCardDebris: ICardDebris
  338. if (idNum.id > 0 && !CardConsumeConfig[idNum.id]) {
  339. console.error('没有这个卡牌碎片')
  340. return
  341. }
  342. if (iCardDebrisObj) {
  343. iCardDebris = iCardDebrisObj
  344. iCardDebris.cfg = CardConsumeConfig[idNum.id]
  345. iCardDebris.num = idNum.num
  346. iCardDebris.id = idNum.id
  347. } else {
  348. iCardDebris = {cfg: CardConsumeConfig[idNum.id], id: idNum.id, num: idNum.num}
  349. }
  350. return iCardDebris
  351. }
  352. buildIEquip(equip: equip, iEquipObj?: IEquip): IEquip {
  353. let iEquip: IEquip
  354. let curCfg = ArmorConfig[equip.id]
  355. if (equip.id > 0 && !curCfg) {
  356. console.error('没有这个装备')
  357. return
  358. }
  359. let baseAttr = this.buildIBaseAttr(curCfg)
  360. //等级加成 1 + 等级/比例值 废弃
  361. /*let rate = Data.game.rateNum
  362. let lvAdd = 1 + +((equip.lv - 1) / 200).toFixed(2)
  363. this.scaleBaseAttr(baseAttr, lvAdd)
  364. //舍弃小数
  365. for (let key in baseAttr) {
  366. baseAttr[key] = Math.floor(baseAttr[key])
  367. }*/
  368. //等级加成为固定值
  369. let lvAddAttr = [ATTR_NAME.HP, ATTR_NAME.attack, ATTR_NAME.spellAttack]
  370. for (let attr of lvAddAttr) {
  371. if (baseAttr[attr] > 0) {
  372. baseAttr[attr] += (equip.lv - 1) * curCfg.increaseLv
  373. }
  374. }
  375. if (iEquipObj) {
  376. iEquip = iEquipObj
  377. iEquip.cfg = curCfg
  378. iEquip.equip = equip
  379. this.changeBaseAttr(iEquip, baseAttr)
  380. iEquip.grade = Data.user.gradeArr[iEquip.cfg.quality - 1]
  381. } else {
  382. iEquip = {
  383. ...baseAttr,
  384. cfg: curCfg,
  385. equip: equip,
  386. grade: Data.user.gradeArr[curCfg.quality - 1],
  387. power: 0,
  388. }
  389. }
  390. iEquip.power = this.getPowerByAttr(iEquip)
  391. return iEquip
  392. }
  393. buildEquipByCfg(id: number): IEquip {
  394. if (id > 0 && !ArmorConfig[id]) {
  395. console.error('没有这个装备')
  396. return
  397. }
  398. let iEquip: equip = {
  399. sid: '',
  400. id: id,
  401. lv: 0,
  402. hero: '',
  403. }
  404. return this.buildIEquip(iEquip)
  405. }
  406. buildICastleSkill(id: number): ICastleSkill {
  407. let cfg = CastleSkillConfig[id]
  408. let baseAttr = this.buildIBaseAttr(cfg)
  409. return {
  410. ...baseAttr,
  411. cfg,
  412. lv: cfg.ID % 100,
  413. isUse: id == Data.user.useCastleSkillID,
  414. }
  415. }
  416. buildIBaseAttr(cfg: IBaseAttr, isZero: boolean = false) {
  417. let baseAttr = {
  418. HP: isZero ? 0 : cfg.HP,
  419. attack: isZero ? 0 : cfg.attack,
  420. spellAttack: isZero ? 0 : cfg.spellAttack,
  421. realAttack: isZero ? 0 : cfg.realAttack,
  422. defense: isZero ? 0 : cfg.defense,
  423. spellDefense: isZero ? 0 : cfg.spellDefense,
  424. attackSpeed: isZero ? 0 : cfg.attackSpeed,
  425. attackCrit: isZero ? 0 : cfg.attackCrit,
  426. critNum: isZero ? 0 : cfg.critNum,
  427. hit: isZero ? 0 : cfg.hit,
  428. dodge: isZero ? 0 : cfg.dodge,
  429. moveSpeed: isZero ? 0 : cfg.moveSpeed,
  430. }
  431. return baseAttr
  432. }
  433. changeBaseAttr(baseAttr: IBaseAttr, changeAttr: IBaseAttr, isAdd: boolean = false) {
  434. baseAttr.HP = isAdd ? baseAttr.HP + changeAttr.HP : changeAttr.HP
  435. baseAttr.attack = isAdd ? baseAttr.attack + changeAttr.attack : changeAttr.attack
  436. baseAttr.attackSpeed = isAdd ? baseAttr.attackSpeed + changeAttr.attackSpeed : changeAttr.attackSpeed
  437. baseAttr.attackCrit = isAdd ? baseAttr.attackCrit + changeAttr.attackCrit : changeAttr.attackCrit
  438. baseAttr.critNum = isAdd ? baseAttr.critNum + changeAttr.critNum : changeAttr.critNum
  439. baseAttr.defense = isAdd ? baseAttr.defense + changeAttr.defense : changeAttr.defense
  440. baseAttr.dodge = isAdd ? baseAttr.dodge + changeAttr.dodge : changeAttr.dodge
  441. baseAttr.hit = isAdd ? baseAttr.hit + changeAttr.hit : changeAttr.hit
  442. baseAttr.spellAttack = isAdd ? baseAttr.spellAttack + changeAttr.spellAttack : changeAttr.spellAttack
  443. baseAttr.spellDefense = isAdd ? baseAttr.spellDefense + changeAttr.spellDefense : changeAttr.spellDefense
  444. baseAttr.realAttack = isAdd ? baseAttr.realAttack + changeAttr.realAttack : changeAttr.realAttack
  445. baseAttr.moveSpeed = isAdd ? baseAttr.moveSpeed + changeAttr.moveSpeed : changeAttr.moveSpeed
  446. return baseAttr
  447. }
  448. scaleBaseAttr(baseAttr: IBaseAttr, scale: number) {
  449. baseAttr.HP *= scale
  450. baseAttr.attack *= scale
  451. baseAttr.attackSpeed *= scale
  452. baseAttr.attackCrit *= scale
  453. baseAttr.critNum *= scale
  454. baseAttr.defense *= scale
  455. baseAttr.dodge *= scale
  456. baseAttr.hit *= scale
  457. baseAttr.spellAttack *= scale
  458. baseAttr.spellDefense *= scale
  459. baseAttr.realAttack *= scale
  460. baseAttr.moveSpeed = baseAttr.moveSpeed
  461. return baseAttr
  462. }
  463. setIBaseAttr(obj: ICard | IRole, cfg: IBaseAttr, lvAdd: number, equips: IEquip[]) {
  464. //装备加成
  465. let attr = this.buildIBaseAttr(null, true)
  466. let allEntryArr: number[] = []
  467. for (let i = 0; i < equips.length; i++) {
  468. if (equips[i]) {
  469. this.changeBaseAttr(attr, equips[i], true)
  470. if (equips[i].cfg.entry) allEntryArr.push(equips[i].cfg.entry)
  471. }
  472. }
  473. obj.HP = cfg.HP * lvAdd + attr.HP
  474. obj.attack = cfg.attack * lvAdd + attr.attack
  475. obj.attackSpeed = cfg.attackSpeed * lvAdd + attr.attackSpeed
  476. obj.attackCrit = cfg.attackCrit * lvAdd + attr.attackCrit
  477. obj.critNum = cfg.critNum * lvAdd + attr.critNum
  478. obj.defense = cfg.defense * lvAdd + attr.defense
  479. obj.dodge = cfg.dodge * lvAdd + attr.dodge
  480. obj.hit = cfg.hit * lvAdd + attr.hit
  481. obj.spellAttack = cfg.spellAttack * lvAdd + attr.spellAttack
  482. obj.spellDefense = cfg.spellDefense * lvAdd + attr.spellDefense
  483. obj.realAttack = cfg.realAttack * lvAdd + attr.realAttack
  484. obj.moveSpeed = cfg.moveSpeed + attr.moveSpeed
  485. //天赋词条加成
  486. if ('hero' in obj) {
  487. let profession = obj.cfg.profession
  488. if (Data.main.talentAdd && Data.main.talentAdd[profession]) {
  489. this.changeBaseAttr(obj, Data.main.talentAdd[profession], true)
  490. }
  491. }
  492. // 所有角色卡牌基础属性万分比词条加成
  493. for (let entry of allEntryArr) {
  494. switch (EntryConfig[entry].type) {
  495. case ENTRY.addRoleHP:
  496. obj.HP *= 1 + EntryConfig[entry].rateArr[0] / Data.game.rateNum
  497. case ENTRY.equipAddAttack:
  498. obj.attack *= 1 + EntryConfig[entry].rateArr[0] / Data.game.rateNum
  499. break
  500. }
  501. }
  502. obj.HP = Math.floor(obj.HP)
  503. obj.attack = Math.floor(obj.attack)
  504. obj.attackSpeed = Math.floor(obj.attackSpeed)
  505. obj.attackCrit = Math.floor(obj.attackCrit)
  506. obj.critNum = Math.floor(obj.critNum)
  507. obj.defense = Math.floor(obj.defense)
  508. obj.dodge = Math.floor(obj.dodge)
  509. obj.hit = Math.floor(obj.hit)
  510. obj.spellAttack = Math.floor(obj.spellAttack)
  511. obj.spellDefense = Math.floor(obj.spellDefense)
  512. obj.realAttack = Math.floor(obj.realAttack)
  513. obj.moveSpeed = Math.floor(obj.moveSpeed)
  514. }
  515. getPower() {
  516. let power = 0
  517. Data.user.teamRole.forEach(iRole => {
  518. if (iRole) {
  519. this.buildIRole(iRole.hero, iRole)
  520. power += iRole.power
  521. }
  522. })
  523. Data.user.teamCard.forEach(iCard => {
  524. if (iCard) {
  525. this.buildICard(iCard.card, iCard)
  526. power += iCard.power
  527. }
  528. })
  529. return power
  530. }
  531. getPowerString() {
  532. return Math.toKMBNum(this.getPower())
  533. }
  534. initPower() {
  535. this.lastPower = this.getPower()
  536. }
  537. updatePower() {
  538. let newPower = this.getPower()
  539. if (newPower > this.lastPower) {
  540. Mgr.ui.show(UI.PowerUpUI, `+${newPower - this.lastPower}`)
  541. this.lastPower = newPower
  542. }
  543. }
  544. entryBaseAttrAdd(baseAttr: IBaseAttr, entryID: number[]) {
  545. for (let id of entryID) {
  546. let entryCfg = EntryConfig[id]
  547. if (entryCfg.type >= ENTRY.HP && entryCfg.type <= ENTRY.realAttack) {
  548. baseAttr[ENTRY[entryCfg.type]] += entryCfg.parmArr[0]
  549. }
  550. if (entryCfg.type >= ENTRY.HPRate && entryCfg.type <= ENTRY.realAttackRate) {
  551. baseAttr[ENTRY[entryCfg.type].replace(/Rate/, '')] += entryCfg.rateArr[0]
  552. }
  553. if (entryCfg.type == ENTRY.talAddAllDefense) {
  554. baseAttr.defense += entryCfg.parmArr[0]
  555. baseAttr.spellDefense += entryCfg.parmArr[0]
  556. }
  557. }
  558. }
  559. //天赋加成是基础值
  560. initTalentAdd() {
  561. Data.user.talents.sort((a, b) => a - b)
  562. let talentAdds = []
  563. for (let i = PROFESSION.warrior; i <= PROFESSION.archer; i++) {
  564. let talentAdd = this.buildIBaseAttr(null, true)
  565. let entryIDs: number[] = []
  566. Data.user.talents.forEach(value => {
  567. if (EntryConfig[TalentConfig[value].entryID].profession.includes(i)) {
  568. entryIDs.push(TalentConfig[value].entryID)
  569. }
  570. })
  571. this.entryBaseAttrAdd(talentAdd, entryIDs)
  572. let addAllAttrRateArr: ENTRY[] = [
  573. ENTRY.talAddHP,
  574. ENTRY.talAddattack,
  575. ENTRY.talAddspellAttack,
  576. ENTRY.talAdddefense,
  577. ENTRY.talAddspellDefense,
  578. ]
  579. for (let id of Data.user.talents) {
  580. let cfg = TalentConfig[id]
  581. let entryCfg = EntryConfig[cfg.entryID]
  582. if (addAllAttrRateArr.includes(entryCfg.type)) {
  583. talentAdd[ENTRY[entryCfg.type].replace('talAdd', '')] *= 1 + entryCfg.rateArr[0] / Data.game.rateNum
  584. }
  585. }
  586. talentAdds[i] = talentAdd
  587. }
  588. Data.main.talentAdd = talentAdds
  589. }
  590. checkModOpen(modID: number) {
  591. // if (CC_DEV) return true
  592. return this.checkModOpenBeyond(modID)
  593. }
  594. checkModOpenBeyond(modID: number, checkCurrent: boolean = false) {
  595. let cfg = FunctionsConfig[modID]
  596. let check = true
  597. //mod为0时,不跳转页面
  598. if (!checkCurrent && cfg == undefined) return check
  599. if (!cfg && checkCurrent) return false
  600. switch (cfg.condition) {
  601. case CONDITION_FUNC.teamLevel:
  602. check = checkCurrent ? Data.user.level == cfg.parameter : Data.user.level >= cfg.parameter
  603. break
  604. case CONDITION_FUNC.normalBarrier:
  605. check = checkCurrent
  606. ? Data.user.adventureId == cfg.parameter + 1
  607. : Data.user.adventureId >= cfg.parameter + 1
  608. break
  609. case CONDITION_FUNC.createRoleDay:
  610. let day = Date.getDayDHMS(Data.main.serverTime - Data.user.createTime).day
  611. check = checkCurrent ? day == cfg.parameter : day >= cfg.parameter
  612. break
  613. case CONDITION_FUNC.eliteBarrier:
  614. check = checkCurrent ? Data.user.eliteId == cfg.parameter + 1 : Data.user.eliteId >= cfg.parameter + 1
  615. break
  616. }
  617. return check
  618. }
  619. getModLockTip(modID: number) {
  620. let cfg = FunctionsConfig[modID]
  621. let text = ''
  622. if (cfg) {
  623. let target = Mgr.i18n.getLabel(FunctionsConfig[modID].name)
  624. switch (cfg.condition) {
  625. case CONDITION_FUNC.teamLevel:
  626. text = Mgr.i18n.getLabel(LANGUAGE_TYPE.teamLevel, [cfg.parameter.toString(), target])
  627. break
  628. case CONDITION_FUNC.normalBarrier:
  629. let stageInfoCfg = StageInfoConfig[cfg.parameter],
  630. barrierName = `${Mgr.i18n.getLabel(stageInfoCfg.name)}-${stageInfoCfg.des}`
  631. text = Mgr.i18n.getLabel(LANGUAGE_TYPE.normalBarrier, [barrierName, target])
  632. break
  633. case CONDITION_FUNC.createRoleDay:
  634. text = Mgr.i18n.getLabel(LANGUAGE_TYPE.createRoleDay, [cfg.parameter.toString(), target])
  635. break
  636. }
  637. }
  638. return text
  639. }
  640. showModLockTip(modID: number) {
  641. Mgr.ui.tip(this.getModLockTip(modID))
  642. }
  643. //检查是否功能开启,并显示跳转页面
  644. tryJumpMod(modID: number) {
  645. //modID为0时,不跳转
  646. if (modID == 0) return
  647. let isOpen = Mgr.global.checkModOpen(modID)
  648. if (isOpen) {
  649. //对金币&体力购买界面做特殊处理
  650. if (modID == MOD.fatigueBuy || modID == MOD.moneyBuy) {
  651. return
  652. }
  653. let uiID = null
  654. let uiArgs = null
  655. let preOpenUIs = []
  656. let preOpenUIArgs = []
  657. if (!UI[modID]) {
  658. switch (modID) {
  659. case MOD.giftStore:
  660. case MOD.dailyGift:
  661. case MOD.weekGift:
  662. case MOD.noviceGift:
  663. case MOD.dailyStore:
  664. case MOD.resourceStore:
  665. case MOD.relicStore:
  666. uiID = UI.ShopUI
  667. uiArgs = modID
  668. break
  669. case MOD.advancedCharge:
  670. case MOD.elite:
  671. uiID = UI.StageChooseUI
  672. uiArgs = GAME_TYPE.elite
  673. break
  674. case MOD.equipGet:
  675. uiID = UI.RecruitUI
  676. uiArgs = RECRUIT_TYPE.forging //装备锻造
  677. break
  678. case MOD.explore:
  679. preOpenUIs.push(UI.CurrencyUI)
  680. preOpenUIArgs[preOpenUIs.length - 1] = [GOODS.coin, GOODS.diamond, GOODS.fatigue]
  681. uiArgs = modID
  682. break
  683. }
  684. } else {
  685. uiID = modID
  686. switch (modID) {
  687. case UI.StageChooseUI:
  688. uiArgs = GAME_TYPE.normal
  689. break
  690. case UI.RecruitUI:
  691. //默认抽奖-人物
  692. uiArgs = RECRUIT_TYPE.summoning //英雄召唤
  693. }
  694. }
  695. if (Mgr.ui.isTopUI(uiID)) {
  696. Mgr.ui.callOnShow(uiID, uiArgs)
  697. return
  698. }
  699. Mgr.ui.closeAll([UI.MainUI])
  700. preOpenUIs.forEach((v, i) => Mgr.ui.show(v, preOpenUIArgs[i]))
  701. if (uiID) Mgr.ui.show(uiID, uiArgs)
  702. } else {
  703. this.showModLockTip(modID)
  704. }
  705. }
  706. tryOpenNextReadyBox() {
  707. let open = false
  708. if (Data.user.readyOpenBox.length > 0) {
  709. let idNum = Data.user.readyOpenBox.shift()
  710. switch (GoodsConfig[idNum.id].type) {
  711. case GOODS_TYPE.randomBox:
  712. let req = boxGetAward.create()
  713. req.type = GOODS_TYPE.randomBox
  714. Data.user.readyOpenBox = Data.user.readyOpenBox.filter(
  715. value => GoodsConfig[value.id].type != GOODS_TYPE.randomBox,
  716. )
  717. Mgr.net.send(msgCmd.cmd_box_get_award, req)
  718. break
  719. case GOODS_TYPE.selectBox:
  720. open = true
  721. Data.user.readyOpenBox.unshift(idNum)
  722. break
  723. }
  724. }
  725. return open
  726. }
  727. //存入&修改localStorage中adFree相关信息(id: adFree_id, time: 结束时间戳)
  728. storageAdInfo(id: number, timeStamp: number, leftDailyTimes: number) {
  729. if (!id) return
  730. let obj = {timeStamp, leftDailyTimes}
  731. if (this.adInfoStorage) {
  732. this.adInfoStorage[id] = obj
  733. } else {
  734. let item = Mgr.storage.getObject(LOCAL.adFreeInfo, {})
  735. item[id] = obj
  736. this.adInfoStorage = item
  737. }
  738. Mgr.storage.set(LOCAL.adFreeInfo, this.adInfoStorage)
  739. }
  740. //获得对应adfree_id对应时间戳
  741. getAdInfo(id: number) {
  742. let adFreeInfos = this.adInfoStorage
  743. if (!adFreeInfos) {
  744. adFreeInfos = Mgr.storage.getObject(LOCAL.adFreeInfo, {})
  745. }
  746. let time = adFreeInfos[id] ? adFreeInfos[id].timeStamp - Data.main.serverTime : -0.1
  747. let min = Math.floor(time / 60)
  748. let sec = time % 60
  749. let dailyTimes = adFreeInfos[id] ? adFreeInfos[id].leftDailyTimes : 0
  750. let status: IAdStatus = {
  751. time,
  752. min: min.toString().zeroPrefix(min, 2),
  753. sec: sec.toString().zeroPrefix(sec, 2),
  754. isZero: time == 0,
  755. inTime: time > 0 && dailyTimes > 0,
  756. dailyTimes,
  757. }
  758. return status
  759. }
  760. tryShowUserGuide(keys: string[], callback: Function = null) {
  761. //没有账号不进入引导
  762. if (!Data.user.uid) return false
  763. if (!keys || keys.length == 0) return false
  764. let bigStep = +keys[0].split('_')[0]
  765. if (this.curGuideStep > 2 && this.curGuideStep != bigStep) return false
  766. //1级0经验引导
  767. if (bigStep == 1 && (Data.user.exp > 0 || Data.user.level > 1)) {
  768. return false
  769. }
  770. //打完第一关引导
  771. if (bigStep == 2 && Data.user.adventureId != 2) {
  772. return false
  773. }
  774. //功能引导
  775. if (bigStep > 2 && bigStep < 10000 && !this.checkModOpenBeyond(bigStep, true)) {
  776. return false
  777. }
  778. //密林5第十关Boss说明引导
  779. if (bigStep == 10001 && Data.game.stageID != 10) {
  780. return false
  781. }
  782. //特殊怪物引导
  783. if (
  784. bigStep == 10002 &&
  785. !Object.values(MonsterManualConfig)
  786. .map(v => v.trigger)
  787. .includes(Data.game.stageID)
  788. ) {
  789. return false
  790. }
  791. let curStep = Mgr.storage.getNumber(`userGuide_${bigStep}`)
  792. if (curStep) {
  793. keys = keys.filter(value => +value.split('_')[1] > curStep)
  794. //当前引导小于等于存储的不引导
  795. if (keys.length == 0) return false
  796. }
  797. Mgr.storage.set(`userGuide_${bigStep}`, +keys[keys.length - 1].split('_')[1])
  798. this.userGuideCom.showGuideByGroup(keys, callback)
  799. this.curGuideStep = bigStep
  800. return true
  801. }
  802. initAvatar(node, baseUI: BaseUI) {
  803. let sprite = node.getComponent(cc.Sprite)
  804. if (Data.user.avatarTex) {
  805. sprite.spriteFrame = new cc.SpriteFrame(Data.user.avatarTex)
  806. } else {
  807. baseUI.loadTexImg(`Public/avatar/${Data.user.avatar}`, node)
  808. }
  809. }
  810. }