446 lines
15 KiB
TypeScript
446 lines
15 KiB
TypeScript
import { getHeroInfoById, getStarRatio, /*getHeroSkillById,*/ getSeidById, getOlySeidByType, getGoodById } from "./gamedata";
|
||
import { getAtrrNameById, ABI_TYPE, SEID_TYPE } from "../consts";
|
||
import { EXPRESSION } from '../consts';
|
||
|
||
export default class Actor {
|
||
private hid: number = 0;
|
||
private lv: number = 0;
|
||
private oldCe: number = 0;
|
||
private star: number = 0;
|
||
private colorStar: number = 0;
|
||
private equips: Array<any> = [];
|
||
private conections: Array<{id: number;name: string;valid: boolean;}> = [];
|
||
/**被动技能 */
|
||
private seidList:Array<any> = new Array<any>(3);
|
||
private effectList:Map<number,Array<any> > = new Map<number,Array<any> >();
|
||
|
||
initHero(hero: any) { // 从数据库拿到的hero
|
||
this.hid = hero.hid;
|
||
this.lv = hero.lv;
|
||
this.oldCe = hero.ce;
|
||
this.star = hero.star;
|
||
this.colorStar = hero.colorStar;
|
||
this.equips = hero.equips;
|
||
console.log(this.hid, this.lv, this.oldCe, this.star, this.colorStar, this.conections);
|
||
this.updateActorEffect();
|
||
}
|
||
|
||
updateActorEffect(){
|
||
|
||
//添加装备属性和效果
|
||
|
||
//添加技能
|
||
this.updateSkillInfo();
|
||
//添加被动效果1.0
|
||
for(let i = 0;i < this.seidList.length;i++){
|
||
if(this.seidList[i] && this.seidList[i].id > 0){
|
||
this.addSeidEffect(this.seidList[i].id,this.seidList[i].gainValueArr);
|
||
}
|
||
}
|
||
//添加被动效果 2.0
|
||
// for(let i = 0;i < this.seidList.length;i++){
|
||
// if(this.seidList[i]._id > 0){
|
||
// this.addSeidEffectNew(this.seidList[i]);
|
||
// }
|
||
// }
|
||
}
|
||
|
||
/**更新武将的被动技能 */
|
||
updateSkillInfo(){
|
||
// let dicHero = getHeroInfoById(this.hid);
|
||
// console.log('updateSkillInfo', dicHero.skill, getHeroSkillById(dicHero.skill))
|
||
//被动技能
|
||
// if(dicHero.skill){
|
||
// let {seidLvUpArr} = getHeroSkillById(dicHero.skill);
|
||
// for(let ii = 0;ii < seidLvUpArr.length;ii+=2){
|
||
// if(this.lv >= seidLvUpArr[ii + 1]){
|
||
// let dicSeid = getSeidById(seidLvUpArr[ii]);
|
||
// // console.log('updateSkillInfo*', seidLvUpArr[ii], dicSeid)
|
||
// if(dicSeid){
|
||
// this.seidList[Math.floor(ii/2)] = dicSeid;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
}
|
||
|
||
addSeidEffect(seidId:number, seidValue?:Array<number>){
|
||
// console.log('addSeidEffect', seidId, seidValue)
|
||
let curSeid = getSeidById(seidId);
|
||
if(!curSeid) {console.log("seidId not found:"+seidId);return;}
|
||
if(!seidValue) seidValue = curSeid.gainValueArr;
|
||
if(!seidValue) seidValue = [];
|
||
|
||
if(curSeid.type === 999){
|
||
for(let i = 0;i < seidValue.length;i++){
|
||
this.addSeidEffect(seidValue[i]);
|
||
}
|
||
return;
|
||
}
|
||
|
||
let olySeid = getOlySeidByType(curSeid.type);
|
||
if(!olySeid) {console.log("olySeidType not found:"+curSeid.type);return;}
|
||
|
||
if(olySeid.isSeid){ // 是被动
|
||
let el = this.effectList.get(curSeid.type);
|
||
if(!el || !el.length){
|
||
if(!el){
|
||
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
|
||
} else {
|
||
el.push(Object.assign({}, curSeid));
|
||
}
|
||
}
|
||
else{
|
||
let buffArr = this.effectList.get(curSeid.type)||[];
|
||
if(olySeid.olyType == 101){
|
||
let identical:boolean = true;
|
||
buffArr.forEach((value)=>{
|
||
if(value.type != curSeid.type||value.gainValueArr.length != seidValue?.length){
|
||
identical = false;
|
||
return;
|
||
}
|
||
value.gainValueArr.forEach((val,key)=>{
|
||
if(!seidValue) seidValue = [];
|
||
if(val!= seidValue[key]){
|
||
identical = false;
|
||
return;
|
||
}
|
||
})
|
||
|
||
});
|
||
if(!identical){
|
||
let el = this.effectList.get(curSeid.type);
|
||
if(!el){
|
||
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
|
||
} else {
|
||
el.push(Object.assign({}, curSeid));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
let tBuff,startIndex:number = 0;
|
||
if(olySeid.olyType >= 103){
|
||
startIndex = 1;
|
||
let addSeid:boolean = true;
|
||
for(let k = 0;k < buffArr.length;k++){
|
||
tBuff = buffArr[k];
|
||
if(tBuff && tBuff.gainValueArr && tBuff.gainValueArr[0] == seidValue[0]){
|
||
addSeid = false;
|
||
break;
|
||
}
|
||
}
|
||
if(addSeid){
|
||
tBuff = null;
|
||
let el = this.effectList.get(curSeid.type);
|
||
if(!el){
|
||
this.effectList.set(curSeid.type, [Object.assign({}, curSeid)]);
|
||
} else {
|
||
el.push(Object.assign({}, curSeid));
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
tBuff = buffArr[0];
|
||
}
|
||
|
||
if(tBuff){
|
||
for(let j = startIndex;j < seidValue.length;j++){
|
||
switch(olySeid.olyType){
|
||
case 100:
|
||
tBuff.gainValueArr[j] += seidValue[j];
|
||
break;
|
||
case 102:
|
||
tBuff.gainValueArr[j] = seidValue[j];
|
||
break;
|
||
case 103:
|
||
if(tBuff.gainValueArr[j] < seidValue[j]){
|
||
tBuff.gainValueArr[j] = seidValue[j];
|
||
}
|
||
break;
|
||
case 104:
|
||
if(tBuff.gainValueArr[j] > seidValue[j]){
|
||
tBuff.gainValueArr[j] = seidValue[j];
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// switch(olySeid._olyType){
|
||
// case 1://对比
|
||
|
||
// break;
|
||
// case 2://
|
||
// default:
|
||
// console.log("not found _olyType:"+olySeid._olyType);
|
||
// break;
|
||
// }
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
getGrowUp(abilityType:number):number{
|
||
const dicHero = getHeroInfoById(this.hid);
|
||
const dicStarRatio = getStarRatio(this.star)||0;
|
||
return dicHero.baseAbilityUpArr[abilityType] * dicStarRatio;
|
||
}
|
||
|
||
getBaseAbility(abilityType:number):number{
|
||
const dicHero = getHeroInfoById(this.hid);
|
||
// console.log('getBaseAbility', dicHero.baseAbilityArr[abilityType]);
|
||
// console.log('getBaseAbility', this.lv);
|
||
// console.log('getBaseAbility', this.getGrowUp(abilityType));
|
||
return dicHero.baseAbilityArr[abilityType] + (this.lv - 1)*this.getGrowUp(abilityType);
|
||
}
|
||
|
||
|
||
isHadSeid(type:number):boolean{
|
||
let el = this.effectList.get(type);
|
||
if(this.effectList.has(type) && el && el.length){
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* 获取武将效果
|
||
* @type 特技type
|
||
* returns Array<Array<Buff> > 0:特技 1:buff 2:光环
|
||
* */
|
||
getSeidEffect(type:number):Array<Array<any> >{
|
||
let retArr:Array<Array<any> > = new Array<Array<any> >();
|
||
let el = this.effectList.get(type);
|
||
if(this.effectList.has(type) && el && el.length){
|
||
retArr.push(el);
|
||
}
|
||
return retArr;
|
||
}
|
||
|
||
/**获取seid 数值效果 */
|
||
getSeidAddAbilityNumByAbility(type:number,ability:number){ // type: 101/102等,ability:1-17代表hp,atk等
|
||
let ret:number = 0;
|
||
if(this.isHadSeid(type)){ // effectList, buffList
|
||
let buff = this.getSeidEffect(type);
|
||
for(let i = 0;i < buff.length;i++){
|
||
for(let j = 0;j < buff[i].length;j++){
|
||
// console.log(ability, buff[i][j].gainValueArr[0], buff[i][j].gainValueArr[1])
|
||
if(ability == buff[i][j].gainValueArr[0]){
|
||
ret += buff[i][j].gainValueArr[1];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// console.log('getSeidAddAbilityNumByAbility', type, ret)
|
||
return ret;
|
||
}
|
||
|
||
getRealAbility(abilityType: number) {
|
||
|
||
let baseAbility:number = 0;
|
||
|
||
if(abilityType <= ABI_TYPE.ABI_SPEED){
|
||
// console.log('getRealAbility', this.getBaseAbility(abilityType));
|
||
// console.log('getRealAbility', this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE102,abilityType));
|
||
// console.log('getRealAbility', this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType));
|
||
baseAbility = this.getBaseAbility(abilityType)*(100+this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE102,abilityType))/100 + this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType);
|
||
}
|
||
else{
|
||
baseAbility = this.getSeidAddAbilityNumByAbility(SEID_TYPE.TYPE101,abilityType);
|
||
}
|
||
return baseAbility
|
||
}
|
||
|
||
getAttributeJson() {
|
||
let json = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, agi: 0, speed: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0};
|
||
|
||
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
|
||
let field = getAtrrNameById(i);
|
||
json[field] = this.getRealAbility(i);
|
||
}
|
||
return json
|
||
}
|
||
|
||
calculateCE() {
|
||
// 武将
|
||
let json = this.getAttributeJson();
|
||
let ce = this.calculateCEByExpression(json);
|
||
|
||
// 装备
|
||
for(let equip of this.equips) {
|
||
let good = new HistoryGoods();
|
||
good.loadDataByJson(equip);
|
||
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
|
||
ce += good.getGoodsAddAbility(i);
|
||
}
|
||
|
||
}
|
||
return Math.floor(ce);
|
||
}
|
||
|
||
calculateCEByExpression(json: {hp:number, atk: number, matk: number, def: number, mdef: number, agi: number, luk: number, hit: number, cri: number, flee: number, antCri: number, damageIncrease: number, damageDecrease: number, defIngnore: number, bloodSuck: number}): number {
|
||
let {hp, atk, matk, def, mdef, agi, luk, hit, cri, flee, antCri, damageIncrease, damageDecrease, defIngnore, bloodSuck } = json;
|
||
console.log(JSON.stringify({hp, atk, matk, def, mdef, agi, luk, hit, cri, flee, antCri, damageIncrease, damageDecrease, defIngnore, bloodSuck}));
|
||
|
||
let ce = 0;
|
||
try {
|
||
ce = eval(EXPRESSION.CE);
|
||
} catch(e) {
|
||
console.error('expression wrong');
|
||
}
|
||
return ce
|
||
}
|
||
|
||
}
|
||
|
||
class HistoryGoods{
|
||
private _goodsId:number = 0;
|
||
private _serverGId:number = 0;
|
||
private _itid:number = 0;
|
||
private _quality:number = 0;
|
||
private _lv:number = 0;
|
||
/**物攻策攻数值浮动上下限变化率 */
|
||
private _randRange:number = 0;
|
||
/**装备的武将dataID */
|
||
private _equipActorDataId:number = 0;
|
||
/**装备属性 */
|
||
private _goodsAbility:Array<number> = new Array<number>();
|
||
/**装备属性 随机的百分比 */
|
||
private _goodsAbilityPre:Array<number> = new Array<number>();
|
||
|
||
resetAllData(){
|
||
this.setGoodsId(0);
|
||
this.setItid(0);
|
||
this.setEquipActorDataId(0);
|
||
|
||
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
|
||
this._goodsAbility[i] = 0;
|
||
this._goodsAbilityPre[i] = 0;
|
||
}
|
||
}
|
||
//加载
|
||
loadDataByJson(json){
|
||
// "_id": "5f841c27eb94a70b385beea4",
|
||
// "seqId": 8,
|
||
// "__v": 0,
|
||
// "createdAt": "2020-10-12T09:04:39.087Z",
|
||
// "eName": "青铜短剑",
|
||
// "eid": 1,
|
||
// "holes": [],
|
||
// "initHoleCnt": 0,
|
||
// "lv": 1,
|
||
// "randRange": 0,
|
||
// "randSe": [],
|
||
// "roleId": "1Emy2SnEaw",
|
||
// "roleName": "大蝈蝈",
|
||
// "type": 1,
|
||
// "updatedAt": "2020-10-12T09:04:39.087Z"
|
||
if(json.seqId){
|
||
this.setServerGId(json.seqId);
|
||
this.setGoodsId(json.eid);
|
||
this.setEquipActorDataId(json.hid);
|
||
//this.setQuality(json.quality);
|
||
this.setLevel(json.lv);
|
||
this.setRandRange(json.randRange);
|
||
|
||
let dicGoods = getGoodById(this.getGoodsId());
|
||
if(dicGoods){
|
||
this.setItid(dicGoods.itid);
|
||
}
|
||
}
|
||
}
|
||
|
||
//属性的获取方法///////////////
|
||
getGoodsId(){
|
||
return this._goodsId;
|
||
}
|
||
setGoodsId(goodsId:number){
|
||
this._goodsId = goodsId;
|
||
}
|
||
|
||
getServerGId(){
|
||
return this._serverGId;
|
||
}
|
||
|
||
setServerGId(serverGId:number){
|
||
this._serverGId = serverGId;
|
||
}
|
||
|
||
getItid(){
|
||
return this._itid;
|
||
}
|
||
setItid(itid:number){
|
||
this._itid = itid;
|
||
}
|
||
|
||
getQuality(){
|
||
return this._quality;
|
||
}
|
||
setQuality(quality:number){
|
||
this._quality = quality;
|
||
}
|
||
|
||
getLevel(){
|
||
return this._lv;
|
||
}
|
||
setLevel(lv:number){
|
||
this._lv = lv;
|
||
}
|
||
|
||
getRandRange(){
|
||
return this._randRange;
|
||
}
|
||
setRandRange(val:number){
|
||
this._randRange = val;
|
||
}
|
||
|
||
getEquipActorDataId(){
|
||
return this._equipActorDataId;
|
||
}
|
||
setEquipActorDataId(dataId:number){
|
||
this._equipActorDataId = dataId;
|
||
}
|
||
|
||
//属性的获取方法 end ////////////
|
||
|
||
constructor(){
|
||
for(let i = ABI_TYPE.ABI_HP;i < ABI_TYPE.ABI_MAX;i++){
|
||
this._goodsAbility[i] = 0;
|
||
this._goodsAbilityPre[i] = 0;
|
||
}
|
||
}
|
||
|
||
/**是否物品 */
|
||
isGoods(){
|
||
if(this.getGoodsId() > 0){
|
||
return true;
|
||
}
|
||
else{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**是否装备 */
|
||
isEquipment(){
|
||
|
||
}
|
||
|
||
/**是否宝物 */
|
||
isTreasure(){
|
||
|
||
}
|
||
|
||
/**是否道具 */
|
||
isItem(){
|
||
|
||
}
|
||
|
||
getGoodsAddAbility(ability:number){
|
||
return Math.floor(this._goodsAbility[ability] * this._goodsAbilityPre[ability] / 100);
|
||
}
|
||
} |