SamsaraGame/assets/Script/ts/panel/AppraisalResult.ts
2025-04-24 17:03:28 +08:00

513 lines
19 KiB
TypeScript

import PopupManager from "../../ts/gear_2.3.4/manager/PopupManager";
import ItemUtil from "../../ts/core/ItemUtil";
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
import GameUtil from "../../ts/core/GameUtil";
import GameModel from "../../ts/core/GameModel";
import SkillUtil from "../../ts/game/skill/core/SkillUtil";
import MsgAlert from "../../ts/game/msg/MsgAlert";
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
moveNode: cc.Node = null;
@property(cc.Label)
baldricName: cc.Label = null;
@property(cc.Sprite)
baldricIcon: cc.Sprite = null;
@property(cc.Node)
skillContent1: cc.Node = null;
@property(cc.Node)
skillContent2: cc.Node = null;
@property(cc.Prefab)
baseAtt: cc.Prefab = null;
@property(cc.Prefab)
skillPrefab: cc.Prefab = null;
baldricInfo: any = null;
attrsInfo: any = null;
skillLevelList: any = null;
currentIdx: number = 0;
direction: number = 1;
canClose: Boolean = false;
// 技能滾動動畫時間屬性
blinkDelay: number = 0.15;
halfRollDuration: number = 0.2;
hideDelay: number = 0.08;//漸隱延遲時間
hideDuration: number = 0.12;//漸隱持續時間
showDuration: number = 0.12;//漸顯持續時間
halfMoveDis: number = 75;
moveDis: number = 150;
skip: boolean = true;//跳過動畫
onLoad() {
cc.tween(this.moveNode)
.by(0, { y: -100 })
.by(0.3, { y: 100 })
.call(() => {
this.loadFlashOfLightAni();
if (this.skip)
this.fastShow()
else
this.loadBaseAtts()
})
.start()
}
// 加載佩飾圖片和名稱
loadBaldricInfo(info, data, skip: boolean = true) {
this.skip = skip
this.baldricInfo = info;
var iconId = ItemUtil.getItemData(info.Type).icon;
this.baldricIcon.spriteFrame = ItemUtil.getItemIconBy({ icon: iconId });
this.node.getChildByName("aniIcon").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: iconId });
this.baldricName.string = info.EName;
this.attrsInfo = [];
let baseAttr = SKDataUtil.jsonBy(data.attribute);
if (SKDataUtil.isArray(baseAttr)) {
for (let item of baseAttr) {
for (let key in item) {
let type = SKDataUtil.toNumber(key);
var name = GameUtil.getAttrTypeL1Name(type);
let value = SKDataUtil.toNumber(item[key]);
let text = ``;
if (GameUtil.equipTypeNumerical.indexOf(type) == -1) {
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value / 10)}%`;
} else {
text = `${value > 0 ? "+" : ""}${SKDataUtil.toDecimal1(value)}`;
}
var pro = item[key].max ? (value / item[key].max) : 1
this.attrsInfo.push({ name: name, value: text, progress: pro })
break;
}
}
}
}
// 加載屬性
loadBaseAtts() {
var atts = this.attrsInfo;
for (let i = 0; i < atts.length; i++) {
let attItem = cc.instantiate(this.baseAtt);
attItem.parent = this.node.getChildByName("attrsNode");
attItem.getChildByName("attrName").getComponent(cc.Label).string = atts[i].name;
attItem.getChildByName("attrValue").getComponent(cc.Label).string = atts[i].value;
attItem.y = -60 - i * 40;
cc.tween(attItem)
.to(0.6, { x: -153 })
.start();
let progress = attItem.getChildByName("progress").getComponent(cc.ProgressBar)
cc.tween(progress)
.delay(0.6)
.to(0.5, { progress: atts[i].progress })
.start();
}
setTimeout(() => {
this.addSkillPrefab();
this.scrollSkill()
}, 1200)
}
fastShow() {
var atts = this.attrsInfo;
for (let i = 0; i < atts.length; i++) {
let attItem = cc.instantiate(this.baseAtt);
attItem.parent = this.node.getChildByName("attrsNode");
attItem.getChildByName("attrName").getComponent(cc.Label).string = atts[i].name;
attItem.getChildByName("attrValue").getComponent(cc.Label).string = atts[i].value;
attItem.y = -60 - i * 40;
cc.tween(attItem)
.to(0.2, { x: -153 })
.start();
let progress = attItem.getChildByName("progress").getComponent(cc.ProgressBar)
cc.tween(progress)
.delay(0.2)
.to(0.2, { progress: atts[i].progress })
.start();
}
setTimeout(() => {
var skillId = this.getSkill(this.baldricInfo.Type);
var skillinfo = SkillUtil.getSkill(skillId);
var skillName = skillinfo.name.substring(0, skillinfo.name.length - 3);
var item1 = cc.instantiate(this.skillPrefab);
item1.parent = this.skillContent1;
item1.getChildByName("Image_item").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: skillinfo.icon });
item1.getChildByName("Text_Skill_Name").getComponent(cc.Label).string = skillName;
item1.getChildByName("Image_190").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: "taozhuang_level" + (this.baldricInfo.Grade + 1) });
}, 200)
setTimeout(() => {
this.appraisalOverFast()
}, 800)
}
// 滾動技能
scrollSkill() {
let t = cc.tween;
t(this.skillContent1)
.call(() => {
this.changeSkillContent(this.skillContent1);
})
.delay(this.blinkDelay)
.union()
.repeat(8)
.call(() => {
this.currentIdx = 0;
this.changeSkillContent(this.skillContent1);
})
.call(() => {
// 2往上走
this.skillContent2.active = true
this.skillContent2MoveUp()
})
.parallel(
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay),
t().to(this.hideDuration, { opacity: 50 })
)
)
.by(0, { y: -this.moveDis })
.call(() => {
// 1往上走
this.skillContent1MoveUp()
})
.start();
}
skillContent1MoveUp() {
let t = cc.tween;
t(this.skillContent1)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent1);
}),
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().to(this.showDuration, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay),
t().to(this.hideDuration, { opacity: 50 })
)
)
.by(0, { y: -this.moveDis })
.union()
.repeat(2)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent1);
}),
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().to(this.showDuration, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay),
t().to(this.hideDuration, { opacity: 50 })
)
)
.call(() => {
this.currentIdx = 6;
this.direction = -1;
this.skillContent1MoveDown()
})
.start();
}
skillContent1MoveDown() {
let t = cc.tween;
t(this.skillContent1)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent1);
}),
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().to(this.showDuration * 1.5, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay * 1.5),
t().to(this.hideDuration * 1.5, { opacity: 50 })
)
)
.by(0, { y: this.moveDis })
.union()
.repeat(2)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent1);
}),
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().to(this.showDuration * 1.5, { opacity: 255 })
)
.call(() => {
this.appraisalOver()
})
.start();
}
skillContent2MoveUp() {
let t = cc.tween;
t(this.skillContent2)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent2);
}),
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().to(this.showDuration, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay),
t().to(this.hideDuration, { opacity: 50 })
)
)
.by(0, { y: -this.moveDis })
.union()
.repeat(3)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent2);
}),
t().by(this.halfRollDuration, { y: this.halfMoveDis }),
t().to(this.showDuration, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay * 1.5),
t().to(this.hideDuration * 1.5, { opacity: 50 })
)
)
.by(0, { y: this.moveDis })
.call(() => {
this.currentIdx = 5;
this.direction = -1;
this.skillContent2MoveDown()
})
.start();
}
skillContent2MoveDown() {
let t = cc.tween;
t(this.skillContent2)
.parallel(
t().call(() => {
this.changeSkillContent(this.skillContent2);
}),
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().to(this.showDuration * 1.5, { opacity: 255 })
)
.parallel(
t().by(this.halfRollDuration * 1.5, { y: -this.halfMoveDis }),
t().sequence(
t().delay(this.hideDelay * 1.5),
t().to(this.hideDuration * 1.5, { opacity: 50 })
)
)
.by(0, { y: this.moveDis })
.union()
.repeat(2)
.to(0, { opacity: 0 })
.start();
}
// 添加技能預製體並隨機化
addSkillPrefab() {
var skillId = this.getSkill(this.baldricInfo.Type);
var skillinfo = SkillUtil.getSkill(skillId);
var skillName = skillinfo.name.substring(0, skillinfo.name.length - 3);
for (let i = 0; i < 3; i++) {
var item1 = cc.instantiate(this.skillPrefab);
var item2 = cc.instantiate(this.skillPrefab);
item1.parent = this.skillContent1;
item2.parent = this.skillContent2;
item1.getChildByName("Image_item").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: skillinfo.icon });
item2.getChildByName("Image_item").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: skillinfo.icon });
item1.getChildByName("Text_Skill_Name").getComponent(cc.Label).string = skillName;
item2.getChildByName("Text_Skill_Name").getComponent(cc.Label).string = skillName;
}
// 隨機出現的技能等級
this.skillLevelList = [];
for (let i = 0; i < 8; i++) {
var r = Math.floor(Math.random() * 10)
var skillCount = r >= 8 ? 3 : r >= 4 ? 2 : 1;
var tempArr = [];
for (let j = 0; j < skillCount; j++) {
r = Math.floor(Math.random() * 1.50);
tempArr[j] = r >= 15 ? 3 : r >= 13 ? 2 : 1;
}
tempArr.sort();
if (i != 0 && this.checkSameArr(tempArr, this.skillLevelList[i - 1])) {
i--;
continue;
}
this.skillLevelList[i] = tempArr;
}
this.skillLevelList[2] = [this.baldricInfo.Grade]
}
getSkill(typeID) {
let baldric_suit = SKDataUtil.clone(GameModel.game_conf.baldric_suit);
let baldric_suits = baldric_suit;
for (let i in baldric_suits) {
for (let j in baldric_suits[i].list) {
if (baldric_suits[i].list[j] == typeID) {
return baldric_suits[i].skill;
}
}
}
console.error("Not find baldric suit skill")
}
checkSameArr(a, b) {
if (a.length != b.length)
return false;
for (let i in a) {
if (a[i] != b[i])
return false
}
return true
}
// 隨機技能等級和數量
changeSkillContent(node) {
var count = this.skillLevelList[this.currentIdx].length;
for (let i = 0; i < 3; i++) {
if (i > count - 1) {
node.children[i].active = false;
continue;
}
node.children[i].active = true;
var skillLevel = this.skillLevelList[this.currentIdx][i];
node.children[i].getChildByName("Image_190").getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: "taozhuang_level" + (skillLevel + 1) });
}
this.currentIdx += 1 * this.direction;
}
// 閃光動畫
loadFlashOfLightAni() {
let url = `ui/appraisal/1044`;
let self = this;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 7);
curClip.name = "auth";
curClip.wrapMode = cc.WrapMode.Loop;
let nodeAni = self.node.getChildByName("ani").getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play("auth");
}
})
}
// 鑑定結束
appraisalOver() {
let t = cc.tween;
var aniIcon = this.node.getChildByName("aniIcon");
var aniLevelIcon = this.node.getChildByName("baldricLevelIcon");
// 整體放大再縮小
t(this.node)
.to(0.1, { scale: 0.85 })
.to(0.1, { scale: 0.77 })
.start();
t(aniIcon)
.delay(0.2)
.call(() => {
var iconId = ItemUtil.getItemData(this.baldricInfo.Type).icon;
var color;
switch (this.baldricInfo.Grade) {
case 1: color = "60d566"; break;
case 2: color = "5fd5d6"; break;
case 3: color = "b94bd1"; break;
default: color = "60d566";
}
MsgAlert.addMsg(`鑑定成功,你獲得了[img]ui://main_ui/${iconId}[/img][color=#${color}][${this.baldricInfo.EName}][/color]`);
})
.parallel(
t().by(0.8, { y: 80 }),
t().to(0.4, { opacity: 255 })
)
.delay(0.3)
.call(() => {
let bezerby = cc.bezierBy(1.0, [cc.v2(88, 10), cc.v2(130, 80), cc.v2(155, -350)]);
aniIcon.runAction(cc.sequence(cc.spawn(bezerby, cc.rotateBy(0.6, 90)), cc.removeSelf()));
this.canClose = true;
})
.start()
t(aniLevelIcon)
.call(() => {
aniLevelIcon.getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: "accessory_level_" + (this.baldricInfo.Grade + 1) });
GameModel.send('c2s_get_bagitem', {
roleid: GameModel.player.roleid
});
})
.delay(0.1)
.by(0.1, { x: -150 })
.start()
}
// 鑑定結束
appraisalOverFast() {
let t = cc.tween;
var aniIcon = this.node.getChildByName("aniIcon");
var aniLevelIcon = this.node.getChildByName("baldricLevelIcon");
// 整體放大再縮小
t(this.node)
.to(0.05, { scale: 0.85 })
.to(0.05, { scale: 0.77 })
.start();
t(aniIcon)
.delay(0.1)
.call(() => {
var iconId = ItemUtil.getItemData(this.baldricInfo.Type).icon;
var color;
switch (this.baldricInfo.Grade) {
case 1: color = "60d566"; break;
case 2: color = "5fd5d6"; break;
case 3: color = "b94bd1"; break;
default: color = "60d566";
}
MsgAlert.addMsg(`鑑定成功,你獲得了[img]ui://main_ui/${iconId}[/img][color=#${color}][${this.baldricInfo.EName}][/color]`);
})
.parallel(
t().by(0.4, { y: 80 }),
t().to(0.2, { opacity: 255 })
)
.delay(0.1)
.call(() => {
let bezerby = cc.bezierBy(0.5, [cc.v2(88, 10), cc.v2(130, 80), cc.v2(155, -350)]);
aniIcon.runAction(cc.sequence(cc.spawn(bezerby, cc.rotateBy(0.3, 90)), cc.removeSelf()));
this.canClose = true;
})
.start()
t(aniLevelIcon)
.call(() => {
aniLevelIcon.getComponent(cc.Sprite).spriteFrame = ItemUtil.getItemIconBy({ icon: "accessory_level_" + (this.baldricInfo.Grade + 1) });
GameModel.send('c2s_get_bagitem', {
roleid: GameModel.player.roleid
});
})
.delay(0.1)
.by(0.1, { x: -150 })
.start()
}
closePanel() {
if (!this.canClose)
return
PopupManager.closeView(this.node.name);
}
}