SetLeader.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { HttpStateType, ReveData } from "../../../util/CHttp";
  2. import PetIcon from "../../common/PetIcon";
  3. import Equip from "./Equip";
  4. /**
  5. * 设置队长
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class SetLeader extends cc.Component {
  10. @property(cc.Node)
  11. mSetButton: cc.Node = null;//设置的按钮
  12. private equip:Equip = null
  13. public onLoad(){
  14. this.equip = this.node.getComponent(Equip)
  15. }
  16. public start(){
  17. this.flushLeader()
  18. }
  19. public flushLeader(){
  20. let main = this.equip.main
  21. let player = main.player
  22. let petListNode = this.equip.mPetList
  23. let nodes = petListNode.children
  24. for (let i = 0; i < nodes.length; i++) {
  25. let node = nodes[i];
  26. let petIcon = node.getComponent(PetIcon)
  27. if(petIcon.id == player.role.leader){
  28. petIcon.mLeaderIcon.active = true
  29. }else{
  30. petIcon.mLeaderIcon.active = false
  31. }
  32. }
  33. }
  34. /**
  35. * 设置队长
  36. */
  37. public onclickSetLeader(){
  38. let main = this.equip.main
  39. let msg = {
  40. leader:this.equip.curPi.id
  41. }
  42. main.gameHttp.sendJson('set/v1/leader',msg,(state,reve:ReveData)=>{
  43. main.stopLoad();
  44. if(state == HttpStateType.SUCCESS){
  45. if(reve.retCode == 0){
  46. main.player.role.leader = msg.leader
  47. this.flushLeader()
  48. main.showTips('设置成功');
  49. }else{
  50. main.showTips(reve.message);
  51. }
  52. }else{
  53. main.showTips('网络异常');
  54. }
  55. });
  56. }
  57. }