FDialogPack26.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import { HttpStateType, ReveData } from "../../../../util/CHttp";
  2. import FF from "../../FF";
  3. import FSprite from "../../object/FSprite";
  4. import WOneByone from "../map1/WOneByone";
  5. import FFruit26 from "./FFruit26";
  6. /**
  7. * 摘果子任务 奖励编号26
  8. */
  9. const {ccclass, property} = cc._decorator;
  10. @ccclass
  11. export default class FDialogPack26 extends cc.Component {
  12. @property(cc.Prefab)
  13. mMapDialog: cc.Prefab = null;
  14. @property({
  15. type:cc.Node,
  16. displayName: '任务提示'
  17. })
  18. public iconTouch:cc.Node = null;
  19. @property({
  20. displayName: '收集的道具id'
  21. })
  22. public goodId = 3002;
  23. @property({
  24. type:[FFruit26],
  25. displayName: '收集的地图上的果子'
  26. })
  27. public goodNodes:Array<FFruit26> = [];
  28. /**
  29. * 记录当前状态
  30. * 0:从来没有过对话
  31. * 1:对话过一次
  32. */
  33. public state:number = 0;
  34. private ff:FF;
  35. onLoad() {
  36. for (let i = 0; i < this.goodNodes.length; i++) {
  37. const element = this.goodNodes[i];
  38. element.setPick26(this);
  39. }
  40. }
  41. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  42. if(other.node.group == 'A'){
  43. let obj = other.node.getComponent(FSprite);
  44. this.ff = obj.ff;
  45. if(obj == this.ff.mainSprite){
  46. this.showButton();
  47. }
  48. }
  49. }
  50. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  51. if(other.node.group == 'A'){
  52. let obj = other.node.getComponent(FSprite);
  53. this.ff = obj.ff;
  54. if(obj == this.ff.mainSprite){
  55. this.closeButton();
  56. }
  57. }
  58. }
  59. public showButton(){
  60. this.ff.control.mEventButton.node.active = true;
  61. this.ff.control.mEventButton.setCallback(()=>{
  62. this.startStory();
  63. });
  64. }
  65. public closeButton(){
  66. this.ff.control.mEventButton.node.active = false;
  67. }
  68. public startStory(){
  69. /**
  70. * 暂停所有
  71. */
  72. this.iconTouch.active = false;
  73. this.ff.pauseSprite(true);
  74. this.ff.mBlockInputEvents.active = true;
  75. if(this.state == 0){
  76. this.showDialog1();
  77. }else{
  78. let count = this.ff.mFFheader.getTmpCount(this.goodId);
  79. if(count >= this.goodNodes.length){
  80. this.showDialogEnd();
  81. }else{
  82. this.showDialog1_x();
  83. }
  84. }
  85. }
  86. private showDialog1(){
  87. let dialogs = [
  88. '我是美神,我最近新学了一些秀法',
  89. '如果你能给我4块棉布,我就能给你变出漂亮的衣服',
  90. ];
  91. let node = cc.instantiate(this.mMapDialog);
  92. node.group = 'map'
  93. node.zIndex = 9999;
  94. node.x = this.node.x;
  95. node.y = this.node.y + this.node.height;
  96. node.parent = this.ff.mMap.mSprites;
  97. let obo = node.getComponent(WOneByone);
  98. obo.dialogs = dialogs;
  99. obo.setCallback(()=>{
  100. this.iconTouch.active = true;
  101. node.destroy();
  102. this.ff.setBlockInputCallback(null);
  103. this.ff.pauseSprite(false);
  104. this.ff.mBlockInputEvents.active = false;
  105. this.state = 1;
  106. });
  107. this.ff.setBlockInputCallback(()=>{
  108. obo.jump();
  109. });
  110. obo._start();
  111. }
  112. private showDialog1_x(){
  113. let dialogs = [
  114. '还没找到吗?',
  115. ];
  116. let node = cc.instantiate(this.mMapDialog);
  117. node.group = 'map'
  118. node.zIndex = 9999;
  119. node.x = this.node.x;
  120. node.y = this.node.y + this.node.height;
  121. node.parent = this.ff.mMap.mSprites;
  122. let obo = node.getComponent(WOneByone);
  123. obo.dialogs = dialogs;
  124. obo.setCallback(()=>{
  125. this.iconTouch.active = true;
  126. node.destroy();
  127. this.ff.setBlockInputCallback(null);
  128. this.ff.pauseSprite(false);
  129. this.ff.mBlockInputEvents.active = false;
  130. });
  131. this.ff.setBlockInputCallback(()=>{
  132. obo.jump();
  133. });
  134. obo._start();
  135. }
  136. private showDialogEnd(){
  137. let dialogs = [
  138. '衣服做好了,快穿上看看吧',
  139. ];
  140. let node = cc.instantiate(this.mMapDialog);
  141. node.group = 'map'
  142. node.zIndex = 9999;
  143. node.x = this.node.x;
  144. node.y = this.node.y + this.node.height;
  145. node.parent = this.ff.mMap.mSprites;
  146. let obo = node.getComponent(WOneByone);
  147. obo.dialogs = dialogs;
  148. obo.setCallback(()=>{
  149. this.iconTouch.active = false;
  150. node.destroy();
  151. this.ff.setBlockInputCallback(null);
  152. this.ff.pauseSprite(false);
  153. this.ff.mBlockInputEvents.active = false;
  154. this.ff.mFFheader.removeTmpGood(this.goodId,this.goodNodes.length);
  155. this.getMapObject(this.node.name);
  156. });
  157. this.ff.setBlockInputCallback(()=>{
  158. obo.jump();
  159. });
  160. obo._start();
  161. }
  162. /**
  163. * 捡起地图上的物品
  164. * @param objectId
  165. */
  166. public getMapObject(objectId:string){
  167. let msg = {
  168. objectId:objectId
  169. }
  170. this.ff.main.gameHttp.sendJson('stage/v1/stageObject',msg,(state,reve:ReveData)=>{
  171. this.ff.main.stopLoad();
  172. if(state == HttpStateType.SUCCESS){
  173. if(reve.retCode == 0){
  174. let player = this.ff.main.player;
  175. let stage = player.stage;
  176. stage.element.push(objectId);
  177. let list = this.ff.main.sManage.getRewards(reve);
  178. this.ff.addGoods(list,this.node.getPosition());
  179. this.iconTouch.active = false;
  180. this.ff.mFFheader.removeTmpGood(this.goodNodes,this.goodNodes.length);
  181. this.node.removeComponent(cc.PhysicsBoxCollider);
  182. }else{
  183. this.ff.main.showTips(reve.message);
  184. }
  185. }else{
  186. this.ff.main.showTips('网络异常');
  187. }
  188. });
  189. }
  190. }