SubwayGenPuppet.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { Vec3, v3 } from "cc";
  2. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  3. import { MoveToComp } from "../../common/ecs/position/MoveTo";
  4. import { Subway } from "../Subway";
  5. import { SubwayModelComp } from "../model/SubwayModelComp";
  6. import { smc } from "../../common/SingletonModuleComp";
  7. import { SubwayEnum } from "../model/SubwayEnum";
  8. import { Puppet } from "../../puppet/puppet";
  9. import { PuppetModelComp } from "../../puppet/model/PuppetModelComp";
  10. import { PuppetAnimatorType } from "../../puppet/model/PuppetEnum";
  11. import { PathFindComp } from "../../common/ecs/path/PathFind";
  12. import { CheckpointPathTriggerComp } from "../../checkpoint/bll/CheckpointPathTrigger";
  13. /** 检查左侧和右侧是否可以出人 */
  14. @ecs.register('SubwayGenPuppet')
  15. export class SubwayGenPuppetComp extends ecs.Comp {
  16. isGen:boolean = false
  17. reset() {
  18. this.isGen = false
  19. }
  20. }
  21. export class SubwayGenPuppetSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
  22. filter(): ecs.IMatcher {
  23. return ecs.allOf(SubwayGenPuppetComp, SubwayModelComp);
  24. }
  25. // entityEnter(e: Subway): void {
  26. // e.remove(SubwayGenPuppetComp)
  27. // }
  28. update(e: Subway): void {
  29. const checkpoint = smc.initialize.account.checkpoint
  30. const genComp = e.get(SubwayGenPuppetComp)
  31. if(genComp.isGen||e.SubwayModel.colorArr.length===0)return
  32. if (checkpoint && checkpoint.CheckpointModel) {
  33. const cells = checkpoint.CheckpointModel.cells
  34. const grids = checkpoint.CheckpointModel.grids
  35. if (e.SubwayModel.type === SubwayEnum.LEFT) {
  36. if (e.SubwayModel.y === 0) {
  37. console.log('地铁靠边出不来的哦')
  38. return
  39. }
  40. const cell = cells[e.SubwayModel.x][e.SubwayModel.y-1]
  41. const grid = grids[e.SubwayModel.x][e.SubwayModel.y-1]
  42. if (grid && !cell) {
  43. genComp.isGen = true
  44. const pos = grid.GridView.node.position.clone()
  45. this.createPuppet(e, e.SubwayModel.x, e.SubwayModel.y-1, pos)
  46. }
  47. } else {
  48. if (e.SubwayModel.y === cells[0]?.length - 1) {
  49. console.log('地铁靠边出不来的哦')
  50. return
  51. }
  52. const cell = cells[e.SubwayModel.x][e.SubwayModel.y+1]
  53. const grid = grids[e.SubwayModel.x][e.SubwayModel.y+1]
  54. if (grid && !cell) {
  55. genComp.isGen = true
  56. const pos = grid.GridView.node.position.clone()
  57. this.createPuppet(e, e.SubwayModel.x, e.SubwayModel.y + 1, pos)
  58. }
  59. }
  60. }
  61. }
  62. createPuppet(e: Subway, x: number, y: number, end: Vec3) {
  63. const genComp = e.get(SubwayGenPuppetComp)
  64. if (!end|| !e.SubwayView.node) {
  65. genComp.isGen = false
  66. return
  67. }
  68. const account = smc.initialize.account
  69. const puppet = ecs.getEntity<Puppet>(Puppet)
  70. const puppetModel = puppet.get(PuppetModelComp)
  71. const color = e.SubwayModel.colorArr.shift()
  72. e.SubwayView.updateCount(e.SubwayModel.colorArr.length)
  73. puppetModel.color = color
  74. puppetModel.withColider = true
  75. puppet.load(account.checkpoint.CheckpointView.node, color, e.SubwayView.node.position.clone(), account.AccountModel.skin);
  76. e.addChild(puppet)
  77. if (e.SubwayModel.type === SubwayEnum.LEFT) {
  78. puppet.PuppetView.animator.toLeft()
  79. } else {
  80. puppet.PuppetView.animator.toRight()
  81. }
  82. puppet.PuppetView.animator.playAni(PuppetAnimatorType.Run)
  83. puppet.PuppetView.animator.scale()
  84. puppet.PuppetView.animator.onRunComplete = () => {
  85. puppet.PuppetView.animator.toStation()
  86. }
  87. puppet.PuppetView.animator.moveToTarget(end)
  88. if (e.SubwayModel.type === SubwayEnum.LEFT) {
  89. account.checkpoint.CheckpointModel.cells[e.SubwayModel.x][e.SubwayModel.y - 1] = puppet
  90. account.checkpoint.CheckpointModel.path_grid[e.SubwayModel.x][e.SubwayModel.y - 1] = {
  91. x: e.SubwayModel.x,
  92. y: e.SubwayModel.y - 1,
  93. fill: color,
  94. pos: end
  95. }
  96. puppetModel.x = e.SubwayModel.x
  97. puppetModel.y = e.SubwayModel.y-1
  98. const pathComp = puppet.add(PathFindComp)
  99. pathComp.x = e.SubwayModel.x
  100. pathComp.y = e.SubwayModel.y - 1
  101. } else {
  102. account.checkpoint.CheckpointModel.cells[e.SubwayModel.x][e.SubwayModel.y + 1] = puppet
  103. account.checkpoint.CheckpointModel.path_grid[e.SubwayModel.x][e.SubwayModel.y + 1] = {
  104. x: e.SubwayModel.x,
  105. y: e.SubwayModel.y + 1,
  106. fill: color,
  107. pos: end
  108. }
  109. puppetModel.x = e.SubwayModel.x
  110. puppetModel.y = e.SubwayModel.y+1
  111. const pathComp = puppet.add(PathFindComp)
  112. pathComp.x = e.SubwayModel.x
  113. pathComp.y = e.SubwayModel.y + 1
  114. }
  115. account.checkpoint.add(CheckpointPathTriggerComp)
  116. genComp.isGen = false
  117. }
  118. }