GameData.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /** @format */
  2. import {Data} from '../GameControl'
  3. import {ccUtils} from '../utils/ccUtils'
  4. import {GAME_TYPE} from '../enums/Enum'
  5. import {observable} from 'mobx'
  6. import {idNum} from '../proto/typedef'
  7. /** @format */
  8. export class GameData {
  9. groupList: string[] = [
  10. 'default',
  11. 'friend',
  12. 'enemy',
  13. 'friendBullet',
  14. 'enemyBullet',
  15. 'friendHurtSkill',
  16. 'friendGainSkill',
  17. 'enemyHurtSkill',
  18. 'enemyGainSkill',
  19. 'friendHurtSkillMonitor',
  20. 'friendGainSkillMonitor',
  21. 'enemyHurtSkillMonitor',
  22. 'enemyGainSkillMonitor',
  23. 'friendMeleeMonitor',
  24. 'enemyMeleeMonitor',
  25. 'friendMeleeXMonitor',
  26. 'enemyMeleeXMonitor',
  27. 'friendAttackMonitor',
  28. 'enemyAttackMonitor',
  29. 'skillArea',
  30. ]
  31. gFriend: number = this.groupList.indexOf('friend')
  32. gEnemy: number = this.groupList.indexOf('enemy')
  33. gFriendBullet: number = this.groupList.indexOf('friendBullet')
  34. gEnemyBullet: number = this.groupList.indexOf('enemyBullet')
  35. gFriendHurtSkill: number = this.groupList.indexOf('friendHurtSkill')
  36. gFriendGainSkill: number = this.groupList.indexOf('friendGainSkill')
  37. gEnemyHurtSkill: number = this.groupList.indexOf('enemyHurtSkill')
  38. gEnemyGainSkill: number = this.groupList.indexOf('enemyGainSkill')
  39. gFriendHurtSkillMonitor: number = this.groupList.indexOf('friendHurtSkillMonitor')
  40. gFriendGainSkillMonitor: number = this.groupList.indexOf('friendGainSkillMonitor')
  41. gEnemyHurtSkillMonitor: number = this.groupList.indexOf('enemyHurtSkillMonitor')
  42. gEnemyGainSkillMonitor: number = this.groupList.indexOf('enemyGainSkillMonitor')
  43. gFriendMeleeMonitor: number = this.groupList.indexOf('friendMeleeMonitor')
  44. gEnemyMeleeMonitor: number = this.groupList.indexOf('enemyMeleeMonitor')
  45. gFriendMeleeXMonitor: number = this.groupList.indexOf('friendMeleeXMonitor')
  46. gEnemyMeleeXMonitor: number = this.groupList.indexOf('enemyMeleeXMonitor')
  47. gFriendAttackMonitor: number = this.groupList.indexOf('friendAttackMonitor')
  48. gEnemyAttackMonitor: number = this.groupList.indexOf('enemyAttackMonitor')
  49. gSkillArea: number = this.groupList.indexOf('skillArea')
  50. collisionMatrix: boolean[][] = new Array(this.groupList.length)
  51. .fill([])
  52. .map(() => new Array(this.groupList.length).fill(false))
  53. gameBundle: cc.AssetManager.Bundle
  54. gameAssetMap: Map<string, cc.Asset> = new Map()
  55. //近战探测范围
  56. meleeRange: number = 130
  57. //万分比
  58. rateNum: number = 10000
  59. //配置表CD最大值
  60. cdMax: number = 9999
  61. //防御常数
  62. defenseConst: number = 325
  63. //环境伤害倍率
  64. curHurtRate: number = 0
  65. //光环cd
  66. holoCD: number = 0.1
  67. //光环buff持续时间 (光环cd小于光环持续时间)
  68. holoDuration: number = 0.15
  69. attackLeftRadiusPoints: cc.Vec2[] = []
  70. attackRightRadiusPoints: cc.Vec2[] = []
  71. //角色出生范围
  72. fightSizeMaxY: number = 0
  73. fightSizeMinY: number = -200
  74. fightSizeMaxX: number = 350
  75. fightSizeMinX: number = -350
  76. //子弹,触摸等范围
  77. fightAreaMaxY: number = 100
  78. fightAreaMinY: number = -300
  79. fightAreaMaxX: number = 350
  80. fightAreaMinX: number = -350
  81. meleeMonitorRangeX: number = 200
  82. meleeMonitorRangeY: number = 1000
  83. meleeYMonitorRangeX: number = 3000
  84. meleeYMonitorRangeY: number = 300
  85. //关卡ID
  86. stageID: number = 1
  87. //关卡波数ID
  88. stageRound: number
  89. //关卡试玩次数
  90. trailTimes: number
  91. //开启试玩
  92. trailOpen: boolean
  93. //关卡试玩ID
  94. trailID: number
  95. gameType: GAME_TYPE = GAME_TYPE.none
  96. spineTimeRate: number = 1
  97. spineScale: number = 0.22
  98. maxAttackSpeed: number = 50000
  99. minAttackSpeed: number = 5000
  100. maxAttackRange: number = 1000
  101. relicEntryArr: number[] = []
  102. dropOut: idNum[]
  103. @observable
  104. gameSpeed: number = 1
  105. speedUpTime: number = 0
  106. friendNum: number = 3
  107. init() {
  108. let colliderPairs = [
  109. [this.gFriend, this.gEnemyAttackMonitor],
  110. [this.gFriend, this.gEnemyBullet],
  111. [this.gFriend, this.gFriendGainSkill],
  112. [this.gFriend, this.gEnemyHurtSkill],
  113. [this.gFriend, this.gFriendGainSkillMonitor],
  114. [this.gFriend, this.gEnemyHurtSkillMonitor],
  115. [this.gFriend, this.gSkillArea],
  116. [this.gEnemy, this.gFriendAttackMonitor],
  117. [this.gEnemy, this.gFriendBullet],
  118. [this.gEnemy, this.gEnemyGainSkill],
  119. [this.gEnemy, this.gFriendHurtSkill],
  120. [this.gEnemy, this.gEnemyGainSkillMonitor],
  121. [this.gEnemy, this.gFriendHurtSkillMonitor],
  122. [this.gEnemy, this.gSkillArea],
  123. [this.gFriendMeleeMonitor, this.gEnemyMeleeMonitor],
  124. [this.gFriendMeleeXMonitor, this.gEnemyMeleeXMonitor],
  125. ,
  126. ]
  127. for (let i = 0; i < this.groupList.length; i++) {
  128. for (let j = 0; j < this.groupList.length; j++) {
  129. this.collisionMatrix[i][j] = colliderPairs.some(arr => {
  130. return [JSON.stringify([i, j]), JSON.stringify([j, i])].includes(JSON.stringify(arr))
  131. })
  132. }
  133. }
  134. //n必须为偶数,单边扇形有n+1个点
  135. this.attackLeftRadiusPoints = ccUtils.generateAttackPoints(Data.game.meleeRange, 10, true, 1)
  136. this.attackRightRadiusPoints = ccUtils.generateAttackPoints(Data.game.meleeRange, 10, false, 1)
  137. //console.log(Data.game.attackLeftRadiusPoints, Data.game.attackRightRadiusPoints)
  138. }
  139. reset() {
  140. Data.game.gameSpeed = 1
  141. }
  142. maskBitByGroupIndex(groupIndex: number) {
  143. let maskBits = 0
  144. let bits = this.collisionMatrix[groupIndex]
  145. for (let i = 0; i < bits.length; i++) {
  146. if (!bits[i]) continue
  147. maskBits |= 1 << i
  148. }
  149. //console.log(this.groupList[groupIndex], '----->', groupIndex, '----mask---------->', maskBits)
  150. return maskBits
  151. }
  152. }