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

135 lines
4.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { EAttrTypeL1 } from "../core/EEnum";
import GameModel from "../core/GameModel";
import GameUtil from "../core/GameUtil";
import ItemUtil from "../core/ItemUtil";
import SKDataUtil from "../gear_2.3.4/util/SKDataUtil";
import Transformation from "./Transformation";
const { ccclass, property } = cc._decorator;
export default class TransformationUtil {
/**
* 變身卡工具單例實例
*/
public static Instance: TransformationUtil = new TransformationUtil();
getCardsInfo(cardId: number = 0) {
let cards = GameModel.conf_transformation;
for (let i in cards) {
for (let j in cards[i]) {
if (cards[i][j].cardid == cardId) {
return cards[i][j];
}
}
}
console.warn("未找到該變身卡信息變身卡id:" + cardId);
return null;
}
getCardBaseDes(info): string {
var levelDesArr = ["普通", "高級", "特殊", "神獸級"];
var cardLevel = ItemUtil.getItemData(info.cardid < 500000 ? info.cardid + 400000 : info.cardid).level;
var des = `${levelDesArr[cardLevel - 1000]}五行變身卡,可${cardLevel > 1001 ? '大幅' : ''}提升能力,改變五行`;
if (info.cardstate == 0) {
// 屬性卡
des += '。\n'
} else {
var colorArr = ["00A03C", "009BFF", "D782FF", "E6641E"];
// 變身卡
des += `,並變換成[color=#${colorArr[cardLevel - 1000]}]${info.cardname}[/color]造型\n`
}
return des;
}
getCardTimeDes(info): string {
if (info.cardstate == 1)
return `【持續時間】:${info.validtime}分鐘\n`;
return "";
}
getCardAttrDes(info): string {
var attr = JSON.parse(info.gain);
var des = "";
for (let key in attr) {
if (parseInt(key) >= 70 && parseInt(key) <= 74) continue;
var str = GameUtil.getAttrTypeL1Name(parseInt(key));
console.log(`key:${key}, name:${str}`)
des += str + `${attr[key] > 0 ? '+' : ""}${attr[key]}%\n`;
}
return des;
}
getCardAttrDesOneLine(info): string {
var attr = JSON.parse(info.gain);
var des = "";
for (let key in attr) {
if (parseInt(key) >= 70 && parseInt(key) <= 74) continue;
var str = GameUtil.getAttrTypeL1Name(parseInt(key));
console.log(`key:${key}, name:${str}`)
des += str + `${attr[key] > 0 ? '+' : ""}${attr[key]}%`;
}
des += "\n";
return des;
}
getCardWuXingDes(info): string {
var attr = JSON.parse(info.fivephases);
var des = `金:${attr.jin}木:${attr.mu}水:${attr.shui}火:${attr.huo}土:${attr.tu}`;
return des;
}
getCardDesById(cardId: number = 0): string {
var info = this.getCardsInfo(cardId);
var des = "";
des += this.getCardBaseDes(info);
des += this.getCardTimeDes(info);
des += "[color=#A35B1B]" + this.getCardAttrDes(info) + "[/color]";
des += "[color=#0096FF]" + this.getCardWuXingDes(info) + "[/color]";
return des;
}
getCardDesInfoById(cardId: number = 0, time): string {
var info = this.getCardsInfo(cardId);
var des = "";
des += this.getCardAttrDesOneLine(info);
des += "<color=#E6F0AA>五行修煉加成 +" + this.getCardAddition(cardId) + "%</color>\n";
var surplusTime = time - new Date().getTime();
des += "<color=#64C8D7>剩餘時間:" + Math.floor(surplusTime / 1000 / 60) + "分</color>";
return des;
}
getCardAddition(cardId: number = 0, practiceData: any = Transformation.Instance.practiceData) {
if (!practiceData) {
console.warn("修煉數據錯誤");
return 0;
}
var addition = 0;
var attr = JSON.parse(this.getCardsInfo(cardId).fivephases);
for (let key in attr) {
if (attr[key] >= 0) {
addition += attr[key] / 100 * practiceData[`${key}level`];
}
}
addition *= 2;
return addition.toFixed(1);
}
/**
* 通過5行查找受影響的卡片
* @param attrType 五行屬性 金1 木2 水3 火4 土5
*/
getEffCardsByAttr(attrType: number = 0): any {
if (attrType == 6)
return GameModel.conf_transformation[0];
var keyArr = ["", "jin", "mu", "shui", "huo", "tu"];
let cards = GameModel.conf_transformation[0];
var eff, list = [];
for (let i in cards) {
eff = JSON.parse(cards[i].fivephases);
if (eff[keyArr[attrType]] > 0) {
list.push(cards[i]);
}
}
return list;
}
}