|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, sys, utils} from "cc";
|
|
|
+import { _decorator, game, sys, utils} from "cc";
|
|
|
import { Singleton } from "../core/manager/Singleton";
|
|
|
import { Constants } from "./Constants";
|
|
|
import { Utils } from "../utils/Utils";
|
|
@@ -6,11 +6,28 @@ import { csvMgr } from "../core/csv/CsvManager";
|
|
|
import { stateMgr } from "../core/manager/StateManager";
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
+/*
|
|
|
+@description 枪的属性值
|
|
|
+ */
|
|
|
+export enum GunAttribute {
|
|
|
+ /**伤害攻击*/
|
|
|
+ attack = "attack",
|
|
|
+ /**子弹速度*/
|
|
|
+ bulletSpeed = "bulletSpeed",
|
|
|
+ /**稳定性*/
|
|
|
+ stability = "stability",
|
|
|
+ /**弹夹容量*/
|
|
|
+ magazine = "magazine",
|
|
|
+ /**换弹速度*/
|
|
|
+ reloadingSpeed = "reloadingSpeed",
|
|
|
+ /**镜头缩放速度*/
|
|
|
+ zoomingSpeed = "zoomingSpeed"
|
|
|
+}
|
|
|
+
|
|
|
@ccclass("UserData")
|
|
|
class UserData extends Singleton {
|
|
|
//枪的属性列表
|
|
|
- public gunAttrKeys:string[] = ["attack","bulletSpeed","stability","magazine",
|
|
|
- "reloadingSpeed","zoomingSpeed"];
|
|
|
+ public gunAttrKeys:string[] = Object.values(GunAttribute);
|
|
|
//玩家是否连续通关 如果连续通关 这个值会大于1
|
|
|
public passNum: number = 0;
|
|
|
//玩家数据
|
|
@@ -152,7 +169,7 @@ class UserData extends Singleton {
|
|
|
guns: [],//玩家拥有的枪
|
|
|
useIdx: 0,
|
|
|
};
|
|
|
- this.getGunData(configData.defaultWeapon,true);
|
|
|
+ this.getGunData(configData.defaultWeapon,true,'');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -160,71 +177,82 @@ class UserData extends Singleton {
|
|
|
* 查询一个枪的数据 顺带把枪的属性等级提升的部分参数带过来
|
|
|
* @param id 枪的id
|
|
|
* @param isSave 是否保存绑定在玩家身上
|
|
|
+ * @param attr_name 属性名字这儿要升级 只有当第一个的没有拥有这把枪的时候 才不传值
|
|
|
+ * 如果是已经 拥有了这把枪 要升级属性时,这个方法不要重复调用,因为会 加等级上的参数值 原因是这个要没把枪持久化数据保存
|
|
|
* @returns 返回枪查询的枪的数据
|
|
|
*/
|
|
|
- public getGunData(id: string,isSave: boolean = false):any{
|
|
|
+ private getGunData(id: string,isSave: boolean = false,attr_name: string = ''):any{
|
|
|
//如果玩家已经拥有该枪 则直接返回
|
|
|
let gData: any = this._data.guns.find(e=>e.id == id);
|
|
|
if(!gData){
|
|
|
gData = Utils.clone(this.playerGunsTable).find(e=>e.id == id);
|
|
|
}
|
|
|
if(!gData)return;
|
|
|
- this.gunAttrKeys.forEach((arg_name:string,idx: number) => {
|
|
|
- const levelKey:string = `${arg_name}Level`;
|
|
|
- let attrLevel:number = 1;
|
|
|
- if(gData[levelKey] != null){
|
|
|
- attrLevel = gData[levelKey];
|
|
|
- }
|
|
|
- let fun: Function = (i,l,name)=>{
|
|
|
- return this.playerGunAttsTable.find(
|
|
|
- e=>e.id == i
|
|
|
- && e.level == l
|
|
|
- && e.attribute_name == name);
|
|
|
- };
|
|
|
- let glData:any = fun(id,attrLevel,arg_name);
|
|
|
- if(glData){
|
|
|
- let nextGLData:any = fun(id,attrLevel + 1,arg_name);
|
|
|
- if(!nextGLData){nextGLData = glData};
|
|
|
- //unique_id 这个字段为了识别到时候同一个属性 升级极端情况下 材料消耗相同的时候的判断
|
|
|
- if(idx == 0){
|
|
|
- gData.attack += glData.value;//伤害
|
|
|
- gData.attackUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.attackLevel= glData.level;//属性等级
|
|
|
- gData.attackExpenditure = glData.expenditure;//当前等级消耗
|
|
|
- gData.nextAttackExpenditure = nextGLData ? nextGLData.expenditure : null;//伤害下一个等级升级消耗
|
|
|
- }else if(idx == 1){
|
|
|
- gData.bulletSpeed += glData.value;//射速
|
|
|
- gData.bulletSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.bulletSpeedLevel= glData.level;//属性等级
|
|
|
- gData.bulletSpeedExpenditure = glData.expenditure;
|
|
|
- gData.nextBulletSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//射速下一个等级升级消耗
|
|
|
- }else if(idx == 2){
|
|
|
- gData.stability += glData.value;//稳定性
|
|
|
- gData.stabilityUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.stabilityLevel= glData.level;//属性等级
|
|
|
- gData.stabilityExpenditure = glData.expenditure;
|
|
|
- gData.nextStabilityExpenditure = nextGLData ? nextGLData.expenditure : null;//稳定性下一个等级升级消耗
|
|
|
- }else if(idx == 3){
|
|
|
- gData.magazine+= glData.value;//弹匣
|
|
|
- gData.magazineUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.magazineLevel= glData.level;//属性等级
|
|
|
- gData.magazineExpenditure = glData.expenditure;
|
|
|
- gData.nextMagazineExpenditure = nextGLData ? nextGLData.expenditure : null;//弹匣下一个等级升级消耗
|
|
|
- }else if(idx == 4){
|
|
|
- gData.reloadingSpeed += glData.value;//装填速度
|
|
|
- gData.reloadingSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.reloadingSpeedLevel= glData.level;//属性等级
|
|
|
- gData.reloadingSpeedExpenditure = glData.expenditure;
|
|
|
- gData.nextReloadingSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//装填速度下一个等级升级消耗
|
|
|
- }else if(idx == 5){
|
|
|
- gData.zoomingSpeed += glData.value;//缩放速度
|
|
|
- gData.zoomingSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
- gData.zoomingSpeedLevel= glData.level;//属性等级
|
|
|
- gData.zoomingSpeedExpenditure = glData.expenditure;
|
|
|
- gData.nextZoomingSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//缩放速度下一个等级升级消耗
|
|
|
+ //属性名字这儿要升级 只有没有拥有这把枪的时候attr_name才默认不传值
|
|
|
+ let attrKeys:any[] = Utils.clone(this.gunAttrKeys);
|
|
|
+ if(!Utils.isNull(attr_name)){
|
|
|
+ attrKeys = attrKeys.filter(e=>e == attr_name);
|
|
|
+ }
|
|
|
+ if(gData.hasAttrs == null
|
|
|
+ || !Utils.isNull(attr_name)){
|
|
|
+ attrKeys.forEach(name => {
|
|
|
+ const levelKey:string = `${name}Level`;
|
|
|
+ let attrLevel:number = 1;
|
|
|
+ if(gData[levelKey] != null){
|
|
|
+ attrLevel = gData[levelKey];
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ let fun: Function = (i,l,name)=>{
|
|
|
+ return this.playerGunAttsTable.find(
|
|
|
+ e=>e.id == i
|
|
|
+ && e.level == l
|
|
|
+ && e.attribute_name == name);
|
|
|
+ };
|
|
|
+ let glData:any = fun(id,attrLevel,name);
|
|
|
+ if(glData){
|
|
|
+ let nextGLData:any = fun(id,attrLevel + 1,name);
|
|
|
+ if(!nextGLData){nextGLData = glData};
|
|
|
+ //unique_id 这个字段为了识别到时候同一个属性 升级极端情况下 材料消耗相同的时候的判断
|
|
|
+ if(name == GunAttribute.attack){
|
|
|
+ gData.attack += glData.value;//伤害
|
|
|
+ gData.attackUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.attackLevel= glData.level;//属性等级
|
|
|
+ gData.attackExpenditure = glData.expenditure;//当前等级消耗
|
|
|
+ gData.nextAttackExpenditure = nextGLData ? nextGLData.expenditure : null;//伤害下一个等级升级消耗
|
|
|
+ }else if(name == GunAttribute.bulletSpeed){
|
|
|
+ gData.bulletSpeed += glData.value;//射速
|
|
|
+ gData.bulletSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.bulletSpeedLevel= glData.level;//属性等级
|
|
|
+ gData.bulletSpeedExpenditure = glData.expenditure;
|
|
|
+ gData.nextBulletSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//射速下一个等级升级消耗
|
|
|
+ }else if(name == GunAttribute.stability){
|
|
|
+ gData.stability += glData.value;//稳定性
|
|
|
+ gData.stabilityUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.stabilityLevel= glData.level;//属性等级
|
|
|
+ gData.stabilityExpenditure = glData.expenditure;
|
|
|
+ gData.nextStabilityExpenditure = nextGLData ? nextGLData.expenditure : null;//稳定性下一个等级升级消耗
|
|
|
+ }else if(name == GunAttribute.magazine){
|
|
|
+ gData.magazine+= glData.value;//弹匣
|
|
|
+ gData.magazineUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.magazineLevel= glData.level;//属性等级
|
|
|
+ gData.magazineExpenditure = glData.expenditure;
|
|
|
+ gData.nextMagazineExpenditure = nextGLData ? nextGLData.expenditure : null;//弹匣下一个等级升级消耗
|
|
|
+ }else if(name == GunAttribute.reloadingSpeed){
|
|
|
+ gData.reloadingSpeed += glData.value;//装填速度
|
|
|
+ gData.reloadingSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.reloadingSpeedLevel= glData.level;//属性等级
|
|
|
+ gData.reloadingSpeedExpenditure = glData.expenditure;
|
|
|
+ gData.nextReloadingSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//装填速度下一个等级升级消耗
|
|
|
+ }else if(name == GunAttribute.zoomingSpeed){
|
|
|
+ gData.zoomingSpeed += glData.value;//缩放速度
|
|
|
+ gData.zoomingSpeedUniqueId = nextGLData.unique_id;//属性等级下的唯一id
|
|
|
+ gData.zoomingSpeedLevel= glData.level;//属性等级
|
|
|
+ gData.zoomingSpeedExpenditure = glData.expenditure;
|
|
|
+ gData.nextZoomingSpeedExpenditure = nextGLData ? nextGLData.expenditure : null;//缩放速度下一个等级升级消耗
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ gData.hasAttrs = true;
|
|
|
if(isSave){
|
|
|
let indx: number = this._data.guns.findIndex(e=>e.id == gData.id);
|
|
|
if(indx == -1){
|
|
@@ -276,7 +304,7 @@ class UserData extends Singleton {
|
|
|
//查询属性的等级
|
|
|
const attrLevelKey:string = `${attribute_name}Level`;
|
|
|
hasGun[attrLevelKey]+= 1;
|
|
|
- this.getGunData(gun.id,true);
|
|
|
+ this.getGunData(gun.id,true,attribute_name);
|
|
|
}
|
|
|
|
|
|
/**
|