FAltar.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FF from "../../FF";
  3. import FMap from "../../map/FMap";
  4. import FAltarLight from "./FAltarLight";
  5. /**
  6. * 祭坛
  7. */
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class FAltar extends cc.Component {
  11. @property({
  12. displayName: '对应的地图物件'
  13. })
  14. public mapGoodId:string = '27';
  15. @property({
  16. type:cc.Node,
  17. displayName: '点亮火焰动画'
  18. })
  19. public spine:cc.Node = null;
  20. @property({
  21. type:[FAltarLight],
  22. displayName: '祭坛灯柱'
  23. })
  24. public altarLight:Array<FAltarLight> = [];
  25. private map:FMap = null;
  26. onLoad () {
  27. this.map = this.node.parent.parent.getComponent(FMap);
  28. }
  29. start () {
  30. let ff = this.map.ff;
  31. let stage = ff.main.player.stage;
  32. if(stage.element.indexOf(this.mapGoodId) >= 0){
  33. this.spine.active = true;
  34. }else{
  35. this.spine.active = false;
  36. }
  37. }
  38. /**
  39. * 检查灯柱点亮情况
  40. */
  41. public check():boolean{
  42. for (let i = 0; i < this.altarLight.length; i++) {
  43. const element = this.altarLight[i];
  44. if(!element.spine.active){
  45. return false;
  46. }
  47. }
  48. this.altarOK();
  49. return true
  50. }
  51. /**
  52. * 祭坛亮起来
  53. */
  54. private altarOK(){
  55. this.getMapObject(this.mapGoodId);
  56. }
  57. /**
  58. * 捡起地图上的物品
  59. * @param objectId
  60. */
  61. public getMapObject(objectId:string){
  62. let msg = {
  63. objectId:objectId
  64. }
  65. let ff = this.map.ff;
  66. ff.main.gameHttp.sendJson('stage/v1/stageObject',msg,(state,reve:ReveData)=>{
  67. if(state == HttpStateType.SUCCESS){
  68. if(reve.retCode == 0){
  69. let player = ff.main.player;
  70. let stage = player.stage;
  71. stage.element.push(objectId);
  72. let list = ff.main.sManage.getRewards(reve);
  73. this.playAction(list);
  74. }else{
  75. ff.main.showTips(reve.message);
  76. }
  77. }else{
  78. ff.main.showTips('网络异常');
  79. }
  80. });
  81. }
  82. private playAction(list){
  83. let ff = this.map.ff;
  84. ff.pauseSprite(true);
  85. this.spine.opacity = 0;
  86. this.spine.active = true;
  87. cc.tween(this.spine).sequence(
  88. cc.callFunc(()=>{
  89. this.moveCamera();
  90. }),
  91. cc.delayTime(0.7),
  92. cc.fadeIn(0.5),
  93. cc.callFunc(()=>{
  94. ff.pauseSprite(false);
  95. ff.addGoods(list,this.node.getPosition());
  96. })
  97. ).start();
  98. }
  99. private moveCamera(){
  100. let map = this.map;
  101. let camera = map.mCamera;
  102. let pos = cc.v3();
  103. let winsize = cc.winSize;
  104. pos.x = this.node.x -winsize.width/2;
  105. pos.y = this.node.y -winsize.height/2;
  106. cc.tween(camera.node).
  107. to(0.5,{position:pos}).start();
  108. }
  109. }