2025-04-23 09:34:08 +08:00

485 lines
16 KiB
TypeScript

import SKDataUtil from "../gear/SKDataUtil"
import ZhenFaUtil from "../../game/core/ZhenFaUtil"
import GameConf from "../../conf/GameConf"
import ItemUtil from "../core/ItemUtil"
import { EAttrTypeL1 } from "../role/EEnum"
import GameUtil from "../core/GameUtil"
import SKLogger from "../gear/SKLogger"
enum ZhenFaPos {
type_Dry, //乾位
type_Xun, //巽位
type_Ridge, //坎位
type_Gen, //艮位
type_Kun, //坤位
type_Earth, //震位
type_Leave, //离位
type_Exchange, //兑位
type_MaxPos
}
export enum XWAttr {
JIAQIANGGONGJI = 0, //加强攻击
JIAQIANGSUDU = 1, //加强速度
JIAQIANGMEIHUO = 2, //加强魅惑
JIAQIANGJIAFANG = 3, //加强加防
JIAQIANGZHIYU = 4, //加强治愈
JIAQIANGHENGSAO = 5, //加强横扫
JIAQIANGPOJIA = 6, //加强破甲
JIAQIANGZHENJI = 7, //加强震击
HUSHISHUI = 8, //忽视抗水
HUSHILEI = 9, //忽视抗雷
HUSHIHUO = 10, //忽视抗火
HUSHIFENG = 11, //忽视抗风
HUSHIFENGYING = 12, //忽视抗封印
HUSHIHUNLUAN = 13, //忽视抗混乱
HUSHIHUNSHUI = 14, //忽视抗昏睡
HUSHIDU = 15, //忽视抗毒
HUSHIYIWANG = 16, //忽视抗遗忘
HUSHIGUIHUO = 17, //忽视抗鬼火
HUSHISANSHICHONG = 18, //忽视抗三尸
HUSHIKANGZHENGSHE = 19, //忽视抗震慑
QIANGLIKEJING = 20, //强力克金
QIANGLIKEMU = 21, //强力克木
QIANGLIKESHUI = 22, //强力克水
QIANGLIKEHUO = 23, //强力克火
QIANGLIKETU = 24, //强力克土
KANGSHUIFA = 100, //抗水法
KANGLEIFA = 101, //抗雷法
KANGHUOFA = 102, //抗火法
KANGFENGFA = 103, //抗风法
KANGFENGYING = 104, //抗封印
KANGHUNLUAN = 105, //抗混乱
KANGHUNSHUI = 106, //抗昏睡
KANGZHONGDU = 107, //抗中毒
KANGYIWANG = 108, //抗遗忘
KANGGUIHUO = 109, //抗鬼火
KANGSANSHICHONG = 110, //抗三尸虫
WULIXISHOU = 111, //物理吸收
KANGZHENGSHE = 112, //抗震慑
DUOSHAN = 113, //躲闪
}
// getAttrName(attr:number) {
// if (0 == this.oldXwItem.classify) {
// const attr_name = ['加强攻击','加强速度','加强魅惑','加强加防','加强治愈','加强横扫','加强破甲'
// ,'加强震击','忽视抗水','忽视抗雷','忽视抗火','忽视抗风','忽视抗封印','忽视抗混乱','忽视抗昏睡','忽视抗毒'
// ,'忽视抗遗忘','忽视抗鬼火','忽视抗三尸虫','忽视抗抗震慑','强力克金','强力克木','强力克水','强力克火'
// ,'强力克土']
// return attr_name[attr]
// } else {
// const attr_name = ['抗水法','抗雷法','抗火法','抗风法','抗封印','抗混乱','抗昏睡'
// ,'抗中毒','抗遗忘','抗鬼火','抗三尸虫','物理吸收','抗震慑','躲闪']
// return attr_name[attr]
// }
// }
/**
* 阵法管理
*/
export default class zhenFaMgr {
/**
* 激活位
*/
private active_index: number = 0
/**
* 激活等级
*/
private active_level: number = 0
/**
* 当前八阵图位置信息
*/
private info: any = []
/**
* 代理
*/
private delegte: any = null
/**
* 构造函数
* @param delegte
*/
constructor(delegte: any) {
this.delegte = delegte
this.active_index = 0 //todo: 可能bug
this.active_level = 0
this.info = []
}
/**
* 初始化
* @returns
*/
public init(): void {
for (var i = 0; i < ZhenFaPos.type_MaxPos; ++i) {
var info = {
index: i,
level: 0,
itemID: 0,//镶嵌在这个位置上的道具ID
valid: 0,//有效位
}
this.info.push(info)
}
}
/**
* 初始化
* @returns
*/
public initByData(data: any): void {
this.info.splice(0, this.info.length)
this.active_index = data.active_index
this.active_level = data.active_level
for (var i = 0; i < data.info.length; ++i) {
var info = {
index: data.info[i].index,
level: data.info[i].level,
itemID: data.info[i].itemID,//镶嵌在这个位置上的道具ID
valid: data.info[i].valid,
}
this.info.push(info)
}
}
/**
* 转换为JSON
*/
public toJson(): string {
var info = {
active_index: this.active_index,
active_level: this.active_level,
info: this.info,
list: this.getEquipList()
}
var str = SKDataUtil.toJson(info, "{}")
return str;
}
getEquipList() {
let list = []
for (let index = 0; index < this.info.length; index++) {
let item = this.info[index];
let xw = this.delegte.XWMgr.getXwItem(item.itemID)
if (xw == null) continue
let attr = xw.getAttrInfo()
if (attr.pos1 == item.index) {
list.push({ id: item.itemID, pos: attr.pos1, attr: attr.attr1, value: attr.value1, max: attr.max1 })
}
if (attr.pos2 == item.index) {
list.push({ id: item.itemID, pos: attr.pos2, attr: attr.attr2, value: attr.value2, max: attr.max2 })
}
if (attr.pos3 == item.index) {
list.push({ id: item.itemID, pos: attr.pos3, attr: attr.attr3, value: attr.value3, max: attr.max3 })
}
}
return list
}
getZhenFaLevelByPos(index: number) {
const size = this.info.length
for (var i = 0; i < size; ++i) {
if (index == parseInt(this.info[i].index)) {
return this.info[i].level
}
}
return 0
}
upLevel(index: number, level: number) {
const size = this.info.length
for (var i = 0; i < size; ++i) {
if (index == parseInt(this.info[i].index)) {
this.info[i].level = level
break
}
}
}
getMinLevel(): number {
let level = 0
for (let index = 0; index < this.info.length; index++) {
let zhenWei = this.info[index];
if (zhenWei.level < level || level == 0) {
level = zhenWei.level
}
}
return level
}
equipXw(index: number, itemID: number) {
var id = this.info[index].itemID
this.info[index].itemID = itemID
return id
}
isEquip(itemID: number) {
const count = this.info.length
for (var i = 0; i < count; ++i) {
if (0 != this.info[i].itemID && itemID == this.info[i].itemID) {
return true
}
}
return false
}
//获取装备位索引
getEquipIndex(itemID: number) {
const count = this.info.length
for (var i = 0; i < count; ++i) {
if (0 != this.info[i].itemID && itemID == this.info[i].itemID) {
return this.info[i].index
}
}
return -1
}
//卸下信物
dumpXw(index: number) {
if (index >= this.info.length)
return false
this.info[index].itemID = 0
return true
}
getXwItemByPos(index: number) {
return this.info[index].itemID
}
saveActiveInde(index: number) {
this.active_index = index
}
clearInfo() {
const count = this.info.length
for (var i = 0; i < count; ++i) {
this.info[i].valid = 0
this.info[i].itemID = 0
}
}
getZhenFaItem() {
var tempList = []
const count = this.info.length
for (var i = 0; i < count; ++i) {
if (0 != this.info[i].itemID) {
tempList.push(this.info[i].itemID)
}
}
return tempList
}
active(index: number, itemID: number) {
if (index < 0 || index >= this.info.length)
return false
this.info[index].valid = 1
if (0 < itemID)
this.info[index].itemID = itemID
return true
}
//是否完全激活阵法
IsFullActive(): boolean {
let config = GameUtil.game_conf.ZhenFa[this.active_index]
let tempList = this.getZhenFaItem()
SKLogger.debug("IsFullActive:" + tempList.length)
if ((config.type + 1) == tempList.length) {
return true
}
return false
}
calculateActiveZhenFa(attr: { [key: string]: number }) {
let config = GameUtil.game_conf.ZhenFa[this.active_index]
if (config.effect == null || config.effect.length == 0) return
if (this.IsFullActive() == false) return
for (let index = 0; index < config.effect.length; index++) {
if (config.target != 0) continue
let effect = config.effect[index];
if (effect == EAttrTypeL1.ATK_ADD) {
attr[EAttrTypeL1.ATK] = Math.round(attr[EAttrTypeL1.ATK] * (1 + this.getMinLevel() / 1000))
} else if (effect == EAttrTypeL1.MP_ADD) {
SKLogger.debug(`法力最大值改变:${attr[EAttrTypeL1.MP_MAX]}->${attr[EAttrTypeL1.MP_MAX] * (1 + this.getMinLevel() / 1000)}`);
attr[EAttrTypeL1.MP_MAX] = Math.round(attr[EAttrTypeL1.MP_MAX] * (1 + this.getMinLevel() / 1000))
attr[EAttrTypeL1.MP] = attr[EAttrTypeL1.MP_MAX]
} else if (effect == EAttrTypeL1.HP_ADD) {
SKLogger.debug(`气血最大值改变:${attr[EAttrTypeL1.HP_MAX]}->${attr[EAttrTypeL1.HP_MAX] * (1 + this.getMinLevel() / 1000)}`);
attr[EAttrTypeL1.HP_MAX] = Math.round(attr[EAttrTypeL1.HP_MAX] * (1 + this.getMinLevel() / 1000))
attr[EAttrTypeL1.HP] = attr[EAttrTypeL1.HP_MAX]
} else if (effect == EAttrTypeL1.SPD_ADD) {
if (attr[EAttrTypeL1.SPD] >= 0) {
attr[EAttrTypeL1.SPD] = Math.round(attr[EAttrTypeL1.SPD] * (1 + this.getMinLevel() / 1000))
} else {
attr[EAttrTypeL1.SPD] = Math.round(attr[EAttrTypeL1.SPD] * (1 - this.getMinLevel() / 1000))
}
} else {
attr[effect] += this.getMinLevel() / 10
}
}
}
calculateActiveZhenFaForPet(attr: { [key: string]: number }) {
let config = GameUtil.game_conf.ZhenFa[this.active_index]
if (config.effect == null || config.effect.length == 0) return
if (this.IsFullActive() == false) return
for (let index = 0; index < config.effect.length; index++) {
if (config.target != 1) continue
let effect = config.effect[index];
if (effect == EAttrTypeL1.ATK_ADD) {
attr[EAttrTypeL1.ATK] = Math.round(attr[EAttrTypeL1.ATK] * (1 + this.getMinLevel() / 1000))
} else if (effect == EAttrTypeL1.MP_ADD) {
SKLogger.debug(`法力最大值改变:${attr[EAttrTypeL1.MP]}->${attr[EAttrTypeL1.MP] * (1 + this.getMinLevel() / 1000)}`);
attr[EAttrTypeL1.MP] = Math.round(attr[EAttrTypeL1.MP] * (1 + this.getMinLevel() / 1000))
} else if (effect == EAttrTypeL1.HP_ADD) {
SKLogger.debug(`气血最大值改变:${attr[EAttrTypeL1.HP]}->${attr[EAttrTypeL1.HP] * (1 + this.getMinLevel() / 1000)}`);
attr[EAttrTypeL1.HP] = Math.round(attr[EAttrTypeL1.HP] * (1 + this.getMinLevel() / 1000))
} else if (effect == EAttrTypeL1.SPD_ADD) {
if (attr[EAttrTypeL1.SPD] >= 0) {
attr[EAttrTypeL1.SPD] = Math.round(attr[EAttrTypeL1.SPD] * (1 + this.getMinLevel() / 1000))
} else {
attr[EAttrTypeL1.SPD] = Math.round(attr[EAttrTypeL1.SPD] * (1 - this.getMinLevel() / 1000))
}
} else {
attr[effect] += this.getMinLevel() / 10
}
}
}
calculateItem(item: any, attr: { [key: string]: number }) {
let data = ItemUtil.getItemData(item.id)
let type = data.classify * 100 + item.attr
let EAttrType = 0
if (type == XWAttr.JIAQIANGGONGJI) {
EAttrType = EAttrTypeL1.ATK
}
if (type == XWAttr.JIAQIANGSUDU) {
EAttrType = EAttrTypeL1.SPD_ADD_EHAN
}
if (type == XWAttr.JIAQIANGMEIHUO) {
EAttrType = EAttrTypeL1.CHARM_ADD
}
if (type == XWAttr.JIAQIANGJIAFANG) {
EAttrType = EAttrTypeL1.DEFEND_ADD_EHAN
}
if (type == XWAttr.JIAQIANGZHIYU) {
EAttrType = EAttrTypeL1.CURE_EHAN
}
if (type == XWAttr.JIAQIANGHENGSAO) {
EAttrType = EAttrTypeL1.SWEEP_EHAN
}
if (type == XWAttr.JIAQIANGPOJIA) {
EAttrType = EAttrTypeL1.BREAK_EHAN
}
if (type == XWAttr.JIAQIANGZHENJI) {
EAttrType = EAttrTypeL1.THUD_EHAN
}
if (type == XWAttr.HUSHISHUI) {
EAttrType = EAttrTypeL1.HK_WATER
}
if (type == XWAttr.HUSHILEI) {
EAttrType = EAttrTypeL1.HK_THUNDER
}
if (type == XWAttr.HUSHIHUO) {
EAttrType = EAttrTypeL1.HK_FIRE
}
if (type == XWAttr.HUSHIFENG) {
EAttrType = EAttrTypeL1.HK_WIND
}
if (type == XWAttr.HUSHIFENGYING) {
EAttrType = EAttrTypeL1.HK_SEAL
}
if (type == XWAttr.HUSHIHUNLUAN) {
EAttrType = EAttrTypeL1.HK_CONFUSION
}
if (type == XWAttr.HUSHIHUNSHUI) {
EAttrType = EAttrTypeL1.HK_SLEEP
}
if (type == XWAttr.HUSHIDU) {
EAttrType = EAttrTypeL1.HK_POISON
}
if (type == XWAttr.HUSHIYIWANG) {
EAttrType = EAttrTypeL1.HK_FORGET
}
if (type == XWAttr.HUSHIGUIHUO) {
EAttrType = EAttrTypeL1.HK_WILDFIRE
}
if (type == XWAttr.HUSHISANSHICHONG) {
EAttrType = EAttrTypeL1.HK_BLOODRETURN
}
if (type == XWAttr.HUSHIKANGZHENGSHE) {
EAttrType = EAttrTypeL1.HK_DETER
}
if (type == XWAttr.QIANGLIKEJING) {
EAttrType = EAttrTypeL1.S_GOLD
}
if (type == XWAttr.QIANGLIKEMU) {
EAttrType = EAttrTypeL1.S_WOOD
}
if (type == XWAttr.QIANGLIKESHUI) {
EAttrType = EAttrTypeL1.S_WATER
}
if (type == XWAttr.QIANGLIKEHUO) {
EAttrType = EAttrTypeL1.S_FIRE
}
if (type == XWAttr.QIANGLIKETU) {
EAttrType = EAttrTypeL1.S_SOIL
}
if (type == XWAttr.KANGSHUIFA) {
EAttrType = EAttrTypeL1.K_WATER
}
if (type == XWAttr.KANGLEIFA) {
EAttrType = EAttrTypeL1.K_THUNDER
}
if (type == XWAttr.KANGHUOFA) {
EAttrType = EAttrTypeL1.K_FIRE
}
if (type == XWAttr.KANGFENGFA) {
EAttrType = EAttrTypeL1.K_WIND
}
if (type == XWAttr.KANGFENGYING) {
EAttrType = EAttrTypeL1.K_SEAL
}
if (type == XWAttr.KANGHUNLUAN) {
EAttrType = EAttrTypeL1.K_CONFUSION
}
if (type == XWAttr.KANGHUNSHUI) {
EAttrType = EAttrTypeL1.K_SLEEP
}
if (type == XWAttr.KANGZHONGDU) {
EAttrType = EAttrTypeL1.K_POISON
}
if (type == XWAttr.KANGYIWANG) {
EAttrType = EAttrTypeL1.K_FORGET
}
if (type == XWAttr.KANGGUIHUO) {
EAttrType = EAttrTypeL1.K_WILDFIRE
}
if (type == XWAttr.KANGSANSHICHONG) {
EAttrType = EAttrTypeL1.K_BLOODRETURN
}
if (type == XWAttr.WULIXISHOU) {
EAttrType = EAttrTypeL1.PHY_GET
}
if (type == XWAttr.KANGZHENGSHE) {
EAttrType = EAttrTypeL1.K_DETER
}
if (type == XWAttr.DUOSHAN) {
EAttrType = EAttrTypeL1.PHY_DODGE
}
// attr[EAttrType] = Math.floor(attr[EAttrType] * (1 + item.value / 1000));
attr[EAttrType] = Math.floor(attr[EAttrType] + item.value / 10)
}
calculateZhenfaAttr(attr: { [key: number]: number }) {
let list = this.getEquipList()
for (let index = 0; index < list.length; index++) {
let item = list[index];
this.calculateItem(item, attr)
}
this.calculateActiveZhenFa(attr)
}
}