Equip.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. import i18n from "../../../i18n/i18n";
  2. import { GameViewType } from "../../../main/ViewManage";
  3. import ViewObject from "../../../main/ViewObject";
  4. import { HttpStateType, ReveData } from "../../../util/CHttp";
  5. import GoodAbout from "../../common/GoodAbout";
  6. import GoodItem from "../../common/GoodItem";
  7. import PetIcon from "../../common/PetIcon";
  8. import FFCalAttr, { FFAttr } from "../../data/FFCalAttr";
  9. import RedPoint from "../../data/RedPoint";
  10. import ChangeEquip from "./ChangeEquip";
  11. import EquipItem from "./EquipItem";
  12. import EquipPack from "./EquipPack";
  13. import EquipQH from "./EquipQH";
  14. import PetInfo from "./PetInfo";
  15. /**
  16. * 宠物装备查看界面
  17. */
  18. const { ccclass, property } = cc._decorator;
  19. @ccclass
  20. export default class Equip extends ViewObject {
  21. @property(cc.Node)
  22. mPetList: cc.Node = null;//宠物列表父节点
  23. @property(cc.Prefab)
  24. mPetPrefab: cc.Prefab = null;//宠物头像
  25. @property(cc.Node)
  26. mModel: cc.Node = null;//宠物模型显示的位置
  27. @property([EquipItem])
  28. mEquips: Array<EquipItem> = [];//6件装备
  29. @property(cc.Prefab)
  30. mEquipPrefab: cc.Prefab = null;
  31. @property(cc.Label)
  32. mZdl: cc.Label = null;
  33. @property(cc.Label)
  34. mAtk: cc.Label = null;
  35. @property(cc.Label)
  36. mDef: cc.Label = null;
  37. @property(cc.Label)
  38. mHp: cc.Label = null;
  39. @property(cc.Label)
  40. mPagSize: cc.Label = null;//背包容量
  41. @property(cc.Label)
  42. mSp: cc.Label = null;
  43. @property(EquipPack)
  44. mEquipPack: EquipPack = null;//装备背包
  45. @property(cc.Node)
  46. mBtExit: cc.Node = null;//退出按钮
  47. public curPi: PetIcon;
  48. public curPage: number = 1;
  49. public inGuide = false;//是否引导中
  50. public guideStep: number = 0; //指引步骤
  51. /**
  52. * 打开伙伴的id
  53. * -1 打开默认的
  54. */
  55. public openId = -1;
  56. public httpEvent(reveData: ReveData) {
  57. let data = reveData.data;
  58. if (data._equip != undefined) {
  59. this.mEquipPack.setEquipType(this.curPage);
  60. }
  61. }
  62. public onLoad() {
  63. let player = this.main.player;
  64. let petMap = player.pet;
  65. let zdl = 0
  66. for (const id in petMap) {
  67. let pet = petMap[id];
  68. let node = cc.instantiate(this.mPetPrefab);
  69. let petIcon = node.getComponent(PetIcon);
  70. petIcon.id = parseInt(id);
  71. petIcon.data = pet;
  72. let ffAttr = FFCalAttr.getAttr(this.main, petIcon.data);
  73. petIcon.flushIcon(ffAttr)
  74. node.parent = this.mPetList;
  75. petIcon.setCallback((pi: PetIcon) => {
  76. this.checkPet(pi);
  77. });
  78. zdl += ffAttr.zdl
  79. }
  80. let msg = {
  81. zdl: zdl,
  82. }
  83. this.main.gameHttp.sendJson('role/v1/zdl', msg, (state, reve: ReveData) => {
  84. });
  85. }
  86. public setCloseCallback(callback: () => void) {
  87. this.closeCallback = callback
  88. }
  89. public start() {
  90. let nodes = this.mPetList.children;
  91. for (let i = 0; i < nodes.length; i++) {
  92. const element = nodes[i];
  93. let petIcon = element.getComponent(PetIcon);
  94. if (this.openId == -1) {
  95. this.openId = petIcon.data.id
  96. }
  97. if (petIcon.data.id == this.openId) {
  98. petIcon.onclick();
  99. } else {
  100. if (RedPoint.petRedPoint(this.main, petIcon.data)) {
  101. RedPoint.addRed(this.main, element)
  102. } else {
  103. RedPoint.removeRed(element)
  104. }
  105. }
  106. }
  107. if (this.inGuide) {
  108. if (this.guideStep == 0) {
  109. this.onGuide()
  110. } else if (this.guideStep == 1) {
  111. this.onGuide_1();
  112. }
  113. }
  114. }
  115. public flushPagSize() {
  116. let equipPag = this.main.player.equip;
  117. this.mPagSize.string = i18n.t('背包容量') + ':' + equipPag.length + '/500';
  118. }
  119. public checkPet(pi: PetIcon) {
  120. this.flushPagSize()
  121. this.curPi = pi;
  122. let sManage = this.main.sManage;
  123. let pet = sManage.getRoleById(pi.id);
  124. this.mModel.destroyAllChildren();
  125. let ffAttr = FFCalAttr.getAttr(this.main, pi.data);
  126. cc.resources.load('prefab/role/' + pet.act, cc.Prefab, (err, prefab: cc.Prefab) => {
  127. if (err) {
  128. cc.error(err);
  129. } else {
  130. let node = cc.instantiate(prefab);
  131. node.parent = this.mModel;
  132. let spriteNode = node.getChildByName('juese01');
  133. let spineNode0 = spriteNode.getChildByName('spineRight');
  134. let spine = spineNode0.getComponent(sp.Skeleton);
  135. let mWeapon1: sp.spine.Bone = spine.findBone('control');
  136. if (mWeapon1) {
  137. mWeapon1.data.rotation = 0;
  138. mWeapon1.rotation = 0;
  139. }
  140. let smoke = spriteNode.children[0]
  141. smoke.active = false
  142. // spine.setSkin(ffAttr.skin)
  143. // Equip.chaneWeapon(spine, ffAttr.weapon)
  144. }
  145. });
  146. for (let i = 0; i < this.mEquips.length; i++) {
  147. const element = this.mEquips[i];
  148. element.setNull();
  149. element.setCallback(() => {
  150. this.mEquipPack.setEquipType(i + 1);
  151. })
  152. }
  153. this.flushEquip(pi);
  154. this.flushAttr(ffAttr)
  155. pi.flushIcon(ffAttr)
  156. }
  157. /**
  158. * 切换武器
  159. * @param spine
  160. * @param attrName
  161. */
  162. public static chaneWeapon(skeleton, attrName: string) {
  163. return
  164. let slotName1 = '1';
  165. let slotName2 = '2';
  166. let targetSkinName = 'default';
  167. let targetAttaName1 = attrName + '/1';
  168. let targetAttaName2 = attrName + '/2';
  169. const skeletonData = skeleton.skeletonData.getRuntimeData();
  170. const skin = skeletonData.findSkin(targetSkinName);
  171. let slot1: sp.spine.Slot = skeleton.findSlot(slotName1);
  172. let slot2: sp.spine.Slot = skeleton.findSlot(slotName2);
  173. const slotIndex1 = skeletonData.findSlotIndex(slotName1);
  174. const atta1 = skin.getAttachment(slotIndex1, targetAttaName1);
  175. const slotIndex2 = skeletonData.findSlotIndex(slotName2);
  176. const atta2 = skin.getAttachment(slotIndex2, targetAttaName2);
  177. if (slot1) {
  178. slot1.setAttachment(atta1);
  179. }
  180. if (slot2) {
  181. slot2.setAttachment(atta2);
  182. }
  183. }
  184. public flushEquip(pi: PetIcon) {
  185. let equips = pi.data.equips;
  186. for (let i = 0; i < equips.length; i++) {
  187. const element = equips[i];
  188. let equipData = this.main.sManage.getEquipById(element.id);
  189. let siteIndex = equipData.type - 1
  190. let mEquip = this.mEquips[siteIndex];
  191. mEquip.initEquip(this.main, element);
  192. mEquip.setCallback((pp: GoodItem) => {
  193. this.openGoodAbout(pp);
  194. });
  195. }
  196. this.mEquipPack.init(pi);
  197. }
  198. public flushAttr(ffAttr: FFAttr) {
  199. this.mZdl.string = '' + ffAttr.zdl
  200. this.mAtk.string = '' + ffAttr.atk;
  201. this.mDef.string = '' + ffAttr.def;
  202. this.mHp.string = '' + ffAttr.hp;
  203. this.mSp.string = '' + ffAttr.sp;
  204. }
  205. /**
  206. * 打开详细说明
  207. */
  208. public openInfo() {
  209. this.main.viewManage.loadFunc(GameViewType.petInfo, (viewObject: ViewObject) => {
  210. let petInfo = viewObject as PetInfo;
  211. petInfo.init(this.curPi)
  212. viewObject.show();
  213. });
  214. }
  215. /**
  216. * 打开换装界面
  217. * @param equipItem
  218. */
  219. public openChangeEquip(equipItem: GoodItem) {
  220. this.main.viewManage.loadFunc(GameViewType.changeEquip, (viewObject: ViewObject) => {
  221. let changeEquip = viewObject as ChangeEquip;
  222. changeEquip.equip = this
  223. let type = equipItem.equipData.type
  224. changeEquip.inGuide = this.inGuide
  225. changeEquip.guideStep = this.guideStep;
  226. this.inGuide = false
  227. changeEquip.init(this.curPi, equipItem, this.mEquips[type - 1]);
  228. viewObject.show();
  229. });
  230. }
  231. /**
  232. * 查看物品
  233. * @param goodItem
  234. */
  235. private openGoodAbout(goodItem: GoodItem) {
  236. this.main.viewManage.loadFunc(GameViewType.goodAbout, (viewObject: ViewObject) => {
  237. let goodAbout = viewObject as GoodAbout;
  238. goodAbout.inGuide = this.inGuide;
  239. goodAbout.guideStep = this.guideStep;
  240. goodAbout.init(goodItem)
  241. viewObject.show();
  242. goodAbout.setQHCallback((gdItem: GoodItem) => {
  243. goodAbout.exitDistroy()
  244. this.openIntensifyEquip(gdItem)
  245. })
  246. if (goodItem.equipData.type == 5) {//服装可以卸下
  247. goodAbout.mUnInstallNode.active = true
  248. goodAbout.setUnCallback((gdItem: GoodItem) => {
  249. goodAbout.exitDistroy()
  250. this.uninstallEquip(gdItem)
  251. })
  252. }
  253. });
  254. }
  255. /**
  256. * 装备强化
  257. */
  258. public openIntensifyEquip(goodItem: GoodItem) {
  259. this.main.viewManage.loadFunc(GameViewType.IntensifyEquip, (viewObject: ViewObject) => {
  260. let equipQH: EquipQH = viewObject as EquipQH;
  261. equipQH.inGuide = this.inGuide;
  262. equipQH.guideStep = this.guideStep;
  263. equipQH.init(goodItem.equip, this.curPi, this)
  264. viewObject.show();
  265. if (this.inGuide) {
  266. if (this.guideStep == 1) {
  267. equipQH.setCloseCallback(() => {
  268. this.onGuideExit();
  269. })
  270. }
  271. }
  272. });
  273. }
  274. private uninstallEquip(goodItem: GoodItem) {
  275. let msg = {
  276. petId: this.curPi.id,
  277. equipId: goodItem.equip.id,
  278. }
  279. this.main.gameHttp.sendJson('equip/v1/uninstall', msg, (state, reve: ReveData) => {
  280. this.main.stopLoad();
  281. if (state == HttpStateType.SUCCESS) {
  282. if (reve.retCode == 0) {
  283. this.checkPet(this.curPi)
  284. } else {
  285. this.main.showTips(reve.message);
  286. }
  287. } else {
  288. this.main.showTips('网络异常');
  289. }
  290. });
  291. }
  292. /**
  293. * 开始引导穿装备
  294. */
  295. private onGuide() {
  296. let guideMask = this.main.mGuideMask
  297. let targetNode = this.mEquipPack.mPagContent.children[0]
  298. guideMask.setTargetNode(targetNode)
  299. guideMask.show()
  300. let equipItem = targetNode.getComponent(GoodItem)
  301. equipItem.inGuide = true
  302. equipItem.setGuideCallback(() => {
  303. guideMask.close()
  304. })
  305. }
  306. /**
  307. * 强化指引
  308. */
  309. private onGuide_1() {
  310. let guideMask = this.main.mGuideMask;
  311. let targetNode = this.mEquips[0].node;
  312. guideMask.setTargetNode(targetNode)
  313. guideMask.show()
  314. let equipItem = targetNode.getComponent(GoodItem)
  315. equipItem.inGuide = true
  316. equipItem.setGuideCallback(() => {
  317. guideMask.close()
  318. })
  319. }
  320. public onGuideExit() {
  321. let guideMask = this.main.mGuideMask
  322. let targetNode = this.mBtExit
  323. guideMask.setTargetNode(targetNode)
  324. guideMask.show()
  325. let closeCallback = this.closeCallback
  326. this.setCloseCallback(() => {
  327. guideMask.close()
  328. if (closeCallback) {
  329. closeCallback()
  330. }
  331. })
  332. }
  333. }