You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
9.2 KiB
271 lines
9.2 KiB
|
|
import { LocalDataMgr } from "../Mgr_LocalData/LocalDataMgr";
|
|
import { Global } from "../Global";
|
|
import { EResUrls } from "../ResUrl/EResUrls";
|
|
import { GameTotalType, EBundleName, QualityType, PropType, GameAbility, ESuitType } from "../const/GameEnum";
|
|
import { IData, IDataArray } from "../const/GameInterface";
|
|
import { Color } from "cc";
|
|
import { QUALITY_COLOR_PARAMS } from "../const/GGameData";
|
|
|
|
export default class GDUtils {
|
|
|
|
/** 获取资源路径 */
|
|
static getName(data: IData) {
|
|
switch (data.type) {
|
|
case GameTotalType.EXP:
|
|
return "御剑经验";
|
|
case GameTotalType.TOKEN:
|
|
return Global.CsvMgr.base_res_csv[data.id].name;
|
|
case GameTotalType.ITEM:
|
|
return Global.CsvMgr.Items_csv[data.id].name;
|
|
}
|
|
return ;
|
|
}
|
|
|
|
/** 获取货币的名称 */
|
|
static getTokenName(type: PropType):string {
|
|
return Global.CsvMgr.base_res_csv[type]? Global.CsvMgr.base_res_csv[type].name : "";
|
|
}
|
|
|
|
/** 获取资源路径 */
|
|
static getUrl(data: IData) {
|
|
return this.getUrl2(data.type, data.id);
|
|
}
|
|
|
|
/** 获取资源路径 */
|
|
static getUrl2(type: GameTotalType, id: number) {
|
|
let url = "";
|
|
switch (type) {
|
|
case GameTotalType.EXP:
|
|
return EResUrls.Texture(`Basic/exp`);
|
|
case GameTotalType.TOKEN:
|
|
return EResUrls.Texture(`Basic/${Global.CsvMgr.base_res_csv[id].icon}`);
|
|
case GameTotalType.ITEM:
|
|
return EResUrls.Texture(`icon/${Global.CsvMgr.Items_csv[id].img}`);
|
|
case GameTotalType.TREAS:
|
|
return EResUrls.Texture(`icon/${Global.CsvMgr.Props_csv[id].img}`);
|
|
case GameTotalType.ENEMYICON:
|
|
let headicon = "Basic/exp"
|
|
let enemycfg:any = Global.CsvMgr.Enemy_csv[id];
|
|
if(enemycfg == null){
|
|
enemycfg = Global.CsvMgr.Mutate_csv[id];
|
|
}
|
|
if(enemycfg){
|
|
headicon = `icon/${enemycfg.headicon}`
|
|
}
|
|
return EResUrls.Texture(headicon);
|
|
case GameTotalType.WUGONG:
|
|
return EResUrls.Texture(`icon/${Global.CsvMgr.WuGong_csv[id].img}`);
|
|
case GameTotalType.UNLOCK:
|
|
case GameTotalType.BUILD:
|
|
return EResUrls.Texture(`unlock/${type}_${id}`);
|
|
case GameTotalType.SCENEBG:
|
|
return EResUrls.Texture(Global.CsvMgr.Level_csv[id].name);
|
|
case GameTotalType.MUTATEICON:
|
|
return EResUrls.Texture(`pic/${id}`);
|
|
case GameTotalType.SUITSKILL:
|
|
return EResUrls.Texture(`skill/${Global.CsvMgr.Suit_eff_csv[id].img}`);
|
|
}
|
|
return url;
|
|
}
|
|
|
|
/** 获取资源路径 */
|
|
static getUBundle(type: GameTotalType,id:number = 0): EBundleName |string {
|
|
switch (type) {
|
|
case GameTotalType.EXP:
|
|
case GameTotalType.TOKEN:
|
|
case GameTotalType.ITEM:
|
|
case GameTotalType.TREAS:
|
|
case GameTotalType.WUGONG:
|
|
case GameTotalType.UNLOCK:
|
|
case GameTotalType.SUITSKILL:
|
|
case GameTotalType.BUILD:
|
|
return EBundleName.GeneralRes;
|
|
case GameTotalType.ENEMYICON:
|
|
case GameTotalType.MUTATEICON:
|
|
return EBundleName.HeadIconRes;
|
|
case GameTotalType.SCENEBG:
|
|
return EBundleName.ScenesBgRes;
|
|
}
|
|
}
|
|
|
|
/** 获取资源路径 */
|
|
static getAtlas(type: GameTotalType): string {
|
|
switch (type) {
|
|
case GameTotalType.TOKEN:
|
|
return null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/** 获取资源路径 */
|
|
static getType(tData: IData) {
|
|
switch (tData.type) {
|
|
case GameTotalType.TOKEN:
|
|
return "货币";
|
|
case GameTotalType.ITEM:
|
|
return "物品";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
/**根据通用数据格式移除道具
|
|
* @param isAll 是否移除所有道具 只有道具和材料类型才生效
|
|
*/
|
|
static RemovePropByIDataArray(data: IData | IDataArray, isAll: boolean = false) {
|
|
if (Array.isArray(data)) {
|
|
for (let i = 0; i < data.length; i++) {
|
|
const element = data[i];
|
|
this.RemovePropByIDataArray(element, isAll);
|
|
}
|
|
} else {
|
|
switch (data.type) {
|
|
case GameTotalType.TOKEN:
|
|
break
|
|
default:
|
|
ConsoleEx.Log("暂不支持 此类型得删除", data);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**根据通用数据格式获取道具数量 */
|
|
static GetPropNumberByIData(data: IData): number {
|
|
switch (data.type) {
|
|
case GameTotalType.TOKEN:
|
|
break
|
|
default:
|
|
ConsoleEx.Log("暂不支持 此类型得删除", data);
|
|
break;
|
|
}
|
|
return 0;
|
|
|
|
}
|
|
|
|
/**分配奖励 */
|
|
static DistributeRewards(data:IDataArray|IData){
|
|
|
|
if(Array.isArray(data)){
|
|
for (let i = 0; i < data.length; i++) {
|
|
this.DistributeRewards(data[i]);
|
|
}
|
|
}else{
|
|
switch (data.type) {
|
|
case GameTotalType.TOKEN:
|
|
LocalDataMgr.Token.addToken(data.id,data.num)
|
|
break;
|
|
case GameTotalType.ITEM:
|
|
LocalDataMgr.Bag.addItem(data.id,data.num)
|
|
break;
|
|
case GameTotalType.ABILITY:
|
|
this.GetGameDataReward(data)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**游戏功能数据奖励 */
|
|
static GetGameDataReward(data:IData): void {
|
|
switch (data.id) {
|
|
case GameAbility.SHOP_REFRESH_TIMES:
|
|
LocalDataMgr.Shop.addTimes(data.num);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/**获取匹配的数据 */
|
|
static GetIDataByList(data: IData, list: IDataArray): IData {
|
|
for (let i = 0; i < list.length; i++) {
|
|
const tData = list[i];
|
|
if (data.type == tData.type && data.id == tData.id) {
|
|
return tData;
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
/**获取品质颜色 */
|
|
static GetQualityColorHEX(quality: QualityType): string {
|
|
switch (quality) {
|
|
case QualityType.NULL:
|
|
case QualityType.BLANCK:
|
|
return "#000000";
|
|
case QualityType.GREEN:
|
|
return "#6da751";
|
|
case QualityType.BLUE:
|
|
return "#5679ff";
|
|
case QualityType.PURPLE:
|
|
return "#a659e1";
|
|
case QualityType.ORANGE:
|
|
return "#F0A03B";
|
|
case QualityType.RED:
|
|
return "#F05F3B";
|
|
case QualityType.COL:
|
|
return "#F05F3B";
|
|
default:
|
|
return "#F05F3B";
|
|
}
|
|
}
|
|
|
|
/**获取品质颜色 */
|
|
static GetQualityColor(quality: QualityType): Color {
|
|
switch (quality) {
|
|
case QualityType.NULL:
|
|
case QualityType.BLANCK:
|
|
return QUALITY_COLOR_PARAMS.BLACK;
|
|
case QualityType.GREEN:
|
|
return QUALITY_COLOR_PARAMS.GREEN;
|
|
case QualityType.BLUE:
|
|
return QUALITY_COLOR_PARAMS.BLUE;
|
|
case QualityType.PURPLE:
|
|
return QUALITY_COLOR_PARAMS.PURPLE;
|
|
case QualityType.ORANGE:
|
|
return QUALITY_COLOR_PARAMS.ORANGE;
|
|
case QualityType.RED:
|
|
return QUALITY_COLOR_PARAMS.RED;
|
|
case QualityType.COL:
|
|
return QUALITY_COLOR_PARAMS.COL;
|
|
default:
|
|
return QUALITY_COLOR_PARAMS.RED;
|
|
}
|
|
}
|
|
/**根据品质颜色格式化字符串 */
|
|
static GetHEXByQualityForStr(string: string, quality: QualityType): string {
|
|
switch (quality) {
|
|
case QualityType.NULL:
|
|
case QualityType.BLANCK:
|
|
return `<color=#000000>${string}</color>`;
|
|
case QualityType.GREEN:
|
|
return `<color=#6da751>${string}</color>`;
|
|
case QualityType.BLUE:
|
|
return `<color=#5679ff>${string}</color>`;
|
|
case QualityType.PURPLE:
|
|
return `<color=#a659e1>${string}</color>`;
|
|
case QualityType.ORANGE:
|
|
return `<color=#F0A03B>${string}</color>`;
|
|
case QualityType.RED:
|
|
return `<color=#F05F3B>${string}</color>`;
|
|
case QualityType.COL:
|
|
return `<color=#F05F3B>${string}</color>`;
|
|
default:
|
|
return `<color=#F05F3B>${string}</color>`;
|
|
}
|
|
}
|
|
|
|
|
|
/**根据套装类型格式化字符串颜色 */
|
|
static GetHEXBySuitTypeForStr(string: string, type: ESuitType): string {
|
|
switch (type) {
|
|
case ESuitType.YinYang:
|
|
return `<color=#DCDCDC>${string}</color>`;
|
|
case ESuitType.LieYan:
|
|
return `<color=#EE6363>${string}</color>`;
|
|
case ESuitType.CuiYu:
|
|
return `<color=#00FA9A>${string}</color>`;
|
|
default:
|
|
return `<color=#000000>${string}</color>`;
|
|
}
|
|
}
|
|
|
|
}
|
|
|