RedPoint.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import Main from "../../main/Main";
  2. import CUtil from "../../util/CUtil";
  3. import FFCalAttr from "./FFCalAttr";
  4. import RedNode from "./RedNode";
  5. import { __EquipData } from "./sdata/SManage";
  6. import { EquipAttr, PetAttr } from "./udata/Player";
  7. /**
  8. * 计算红点
  9. */
  10. export default class RedPoint {
  11. /**
  12. * 角色查看界面是否有红点
  13. * @param main
  14. */
  15. public static petsRedPoint(main: Main):boolean{
  16. let petMap = main.player.pet
  17. for (const id in petMap) {
  18. let pet = petMap[id];
  19. if(RedPoint.petRedPoint(main,pet)){
  20. return true
  21. }
  22. }
  23. return false
  24. }
  25. /**
  26. * 伙伴是否有可使用的装备
  27. * @param main
  28. * @param petAttr
  29. * @returns
  30. */
  31. public static petRedPoint(main: Main, petAttr: PetAttr): boolean {
  32. let equip = main.player.equip
  33. for (let i = 0; i < equip.length; i++) {
  34. const element = equip[i];
  35. if (RedPoint.equipRedPoint(main, element, petAttr)) {
  36. return true
  37. }
  38. }
  39. return false
  40. }
  41. /**
  42. * 装备是否有红点
  43. * @param element
  44. * @param petAttr
  45. * @returns
  46. */
  47. public static equipRedPoint(main: Main, equipAttr: EquipAttr, petAttr: PetAttr): boolean {
  48. //1.判断职业是否符合
  49. let _equipA: __EquipData = main.sManage.getEquipById(equipAttr.id);
  50. if(_equipA.type > 5){//不是装备
  51. return false
  52. }
  53. if(_equipA.occ != 0){//有职业限制
  54. if (_equipA.occ != petAttr.id) {
  55. return false
  56. }
  57. }
  58. let oldEquipAttr = RedPoint.getPetAttr(main, _equipA.type, petAttr)
  59. if (oldEquipAttr == null) {//如果这个位置没有装备
  60. return true
  61. }
  62. let _equipB: __EquipData = main.sManage.getEquipById(oldEquipAttr.id);
  63. let ffData1 = FFCalAttr.getEquipAttr(main, equipAttr, _equipA)
  64. let ffData2 = FFCalAttr.getEquipAttr(main, oldEquipAttr, _equipB)
  65. return ffData1.zdl > ffData2.zdl
  66. }
  67. /**
  68. *
  69. * @param equipAttr
  70. * @param petAttr
  71. * @returns 伙伴穿的相同类型的装备
  72. */
  73. public static getPetAttr(main: Main, type: number, petAttr: PetAttr): EquipAttr {
  74. let petEquips = petAttr.equips
  75. for (let i = 0; i < petEquips.length; i++) {
  76. const element = petEquips[i];
  77. let _equipB: __EquipData = main.sManage.getEquipById(element.id);
  78. if (type == _equipB.type) {
  79. return element
  80. }
  81. }
  82. return null;
  83. }
  84. /**
  85. *
  86. * @param pNode
  87. * @param force 是否强制添加红点
  88. */
  89. public static addRed(main:Main,pNode: cc.Node, force?: boolean,lr?:boolean) {
  90. let node = pNode.getChildByName('redpoint');
  91. if(node){
  92. if(!node.active){
  93. if(force){
  94. node.active = true;
  95. }else{
  96. let nowTime = CUtil.getNowTime();
  97. let redNode = node.getComponent(RedNode);
  98. if(nowTime - redNode.time > 600){
  99. node.active = true;
  100. }
  101. }
  102. }
  103. return;
  104. }
  105. node = new cc.Node('redpoint');
  106. let sprite = node.addComponent(cc.Sprite);
  107. sprite.spriteFrame = main.RED_POINT;
  108. node.addComponent(RedNode);
  109. node.parent = pNode;
  110. let rect = main.RED_POINT.getRect();
  111. if(lr){
  112. node.x = -(pNode.width - rect.width) / 2;
  113. node.y = (pNode.height - rect.height) / 2;
  114. }else{
  115. node.x = (pNode.width - rect.width) / 2;
  116. node.y = (pNode.height - rect.height) / 2;
  117. }
  118. }
  119. public static removeRed(pNode: cc.Node) {
  120. let node = pNode.getChildByName('redpoint');
  121. if (node) {
  122. node.active = false;
  123. let redNode = node.getComponent(RedNode);
  124. redNode.time = CUtil.getNowTime();
  125. }
  126. }
  127. }