123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- import i18n from "../../../i18n/i18n";
- import { GameViewType } from "../../../main/ViewManage";
- import ViewObject from "../../../main/ViewObject";
- import { HttpStateType, ReveData } from "../../../util/CHttp";
- import GoodItem from "../../common/GoodItem";
- import FFCalAttr from "../../data/FFCalAttr";
- import { __GodCardLevel } from "../../data/sdata/SManage";
- import CardInfoView from "./CardInfoView";
- import CardStarSuccessView from "./CardStarSuccessView";
- import CardAttrItem from "./item/CardAttrItem";
- import CardItem from "./item/CardItem";
- import CardUplevelItem from "./item/CardUplevelItem";
- /**
- * 神像升星
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class CardStarView extends ViewObject {
- public static attrName = ['攻击','防御','气血','敏捷','水','火','风','雷','土'];
- @property(CardItem)
- mCardItem: CardItem = null;
- @property(cc.Node)
- mAttrContent: cc.Node = null;
- @property(cc.Prefab)
- mAttrPrefab: cc.Prefab = null;
- @property(cc.Node)
- mGoodContent: cc.Node = null;
- @property(cc.Prefab)
- mGoodItemPrefab: cc.Prefab = null;
- @property([CardUplevelItem])
- mUpLevelItem: Array<CardUplevelItem> = [];
- @property(cc.Node)
- mFullStar: cc.Node = null;//满星显示
- @property(cc.Node)
- mFullContent: cc.Node = null;
- @property(cc.Node)
- mFinish: cc.Node = null;//所有操作完成后显示
- @property(cc.Label)
- mBtName: cc.Label = null;
- private upStatus = 0;
- public cardInfoView:CardInfoView
- private tempStar = 0;
- public exitDistroy(){
- super.exitDistroy()
- this.cardInfoView.flushRadarChart()
- }
- public init(cardInfoView:CardInfoView){
- this.cardInfoView = cardInfoView
- let attrValues = [0,0,0,0,0,0,0,0,0]
- let _godCard = cardInfoView.cardItem._godCard
- if(_godCard.godReborn){
- let _godReborn = _godCard.godReborn
- if(_godReborn){
- attrValues = [_godReborn.atk,_godReborn.def,_godReborn.hp,
- _godReborn.sp,_godReborn.water,_godReborn.fire,
- _godReborn.wind,_godReborn.thunder,_godReborn.earth]
- }
- }
- for (let i = 0; i < attrValues.length; i++) {
- let v1 = attrValues[i];
- if(v1 > 0){
- let node = cc.instantiate(this.mAttrPrefab)
- node.parent = this.mFullContent
- let cardAttrItem:CardAttrItem = node.getComponent(CardAttrItem)
-
- let jobStr = ''
- if(i < 4){
- let job = ['','射手','法师','战士']
- jobStr = job[_godCard.job]
- }
- cardAttrItem.init(jobStr+CardStarView.attrName[i],v1,0)
- }
- }
- this.mFullStar.active = false;
- this.flushView()
- }
- public flushView(){
- let cardItem:CardItem = this.cardInfoView.cardItem
- let star = this.mCardItem.init(this.main,cardItem.godCardAttr)
- let isUpdateView = true
- if(this.tempStar == 0){
- this.tempStar = star
- }else{
- if(this.tempStar != star){
- isUpdateView = false
- this.tempStar = star
- this.showSuccess(()=>{
- this.updateView()
- })
- }
- }
- if(isUpdateView){
- this.updateView()
- }
- }
- private updateView(){
- let cardItem:CardItem = this.cardInfoView.cardItem
- let fAttr = FFCalAttr.getGodCardAttr(this.main,cardItem.godCardAttr)
- let _godCardLevel:__GodCardLevel = cardItem._godCard.list[cardItem.godCardAttr.level]//下一级属性
- let _godCardLevel1:__GodCardLevel = null//当前属性
- if(cardItem.godCardAttr.level > 0){
- _godCardLevel1 = cardItem._godCard.list[cardItem.godCardAttr.level - 1]
- }
-
- let attrValues = [fAttr.atk,fAttr.def,fAttr.hp,fAttr.sp,fAttr.water,
- fAttr.fire,fAttr.wind,fAttr.thunder,fAttr.earth]
- let attrValues1 = [0,0,0,0,0,0,0,0,0]
- let attrValues2 = [0,0,0,0,0,0,0,0,0]
- if(_godCardLevel){
- attrValues1 = [_godCardLevel.atk,_godCardLevel.def,_godCardLevel.hp,
- _godCardLevel.sp,_godCardLevel.water,_godCardLevel.fire,
- _godCardLevel.wind,_godCardLevel.thunder,_godCardLevel.earth]
- }
- if(_godCardLevel1){
- attrValues2 = [_godCardLevel1.atk,_godCardLevel1.def,_godCardLevel1.hp,
- _godCardLevel1.sp,_godCardLevel1.water,_godCardLevel1.fire,
- _godCardLevel1.wind,_godCardLevel1.thunder,_godCardLevel1.earth]
- }
- this.mAttrContent.destroyAllChildren()
- for (let i = 0; i < attrValues.length; i++) {
- let v1 = attrValues[i];
- let v2 = attrValues1[i] - attrValues2[i]
- if(v1 > 0 || v2 > 0){
- let node = cc.instantiate(this.mAttrPrefab)
- node.parent = this.mAttrContent
- let cardAttrItem:CardAttrItem = node.getComponent(CardAttrItem)
- let jobStr = ''
- if(i < 4){
- let job = ['','射手','法师','战士']
- jobStr = job[cardItem._godCard.job]
- }
- cardAttrItem.init(jobStr+CardStarView.attrName[i],v1,v2)
- }
- }
- let goods = []
- if(_godCardLevel){
- if(_godCardLevel.goodId1 > 0){
- goods.push({
- id:_godCardLevel.goodId1,
- count:_godCardLevel.goodCount1
- })
- }
-
- if(_godCardLevel.goodId2 > 0){
- goods.push({
- id:_godCardLevel.goodId2,
- count:_godCardLevel.goodCount2
- })
- }
- if(_godCardLevel.goodId3 > 0){
- goods.push({
- id:_godCardLevel.goodId3,
- count:_godCardLevel.goodCount3
- })
- }
- this.mFullStar.active = false
- this.mBtName.string = i18n.t('升星')
- this.upStatus = 0
- }else{
- this.upStatus = 1
- this.mBtName.string = i18n.t('重塑')
- this.mFullStar.active = true
- let _godCard = this.cardInfoView.cardItem._godCard
- let _godReborn = _godCard.godReborn
- if(_godReborn.goodId1 > 0){
- goods.push({
- id:_godReborn.goodId1,
- count:_godReborn.goodCount1
- })
- }
-
- if(_godReborn.goodId2 > 0){
- goods.push({
- id:_godReborn.goodId2,
- count:_godReborn.goodCount2
- })
- }
- if(this.cardInfoView.cardItem.godCardAttr.reborn > 0){
- this.mFinish.active = false
- }
- }
- this.mGoodContent.destroyAllChildren()
- for (let i = 0; i < goods.length; i++) {
- const element = goods[i];
- let node = cc.instantiate(this.mGoodItemPrefab)
- let goodItem = node.getComponent(GoodItem)
- goodItem.initContrast(this.main,element)
- node.parent = this.mGoodContent
- }
-
- this.flushTree()
- }
- private flushTree(){
- let _godCard = this.cardInfoView.cardItem._godCard
- let tree = []
- let _cardLevels = _godCard.list
- let tmpId = 0;
- let tmpList = []
- for (let i = 0; i < _cardLevels.length; i++) {
- const element = _cardLevels[i];
- if(tmpId == 0){
- tmpId = element.star
- tmpList.push(element)
- }else if(tmpId != element.star){
- tmpId = element.star
- let list = tmpList.slice()
- tree.push(list)
- tmpList = []
- tmpList.push(element)
- }else{
- tmpList.push(element)
- }
- }
- tree.push(tmpList)
- let godCardAttr = this.cardInfoView.cardItem.godCardAttr
- let _godCardLevel = _godCard.list[godCardAttr.level]
- if(_godCardLevel){
- let myStar = _godCardLevel.star
- let myList = tree[myStar - 1]
-
- let tmpData = this.getTmpLevel(_godCardLevel,myList)
-
- for (let i = 0; i < 6; i++) {
- const element = this.mUpLevelItem[i];
- if(i > tmpData.index){
- element.setLock()
- }else if(i == tmpData.index){
- element.setLabel(tmpData.level,tmpData.maxLevel)
- }else{
- element.setLabel(tmpData.maxLevel,tmpData.maxLevel)
- }
- }
- }
- }
- /**
- * 获取在某个节点上的等级
- * @param _godCardLevel
- * @param list
- */
- private getTmpLevel(_godCardLevel:__GodCardLevel,list:Array<__GodCardLevel>){
- let maxLevel = (list.length - 1)/5;//当前最大等级
- if(_godCardLevel == list[list.length - 1]){//如果是最后一个,不会分数升级
- return {
- index:5,//当前所在位置
- level:0,//当前所在位置等级
- maxLevel:maxLevel//最高等级
- }
- }
- let level = 0;
- for (let i = 0; i < list.length - 1; i++) {
- const element = list[i];
- if(_godCardLevel == element){
- return {
- index:element.attrType - 1,//当前所在位置
- level:level,//当前所在位置等级
- maxLevel:maxLevel//最高等级
- }
- }
- level ++
- if(level >= maxLevel){
- level = 0
- }
- }
- }
- /**
- * 升星
- */
- public onclickStar(){
- let action = ''
- if(this.upStatus == 0){
- action = 'card/v1/uplevel'
- }else{
- action = 'card/v1/reborn'
- }
- let cardItem = this.cardInfoView.cardItem
- let msg = {
- id:cardItem.godCardAttr.id
- }
- this.main.gameHttp.sendJson(action,msg,(state,reve:ReveData)=>{
- this.main.stopLoad();
- if(state == HttpStateType.SUCCESS){
- if(reve.retCode == 0){
- if(this.upStatus == 0){
- cardItem.godCardAttr.level += 1
- }else{
- cardItem.godCardAttr.reborn += 1
- }
- this.flushView()
- }else{
- this.main.showTips(reve.message);
- }
- }else{
- this.main.showTips('网络异常');
- }
- });
- }
- /**
- * 显示进阶成功
- */
- public showSuccess(callback:()=>void){
- let count = 0
- this.schedule(()=>{
- count += 0.1
- this.mUpLevelItem[5].mProgessBar.progress = count
- if(count > 1){
- this.main.viewManage.loadFunc(GameViewType.god_card_star_success,(viewObject:ViewObject)=>{
- let cardInfoView = viewObject as CardStarSuccessView
- cardInfoView.init(this.cardInfoView.cardItem)
-
- viewObject.show();
- });
- callback()
- }
- },0.1,10)
- }
- }
|