2025-04-24 17:03:28 +08:00

273 lines
11 KiB
JavaScript

import ExpUtil from "../ts/core/ExpUtil";
import GameModel from "../ts/core/GameModel";
import {EAttrTypeL1,EAttrTypeL2} from "../ts/core/EEnum";
import SKDataUtil from "../ts/gear_2.3.4/util/SKDataUtil";
var PracticeMgr = require('./PetPracticeMgr');
class PetLogic {
constructor() {}
init() {
this.petid = 0; //數據庫中的寵物id
this.resid = 0; //資源id
this.dataid = 0;
this.aptitude=0;
this.intro = ''; //介紹
this.name = '';
this.relive = 0;
this.level = 0;
this.grade = 0;
this.skill = [];
this.shenSkill = 0;
this.rate = 0;
this.hp = 0;
this.mp = 0;
this.atk = 0;
this.spd = 0;
this.cur_aptitude = 0;
this.cur_hp = 0;
this.cur_mp = 0;
this.cur_atk = 0;
this.cur_spd = 0;
this.exp = 0;
this.maxexp = 0;
this.ppoint = {};
this.dpoint = {};
this.wuxing = {};
this.xexp = 0;
this.xlevel = 0;
this.longgu = 0;
this.qianneng = 0;
this.ppointT = {};
this.dpointT = {};
this.xiulianfree = 0;
this.xiulianleft = 0;
this.xmaxexp = 0;
this.maxskillcnt = 4;
this.petcolor = -1;
this.qinmi = 0;
this.maxRate = 0;
}
createPet(petid) {
// this.setInfo(info);
GameModel.send('c2s_create_pet', {
petid: petid,
});
}
setInfo(info) {
this.init();
this.petinfo = info;
if (this.petinfo == null) {
return;
}
let skilllist = {};
if(info.petid){
this.petid=info.petid;
}
if(info.dataid){
this.dataid = info.dataid;
}
if(info.resid){
this.resid = info.resid;
}
if(info.intro){
this.intro = info.intro;
}
if(info.name){
this.name = info.name;
}
if(info.relive){
this.relive = info.relive;
}
if(info.level){
this.level = info.level;
}
if(info.grade){
this.grade = info.grade;
}
if(info.skill){
skilllist = SKDataUtil.jsonBy(info.skill);
}
if(info.shenskill){
this.shenSkill = info.shenskill;
}
if(info.rate){
this.rate=info.rate / 10000;
}
if(info.aptitude){
this.aptitude=info.aptitude;
}
if(info.hp){
this.hp = info.hp;
}
if(info.mp){
this.mp = info.mp;
}
if(info.atk){
this.atk = info.atk;
}
if(info.spd){
this.spd = info.spd;
}
if(info.exp){
this.exp = info.exp;
}
if(info.ppoint){
this.ppoint = SKDataUtil.jsonBy(info.ppoint);
}
if(info.dpoint){
this.dpoint = SKDataUtil.jsonBy(info.dpoint);
}
info.wuxing && (this.wuxing = SKDataUtil.jsonBy(info.wuxing));
info.xexp && (this.xexp = SKDataUtil.jsonBy(info.xexp));
info.xlevel && (this.xlevel = SKDataUtil.jsonBy(info.xlevel));
info.longgu && (this.longgu = info.longgu);
info.maxskillcnt && (this.maxskillcnt = info.maxskillcnt);
info.color && (this.petcolor = info.color);
info.qinmi && (this.qinmi = info.qinmi);
info.maxrate && (this.maxRate = info.maxrate / 10000);
if (info.attr1) {
this.attr1 = SKDataUtil.jsonBy(info.attr1);
this.cur_aptitude = this.attr1[EAttrTypeL1.Aptitude];
this.cur_hp = this.attr1[EAttrTypeL1.HP];
this.cur_mp = this.attr1[EAttrTypeL1.MP];
this.cur_atk = this.attr1[EAttrTypeL1.ATK];
this.cur_spd = this.attr1[EAttrTypeL1.SPD];
}
this.petinfo.skill = skilllist;
for (let key in skilllist) {
if (SKDataUtil.hasProperty(skilllist,key)){
this.skill.push(key);
}
}
this.maxexp = ExpUtil.getSummonUpGradeExp(this.relive, this.level);
this.xmaxexp = PracticeMgr.GetUpdateHunPo(info.xlevel);
this.initPoint();
this.calculateAttribute();
}
initPoint() {
for(let key in EAttrTypeL2){
let value=SKDataUtil.toNumber(key);
if(isNaN(value)){
continue;
}
let element=this.ppoint[value];
if(element==null){
this.ppoint[value]=0;
}
this.ppoint[value]+=this.petinfo.level;
this.ppointT[value]=0;
}
(this.dpoint[EAttrTypeL1.K_SEAL] == null) && (this.dpoint[EAttrTypeL1.K_SEAL] = 0);
(this.dpoint[EAttrTypeL1.K_CONFUSION] == null) && (this.dpoint[EAttrTypeL1.K_CONFUSION] = 0);
(this.dpoint[EAttrTypeL1.K_SLEEP] == null) && (this.dpoint[EAttrTypeL1.K_SLEEP] = 0);
(this.dpoint[EAttrTypeL1.K_FORGET] == null) && (this.dpoint[EAttrTypeL1.K_FORGET] = 0);
this.dpointT[EAttrTypeL1.K_SEAL] = 0;
this.dpointT[EAttrTypeL1.K_CONFUSION] = 0;
this.dpointT[EAttrTypeL1.K_SLEEP] = 0;
this.dpointT[EAttrTypeL1.K_FORGET] = 0;
(this.dpoint[EAttrTypeL1.K_WIND] == null) && (this.dpoint[EAttrTypeL1.K_WIND] = 0);
(this.dpoint[EAttrTypeL1.K_WATER] == null) && (this.dpoint[EAttrTypeL1.K_WATER] = 0);
(this.dpoint[EAttrTypeL1.K_FIRE] == null) && (this.dpoint[EAttrTypeL1.K_FIRE] = 0);
(this.dpoint[EAttrTypeL1.K_POISON] == null) && (this.dpoint[EAttrTypeL1.K_POISON] = 0);
(this.dpoint[EAttrTypeL1.K_THUNDER] == null) && (this.dpoint[EAttrTypeL1.K_THUNDER] = 0);
(this.dpoint[EAttrTypeL1.K_WILDFIRE] == null) && (this.dpoint[EAttrTypeL1.K_WILDFIRE] = 0);
(this.dpoint[EAttrTypeL1.K_BLOODRETURN] == null) && (this.dpoint[EAttrTypeL1.K_BLOODRETURN] = 0);
(this.dpoint[EAttrTypeL1.K_DETER] == null) && (this.dpoint[EAttrTypeL1.K_DETER] = 0);
this.dpointT[EAttrTypeL1.K_WIND] = 0;
this.dpointT[EAttrTypeL1.K_WATER] = 0;
this.dpointT[EAttrTypeL1.K_FIRE] = 0;
this.dpointT[EAttrTypeL1.K_POISON] = 0;
this.dpointT[EAttrTypeL1.K_THUNDER] = 0;
this.dpointT[EAttrTypeL1.K_WILDFIRE] = 0;
this.dpointT[EAttrTypeL1.K_BLOODRETURN] = 0;
this.dpointT[EAttrTypeL1.K_DETER] = 0;
(this.dpoint[EAttrTypeL1.PHY_GET] == null) && (this.dpoint[EAttrTypeL1.PHY_GET] = 0);
(this.dpoint[EAttrTypeL1.PHY_HIT] == null) && (this.dpoint[EAttrTypeL1.PHY_HIT] = 0);
(this.dpoint[EAttrTypeL1.PHY_DODGE] == null) && (this.dpoint[EAttrTypeL1.PHY_DODGE] = 0);
(this.dpoint[EAttrTypeL1.PHY_COMBO] == null) && (this.dpoint[EAttrTypeL1.PHY_COMBO] = 0);
(this.dpoint[EAttrTypeL1.PHY_COMBO_PROB] == null) && (this.dpoint[EAttrTypeL1.PHY_COMBO_PROB] = 0);
(this.dpoint[EAttrTypeL1.PHY_DEADLY] == null) && (this.dpoint[EAttrTypeL1.PHY_DEADLY] = 0);
(this.dpoint[EAttrTypeL1.PHY_BREAK] == null) && (this.dpoint[EAttrTypeL1.PHY_BREAK] = 0);
(this.dpoint[EAttrTypeL1.PHY_BREAK_PROB] == null) && (this.dpoint[EAttrTypeL1.PHY_BREAK_PROB] = 0);
(this.dpoint[EAttrTypeL1.PHY_REBOUND_PROB] == null) && (this.dpoint[EAttrTypeL1.PHY_REBOUND_PROB] = 0);
(this.dpoint[EAttrTypeL1.PHY_REBOUND] == null) && (this.dpoint[EAttrTypeL1.PHY_REBOUND] = 0);
this.dpointT[EAttrTypeL1.PHY_GET] = 0;
this.dpointT[EAttrTypeL1.PHY_HIT] = 0;
this.dpointT[EAttrTypeL1.PHY_DODGE] = 0;
this.dpointT[EAttrTypeL1.PHY_COMBO] = 0;
this.dpointT[EAttrTypeL1.PHY_COMBO_PROB] = 0;
this.dpointT[EAttrTypeL1.PHY_DEADLY] = 0;
this.dpointT[EAttrTypeL1.PHY_BREAK] = 0;
this.dpointT[EAttrTypeL1.PHY_BREAK_PROB] = 0;
this.dpointT[EAttrTypeL1.PHY_REBOUND_PROB] = 0;
this.dpointT[EAttrTypeL1.PHY_REBOUND] = 0;
}
calculateAttribute() {
this.calculateProperty();
this.calculateKang();
// this.calPassiveSkillAttr();
}
calculateProperty() {
let qianneng=this.level * 8 - this.ppoint[EAttrTypeL1.BONE] - this.ppoint[EAttrTypeL1.SPIRIT] - this.ppoint[EAttrTypeL1.STRENGTH] - this.ppoint[EAttrTypeL1.DEXTERITY];
this.qianneng = Math.max(0,qianneng);
}
calculateKang() {
this.dfengyin = this.attr1[EAttrTypeL1.K_SEAL]; // this.dpoint[EAttrTypeL1.K_SEAL] * 4;
this.dhunlun = this.attr1[EAttrTypeL1.K_CONFUSION]; // this.dpoint[EAttrTypeL1.K_CONFUSION] * 4;
this.dhunshui = this.attr1[EAttrTypeL1.K_SLEEP]; // this.dpoint[EAttrTypeL1.K_SLEEP] * 4;
this.dyiwang = this.attr1[EAttrTypeL1.K_FORGET]; // this.dpoint[EAttrTypeL1.K_FORGET] * 4;
this.dfeng = this.attr1[EAttrTypeL1.K_WIND]; // this.dpoint[EAttrTypeL1.K_WIND] * 4;
this.dshui = this.attr1[EAttrTypeL1.K_WATER]; // this.dpoint[EAttrTypeL1.K_WATER] * 4;
this.dhuo = this.attr1[EAttrTypeL1.K_FIRE]; // this.dpoint[EAttrTypeL1.K_FIRE] * 4;
this.ddu = this.attr1[EAttrTypeL1.K_POISON]; // this.dpoint[EAttrTypeL1.K_POISON] * 4;
this.dlei = this.attr1[EAttrTypeL1.K_THUNDER]; // this.dpoint[EAttrTypeL1.K_THUNDER] * 4;
this.dguihuo = this.attr1[EAttrTypeL1.K_WILDFIRE]; // this.dpoint[EAttrTypeL1.K_WILDFIRE] * 4;
this.dsanshi = this.attr1[EAttrTypeL1.K_BLOODRETURN]; // this.dpoint[EAttrTypeL1.K_BLOODRETURN] * 4;
this.dzhenshe = this.attr1[EAttrTypeL1.K_DETER];
this.pxishou = this.attr1[EAttrTypeL1.K_PHY_GET]; // this.dpoint[EAttrTypeL1.PHY_GET] * 3;
this.pmingzhong = this.attr1[EAttrTypeL1.PHY_HIT]; // this.dpoint[EAttrTypeL1.PHY_HIT] * 1.5;
this.pshanbi = this.attr1[EAttrTypeL1.PHY_DODGE]; // this.dpoint[EAttrTypeL1.PHY_DODGE] * 1.5;
this.plianji = 3 + this.attr1[EAttrTypeL1.PHY_COMBO]; // this.dpoint[EAttrTypeL1.PHY_COMBO] * 1;
this.plianjilv = this.attr1[EAttrTypeL1.PHY_COMBO_PROB]; // this.dpoint[EAttrTypeL1.PHY_COMBO_PROB] * 1.5;
this.pkuangbao = this.attr1[EAttrTypeL1.PHY_DEADLY]; // this.dpoint[EAttrTypeL1.PHY_DEADLY] * 1.5;
this.ppofang = this.attr1[EAttrTypeL1.PHY_BREAK]; // this.dpoint[EAttrTypeL1.PHY_BREAK] * 3;
this.ppofanglv = this.attr1[EAttrTypeL1.PHY_BREAK_PROB]; // this.dpoint[EAttrTypeL1.PHY_BREAK_PROB] * 3;
this.pfanzhenlv = this.attr1[EAttrTypeL1.PHY_REBOUND_PROB]; // this.dpoint[EAttrTypeL1.PHY_REBOUND_PROB] * 4;
this.pfanzhen = this.attr1[EAttrTypeL1.PHY_REBOUND]; // this.dpoint[EAttrTypeL1.PHY_REBOUND] * 4;
this.xiulianfree = PracticeMgr.GetLevelPoint(this.petinfo.relive, this.petinfo.xlevel);
this.xiulianleft = this.xiulianfree;
for (let key in this.dpoint) {
this.xiulianleft -= this.dpoint[key];
}
}
getMaxAddPoint(type) {
return PracticeMgr.GetMaxAddPoint(this.relive, type);
}
getMaxLongGu() {
if (this.relive == 0) return 2;
if (this.relive == 1) return 4;
if (this.relive == 2) return 7;
if (this.relive == 3) return 12;
if (this.relive == 4) return 12;
}
}
module.exports = {
PetLogic
};