CardStarView.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 GoodItem from "../../common/GoodItem";
  6. import FFCalAttr from "../../data/FFCalAttr";
  7. import { __GodCardLevel } from "../../data/sdata/SManage";
  8. import CardInfoView from "./CardInfoView";
  9. import CardStarSuccessView from "./CardStarSuccessView";
  10. import CardAttrItem from "./item/CardAttrItem";
  11. import CardItem from "./item/CardItem";
  12. import CardUplevelItem from "./item/CardUplevelItem";
  13. /**
  14. * 神像升星
  15. */
  16. const { ccclass, property } = cc._decorator;
  17. @ccclass
  18. export default class CardStarView extends ViewObject {
  19. public static attrName = ['攻击','防御','气血','敏捷','水','火','风','雷','土'];
  20. @property(CardItem)
  21. mCardItem: CardItem = null;
  22. @property(cc.Node)
  23. mAttrContent: cc.Node = null;
  24. @property(cc.Prefab)
  25. mAttrPrefab: cc.Prefab = null;
  26. @property(cc.Node)
  27. mGoodContent: cc.Node = null;
  28. @property(cc.Prefab)
  29. mGoodItemPrefab: cc.Prefab = null;
  30. @property([CardUplevelItem])
  31. mUpLevelItem: Array<CardUplevelItem> = [];
  32. @property(cc.Node)
  33. mFullStar: cc.Node = null;//满星显示
  34. @property(cc.Node)
  35. mFullContent: cc.Node = null;
  36. @property(cc.Node)
  37. mFinish: cc.Node = null;//所有操作完成后显示
  38. @property(cc.Label)
  39. mBtName: cc.Label = null;
  40. private upStatus = 0;
  41. public cardInfoView:CardInfoView
  42. private tempStar = 0;
  43. public exitDistroy(){
  44. super.exitDistroy()
  45. this.cardInfoView.flushRadarChart()
  46. }
  47. public init(cardInfoView:CardInfoView){
  48. this.cardInfoView = cardInfoView
  49. let attrValues = [0,0,0,0,0,0,0,0,0]
  50. let _godCard = cardInfoView.cardItem._godCard
  51. if(_godCard.godReborn){
  52. let _godReborn = _godCard.godReborn
  53. if(_godReborn){
  54. attrValues = [_godReborn.atk,_godReborn.def,_godReborn.hp,
  55. _godReborn.sp,_godReborn.water,_godReborn.fire,
  56. _godReborn.wind,_godReborn.thunder,_godReborn.earth]
  57. }
  58. }
  59. for (let i = 0; i < attrValues.length; i++) {
  60. let v1 = attrValues[i];
  61. if(v1 > 0){
  62. let node = cc.instantiate(this.mAttrPrefab)
  63. node.parent = this.mFullContent
  64. let cardAttrItem:CardAttrItem = node.getComponent(CardAttrItem)
  65. let jobStr = ''
  66. if(i < 4){
  67. let job = ['','射手','法师','战士']
  68. jobStr = job[_godCard.job]
  69. }
  70. cardAttrItem.init(jobStr+CardStarView.attrName[i],v1,0)
  71. }
  72. }
  73. this.mFullStar.active = false;
  74. this.flushView()
  75. }
  76. public flushView(){
  77. let cardItem:CardItem = this.cardInfoView.cardItem
  78. let star = this.mCardItem.init(this.main,cardItem.godCardAttr)
  79. let isUpdateView = true
  80. if(this.tempStar == 0){
  81. this.tempStar = star
  82. }else{
  83. if(this.tempStar != star){
  84. isUpdateView = false
  85. this.tempStar = star
  86. this.showSuccess(()=>{
  87. this.updateView()
  88. })
  89. }
  90. }
  91. if(isUpdateView){
  92. this.updateView()
  93. }
  94. }
  95. private updateView(){
  96. let cardItem:CardItem = this.cardInfoView.cardItem
  97. let fAttr = FFCalAttr.getGodCardAttr(this.main,cardItem.godCardAttr)
  98. let _godCardLevel:__GodCardLevel = cardItem._godCard.list[cardItem.godCardAttr.level]//下一级属性
  99. let _godCardLevel1:__GodCardLevel = null//当前属性
  100. if(cardItem.godCardAttr.level > 0){
  101. _godCardLevel1 = cardItem._godCard.list[cardItem.godCardAttr.level - 1]
  102. }
  103. let attrValues = [fAttr.atk,fAttr.def,fAttr.hp,fAttr.sp,fAttr.water,
  104. fAttr.fire,fAttr.wind,fAttr.thunder,fAttr.earth]
  105. let attrValues1 = [0,0,0,0,0,0,0,0,0]
  106. let attrValues2 = [0,0,0,0,0,0,0,0,0]
  107. if(_godCardLevel){
  108. attrValues1 = [_godCardLevel.atk,_godCardLevel.def,_godCardLevel.hp,
  109. _godCardLevel.sp,_godCardLevel.water,_godCardLevel.fire,
  110. _godCardLevel.wind,_godCardLevel.thunder,_godCardLevel.earth]
  111. }
  112. if(_godCardLevel1){
  113. attrValues2 = [_godCardLevel1.atk,_godCardLevel1.def,_godCardLevel1.hp,
  114. _godCardLevel1.sp,_godCardLevel1.water,_godCardLevel1.fire,
  115. _godCardLevel1.wind,_godCardLevel1.thunder,_godCardLevel1.earth]
  116. }
  117. this.mAttrContent.destroyAllChildren()
  118. for (let i = 0; i < attrValues.length; i++) {
  119. let v1 = attrValues[i];
  120. let v2 = attrValues1[i] - attrValues2[i]
  121. if(v1 > 0 || v2 > 0){
  122. let node = cc.instantiate(this.mAttrPrefab)
  123. node.parent = this.mAttrContent
  124. let cardAttrItem:CardAttrItem = node.getComponent(CardAttrItem)
  125. let jobStr = ''
  126. if(i < 4){
  127. let job = ['','射手','法师','战士']
  128. jobStr = job[cardItem._godCard.job]
  129. }
  130. cardAttrItem.init(jobStr+CardStarView.attrName[i],v1,v2)
  131. }
  132. }
  133. let goods = []
  134. if(_godCardLevel){
  135. if(_godCardLevel.goodId1 > 0){
  136. goods.push({
  137. id:_godCardLevel.goodId1,
  138. count:_godCardLevel.goodCount1
  139. })
  140. }
  141. if(_godCardLevel.goodId2 > 0){
  142. goods.push({
  143. id:_godCardLevel.goodId2,
  144. count:_godCardLevel.goodCount2
  145. })
  146. }
  147. if(_godCardLevel.goodId3 > 0){
  148. goods.push({
  149. id:_godCardLevel.goodId3,
  150. count:_godCardLevel.goodCount3
  151. })
  152. }
  153. this.mFullStar.active = false
  154. this.mBtName.string = i18n.t('升星')
  155. this.upStatus = 0
  156. }else{
  157. this.upStatus = 1
  158. this.mBtName.string = i18n.t('重塑')
  159. this.mFullStar.active = true
  160. let _godCard = this.cardInfoView.cardItem._godCard
  161. let _godReborn = _godCard.godReborn
  162. if(_godReborn.goodId1 > 0){
  163. goods.push({
  164. id:_godReborn.goodId1,
  165. count:_godReborn.goodCount1
  166. })
  167. }
  168. if(_godReborn.goodId2 > 0){
  169. goods.push({
  170. id:_godReborn.goodId2,
  171. count:_godReborn.goodCount2
  172. })
  173. }
  174. if(this.cardInfoView.cardItem.godCardAttr.reborn > 0){
  175. this.mFinish.active = false
  176. }
  177. }
  178. this.mGoodContent.destroyAllChildren()
  179. for (let i = 0; i < goods.length; i++) {
  180. const element = goods[i];
  181. let node = cc.instantiate(this.mGoodItemPrefab)
  182. let goodItem = node.getComponent(GoodItem)
  183. goodItem.initContrast(this.main,element)
  184. node.parent = this.mGoodContent
  185. }
  186. this.flushTree()
  187. }
  188. private flushTree(){
  189. let _godCard = this.cardInfoView.cardItem._godCard
  190. let tree = []
  191. let _cardLevels = _godCard.list
  192. let tmpId = 0;
  193. let tmpList = []
  194. for (let i = 0; i < _cardLevels.length; i++) {
  195. const element = _cardLevels[i];
  196. if(tmpId == 0){
  197. tmpId = element.star
  198. tmpList.push(element)
  199. }else if(tmpId != element.star){
  200. tmpId = element.star
  201. let list = tmpList.slice()
  202. tree.push(list)
  203. tmpList = []
  204. tmpList.push(element)
  205. }else{
  206. tmpList.push(element)
  207. }
  208. }
  209. tree.push(tmpList)
  210. let godCardAttr = this.cardInfoView.cardItem.godCardAttr
  211. let _godCardLevel = _godCard.list[godCardAttr.level]
  212. if(_godCardLevel){
  213. let myStar = _godCardLevel.star
  214. let myList = tree[myStar - 1]
  215. let tmpData = this.getTmpLevel(_godCardLevel,myList)
  216. for (let i = 0; i < 6; i++) {
  217. const element = this.mUpLevelItem[i];
  218. if(i > tmpData.index){
  219. element.setLock()
  220. }else if(i == tmpData.index){
  221. element.setLabel(tmpData.level,tmpData.maxLevel)
  222. }else{
  223. element.setLabel(tmpData.maxLevel,tmpData.maxLevel)
  224. }
  225. }
  226. }
  227. }
  228. /**
  229. * 获取在某个节点上的等级
  230. * @param _godCardLevel
  231. * @param list
  232. */
  233. private getTmpLevel(_godCardLevel:__GodCardLevel,list:Array<__GodCardLevel>){
  234. let maxLevel = (list.length - 1)/5;//当前最大等级
  235. if(_godCardLevel == list[list.length - 1]){//如果是最后一个,不会分数升级
  236. return {
  237. index:5,//当前所在位置
  238. level:0,//当前所在位置等级
  239. maxLevel:maxLevel//最高等级
  240. }
  241. }
  242. let level = 0;
  243. for (let i = 0; i < list.length - 1; i++) {
  244. const element = list[i];
  245. if(_godCardLevel == element){
  246. return {
  247. index:element.attrType - 1,//当前所在位置
  248. level:level,//当前所在位置等级
  249. maxLevel:maxLevel//最高等级
  250. }
  251. }
  252. level ++
  253. if(level >= maxLevel){
  254. level = 0
  255. }
  256. }
  257. }
  258. /**
  259. * 升星
  260. */
  261. public onclickStar(){
  262. let action = ''
  263. if(this.upStatus == 0){
  264. action = 'card/v1/uplevel'
  265. }else{
  266. action = 'card/v1/reborn'
  267. }
  268. let cardItem = this.cardInfoView.cardItem
  269. let msg = {
  270. id:cardItem.godCardAttr.id
  271. }
  272. this.main.gameHttp.sendJson(action,msg,(state,reve:ReveData)=>{
  273. this.main.stopLoad();
  274. if(state == HttpStateType.SUCCESS){
  275. if(reve.retCode == 0){
  276. if(this.upStatus == 0){
  277. cardItem.godCardAttr.level += 1
  278. }else{
  279. cardItem.godCardAttr.reborn += 1
  280. }
  281. this.flushView()
  282. }else{
  283. this.main.showTips(reve.message);
  284. }
  285. }else{
  286. this.main.showTips('网络异常');
  287. }
  288. });
  289. }
  290. /**
  291. * 显示进阶成功
  292. */
  293. public showSuccess(callback:()=>void){
  294. let count = 0
  295. this.schedule(()=>{
  296. count += 0.1
  297. this.mUpLevelItem[5].mProgessBar.progress = count
  298. if(count > 1){
  299. this.main.viewManage.loadFunc(GameViewType.god_card_star_success,(viewObject:ViewObject)=>{
  300. let cardInfoView = viewObject as CardStarSuccessView
  301. cardInfoView.init(this.cardInfoView.cardItem)
  302. viewObject.show();
  303. });
  304. callback()
  305. }
  306. },0.1,10)
  307. }
  308. }