伤害计算 需要统一

This commit is contained in:
2025-06-25 11:10:03 +08:00
parent 6b030894ef
commit b4ed42456e
6 changed files with 4952 additions and 4660 deletions

View File

@@ -6,6 +6,8 @@ import { timedCom } from '../skills/timedCom';
import { smc } from '../common/SingletonModuleComp';
import { BuffGet } from '../skills/BuffGet';
import { HeroViewComp } from './HeroViewComp';
import { FightConComp } from '../map/FightConComp';
import { BuffAttr, DebuffAttr } from '../common/config/SkillSet';
const { ccclass, property } = _decorator;
@ccclass('BuffComp')
@@ -31,23 +33,27 @@ export class BuffComp extends Component {
buff_cd:number=0;
wind_cd:number=0;
speek_time:number=0;
HeroView:HeroViewComp=null!
FIGHTCON:FightConComp=null!
start() {
this.info_init()
}
info_init(){
this.HeroView=this.node.getComponent(HeroViewComp)
this.FIGHTCON=this.node.parent.getComponent(FightConComp)
this.top_node = this.node.getChildByName("top");
this.top_node.getChildByName("lv").active=false
// this.top_node.getChildByName("hp").active=(this.node.getComponent(HeroViewComp).fac == 1 ? true : false)
this.top_node.getChildByName("sboss").active=this.node.getComponent(HeroViewComp).is_boss
this.top_node.getChildByName("sboss").active= this.HeroView.is_boss
this.top_node.getChildByName("lv").getChildByName("lv").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).lv.toFixed(0)
this.top_node.getChildByName("ihp").getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).hp.toFixed(0)
this.top_node.getChildByName("iap").getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).ap.toFixed(0)
this.top_node.getChildByName("lv").getChildByName("lv").getComponent(Label)!.string = this.HeroView.lv.toFixed(0)
this.top_node.getChildByName("ihp").getChildByName("num").getComponent(Label)!.string = this.HeroView.hp.toFixed(0)
this.top_node.getChildByName("iap").getChildByName("num").getComponent(Label)!.string = this.HeroView.ap.toFixed(0)
this.top_node.getChildByName("ihp").active=false
this.top_node.getChildByName("iap").active=false
this.vmdata_update(this.HeroView.VM_TYPE.ALL)
}
update(deltaTime: number) {
@@ -66,30 +72,74 @@ export class BuffComp extends Component {
}
hp_show(){
// if(this.node.getComponent(HeroViewComp).fac == 0) return
let hp=this.node.getComponent(HeroViewComp).hp;
let hp_max=this.node.getComponent(HeroViewComp).hp_max;
let hp=this.HeroView.hp;
let hp_max=this.HeroView.hp_max;
let hp_progress= hp/hp_max;
this.top_node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.node.getComponent(HeroViewComp).is_boss) return
if(this.HeroView.is_boss) return
this.top_node.getChildByName("hp").active = (hp == hp_max) ? false : true;
}
show_shield(val:boolean){
this.node.getChildByName("shielded").active=val
}
vmdata_update(data_type:string){
let target_key=null
let buff_key=null
if(this.HeroView.is_master) {target_key="hero";buff_key="hero"}
if(this.HeroView.is_friend) {target_key="friend";buff_key="friend"}
if(this.HeroView.is_boss) {target_key="boss";buff_key="enemy"}
if(target_key==null) return
switch(data_type){
case this.HeroView.VM_TYPE.ALL:
smc.vmdata[target_key].hp=this.HeroView.hp
smc.vmdata[target_key].hp_max=this.HeroView.hp_max
smc.vmdata[target_key].ap=this.HeroView.ap
break
case this.HeroView.VM_TYPE.HP:
smc.vmdata[target_key].hp=this.HeroView.hp
smc.vmdata[target_key].hp_max=this.HeroView.hp_max
break
case this.HeroView.VM_TYPE.OTHER:
let view_atk = 0 //临时buff
for(let i=0;i<this.HeroView.BUFF_ATKS.length;i++){
view_atk += this.HeroView.BUFF_ATKS[i].value
}
let view_deatk = 0 //临时debuff
for(let i=0;i<this.HeroView.DEBUFF_DEATKS.length;i++){
view_deatk += this.HeroView.DEBUFF_DEATKS[i].value
}
let buff=this.FIGHTCON[buff_key+"_buff"]
let debuff=this.FIGHTCON[buff_key+"_debuff"]
smc.vmdata[target_key].ap=this.HeroView.ap
smc.vmdata[target_key].equip_ap=buff.ATK+debuff.DEATK
smc.vmdata[target_key].buff_ap=view_atk
smc.vmdata[target_key].debuff_ap=view_deatk
smc.vmdata[target_key].t_ap=this.HeroView.ap*(100+buff.ATK-debuff.DEATK)/100*(100+view_atk-view_deatk)/100
break
}
}
update_info_hp(){
let ihp_node = this.top_node.getChildByName("ihp");
ihp_node.getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).hp.toFixed(0)
ihp_node.getChildByName("num").getComponent(Label)!.string = this.HeroView.hp.toFixed(0)
}
update_info_ap(){
let iap_node = this.top_node.getChildByName("iap");
iap_node.getChildByName("num").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).ap.toFixed(0)
iap_node.getChildByName("num").getComponent(Label)!.string = this.HeroView.ap.toFixed(0)
}
update_info_lv(){
let lv_node = this.top_node.getChildByName("lv");
lv_node.getChildByName("lv").getComponent(Label)!.string = this.node.getComponent(HeroViewComp).lv.toFixed(0)
lv_node.getChildByName("lv").getComponent(Label)!.string = this.HeroView.lv.toFixed(0)
}
show_wind(t:number=1){

View File

@@ -45,6 +45,8 @@ export class HeroViewComp extends CCComp {
is_boss:boolean = false;
is_big_boss:boolean = false;
is_master:boolean =false;
is_friend:boolean =false;
is_kalami:boolean =false;
ap_u:number=0;
ap_ur:number=0;
hp_up:number=0;
@@ -82,11 +84,22 @@ export class HeroViewComp extends CCComp {
Friend_alive_cd:Timer=new Timer(10)
double_dead:boolean=false
double_atked:boolean=false
DEBUFF_BURN: Array<{burn: number, count: number}> = []
BUFF_DEFS: Array<{value: number, count: number}> = []
BUFF_ATKS: Array<{value: number, count: number}> = []
BUFF_CDS: Array<{value: number, count: number}> = []
DEBUFF_BURNS: Array<{value: number, count: number}> = []
DEBUFF_DEATKS: Array<{value: number, count: number}> = []
DEBUFF_DECDS: Array<{value: number, count: number}> = []
DEBUFF_SLOW: number = 0;
DEBUFF_FROST: number = 0;
DEBUFF_STUN: number = 0;
BUFF_DEF: Array<{def: number, count: number}> = []
VM_TYPE:any={
ALL:0,
HP:1,
OTHER:2,
}
private damageQueue: Array<{
damage: number,
isCrit: boolean,
@@ -119,6 +132,13 @@ export class HeroViewComp extends CCComp {
}
/* 显示角色血量 */
this.node.getChildByName("top").getChildByName("hp").active = true;
if(!this.is_master&&this.fac==FacSet.HERO){
this.is_friend=true
}
if(this.fac==FacSet.MON&&!this.is_boss&&!this.is_big_boss){
this.is_kalami=true
}
}
update(dt: number){
if(!smc.mission.play||smc.mission.pause) return
@@ -165,6 +185,9 @@ export class HeroViewComp extends CCComp {
get isActive() {
return this.ent.has(HeroViewComp) && this.node?.isValid;
}
hide_info(){
this.node.getChildByName("top").getChildByName("ihp").active = false;
this.node.getChildByName("top").getChildByName("iap").active = false;
@@ -203,6 +226,7 @@ export class HeroViewComp extends CCComp {
this.ap += Math.floor(ap/100*this.ap);
}
this.BUFFCOMP.update_info_ap()
this.BUFFCOMP.vmdata_update(this.VM_TYPE.OTHER)
}
de_ap(ap: number,is_num:boolean=true){
@@ -213,6 +237,7 @@ export class HeroViewComp extends CCComp {
this.ap -= Math.floor(ap/100*this.ap);
}
this.BUFFCOMP.update_info_ap()
this.BUFFCOMP.vmdata_update(this.VM_TYPE.OTHER)
}
add_hp_max(hp: number=0,is_num:boolean=true){
@@ -235,6 +260,7 @@ export class HeroViewComp extends CCComp {
this.hp_max -= Math.floor(hp/100*this.hp_max);
}
this.BUFFCOMP.update_info_hp()
this.BUFFCOMP.vmdata_update(this.VM_TYPE.HP)
}
add_hp(hp: number = 0,is_num:boolean=true) {
@@ -248,6 +274,7 @@ export class HeroViewComp extends CCComp {
this.hp = this.hp_max;
}
this.BUFFCOMP.tooltip(2,hp.toFixed(0));
this.BUFFCOMP.vmdata_update(this.VM_TYPE.HP)
}
@@ -301,17 +328,6 @@ export class HeroViewComp extends CCComp {
}
do_change(){
this.BUFFCOMP.update_info_ap()
this.BUFFCOMP.update_info_hp()
this.BUFFCOMP.update_info_lv()
}
do_update(){
this.BUFFCOMP.update_info_ap()
this.BUFFCOMP.update_info_hp()
this.BUFFCOMP.update_info_lv()
}
do_dead(){
@@ -327,7 +343,7 @@ export class HeroViewComp extends CCComp {
add_debuff(type:number,deV:number,deC:number,){
switch(type){
case DebuffAttr.BURN:
this.DEBUFF_BURN.push({burn:deV,count:deC})
this.DEBUFF_BURNS.push({value:deV,count:deC})
break
case DebuffAttr.SLOW:
this.DEBUFF_SLOW+=deV
@@ -342,7 +358,7 @@ export class HeroViewComp extends CCComp {
this.is_stop=true
break
case DebuffAttr.DECD:
this.cd-=deV
this.DEBUFF_DECDS.push({value:deV,count:deC})
break
case DebuffAttr.DEHP:
this.hp_max-=deV
@@ -368,7 +384,7 @@ export class HeroViewComp extends CCComp {
add_buff(buff:number,count:number,type:number){
switch(type){
case BuffAttr.DEF:
this.BUFF_DEF.push({def:buff,count:count})
this.BUFF_DEFS.push({value:buff,count:count})
break
}
}
@@ -400,6 +416,7 @@ export class HeroViewComp extends CCComp {
}
}
this.BUFFCOMP.update_info_hp()
this.BUFFCOMP.vmdata_update(this.VM_TYPE.HP)
this.showDamage(damage, is_crit);
}
@@ -408,28 +425,40 @@ export class HeroViewComp extends CCComp {
let damage = 0;
let Burn = 0;
let def = 0;
for(let i=0;i<this.DEBUFF_BURN.length;i++){
Burn+=this.DEBUFF_BURN[i].burn
this.DEBUFF_BURN[i].count-=1
if(this.DEBUFF_BURN[i].count<=0){
this.DEBUFF_BURN.splice(i,1)
for(let i=0;i<this.DEBUFF_BURNS.length;i++){
Burn+=this.DEBUFF_BURNS[i].value
this.DEBUFF_BURNS[i].count-=1
if(this.DEBUFF_BURNS[i].count<=0){
this.DEBUFF_BURNS.splice(i,1)
}
}
for(let i=0;i<this.BUFF_DEF.length;i++){
def+=this.BUFF_DEF[i].def
this.BUFF_DEF[i].count-=1
if(this.BUFF_DEF[i].count<=0){
this.BUFF_DEF.splice(i,1)
for(let i=0;i<this.BUFF_DEFS.length;i++){
def+=this.BUFF_DEFS[i].value
this.BUFF_DEFS[i].count-=1
if(this.BUFF_DEFS[i].count<=0){
this.BUFF_DEFS.splice(i,1)
}
}
if(this.fac == FacSet.HERO ){
damage=remainingDamage*(100-(this.FIGHTCON.hero_buff.DEF+def)+(this.FIGHTCON.hero_debuff.BURN+Burn))/100
}
if(this.fac == FacSet.MON){
damage=remainingDamage*(100-(this.FIGHTCON.enemy_buff.DEF+def)+(this.FIGHTCON.enemy_debuff.BURN+Burn))/100
}
let buff_key=null
if(this.is_master) {buff_key="hero"}
if(this.is_friend) {buff_key="friend"}
if(this.is_boss) {buff_key="enemy"}
if(this.is_kalami) {buff_key="enemy"}
if(buff_key==null) return
let debuff=this.FIGHTCON[buff_key+"_debuff"]
let buff=this.FIGHTCON[buff_key+"_buff"]
damage=remainingDamage*(100-(buff.DEF+def)+(debuff.BURN+Burn))/100
return Math.floor(damage)
}
count_debuff(){
}
count_buff(){
}
check_shield(){
if(this.shield>0){
this.shield -= 1

View File

@@ -186,15 +186,36 @@ export class SkillConComp extends CCComp {
Object.values(this._timers).forEach(clearTimeout);
}
get_cd(cd:number,view:HeroViewComp){
if(view.fac==FacSet.HERO){
if(view.is_master){
return cd*(100-this.FIGHTCON.hero_buff.ATK_CD+this.FIGHTCON.hero_debuff.DECD)/100
}else{
return cd*(100-this.FIGHTCON.friend_buff.ATK_CD+this.FIGHTCON.friend_debuff.DECD)/100
let buff_key=null
if(view.is_master) {buff_key="hero"}
if(view.is_friend) {buff_key="friend"}
if(view.is_boss) {buff_key="enemy"}
if(view.is_kalami) {buff_key="enemy"}
if(buff_key==null) return
let debuff=this.FIGHTCON[buff_key+"_debuff"]
let buff=this.FIGHTCON[buff_key+"_buff"]
// 汇总DEBUFF_DECD并处理count值
let decd = 0;
for (let i = view.DEBUFF_DECDS.length - 1; i >= 0; i--) {
decd += view.DEBUFF_DECDS[i].value;
view.DEBUFF_DECDS[i].count--;
// 当count为0时移除该记录
if (view.DEBUFF_DECDS[i].count <= 0) {
view.DEBUFF_DECDS.splice(i, 1);
}
}else{
return cd*(100-this.FIGHTCON.enemy_buff.ATK_CD+this.FIGHTCON.enemy_debuff.DECD)/100
}
let bcd=0
for (let i = view.BUFF_CDS.length - 1; i >= 0; i--) {
bcd += view.BUFF_CDS[i].value;
view.BUFF_CDS[i].count--;
if (view.BUFF_CDS[i].count <= 0) {
view.BUFF_CDS.splice(i, 1);
}
}
return cd*(100-bcd-buff.ATK_CD+decd+debuff.DECD)/100
}
get_count(count:number,view:HeroViewComp){
if(view.fac==FacSet.HERO){

View File

@@ -14,7 +14,7 @@ const { ccclass, property } = _decorator;
@ccclass('FightConComp')
export class FightConComp extends Component {
//装备 及 光环效果 物品存在生效
hero_buff=getBuffNum()
friend_buff=getBuffNum()
enemy_buff=getBuffNum()
@@ -22,16 +22,10 @@ export class FightConComp extends Component {
hero_debuff=geDebuffNum()
friend_debuff=geDebuffNum()
enemy_debuff=geDebuffNum()
//注意临时buff和debuff 每种buff的值 必须都一样 多种值 战斗处理复杂 暂时放弃
temp_hero_buff = this.getInitTempBuff();
temp_friend_buff = this.getInitTempBuff();
temp_enemy_buff = this.getInitTempBuff();
temp_hero_debuff = this.getInitTempDebuff();
temp_friend_debuff = this.getInitTempDebuff();
temp_enemy_debuff = this.getInitTempDebuff();
//注意临时buff和debuff 每种buff的值 必须都一样 多种值 战斗处理复杂 暂时放弃
atk_type:number=0;
//装备特殊属性
//装备特殊属性 触发后 局内永久生效
friend_alive_cd:number=FightSet.FRIEND_LIVE_CD
atk_add_friend_atk:number=0
atk_add_friend_hp:number=0
@@ -65,9 +59,9 @@ export class FightConComp extends Component {
this.friend_alive_cd=FightSet.FRIEND_LIVE_CD
}
change_equip_special_attr(e:GameEvent,data:any){
change_equip_special_attr(e:GameEvent,data:any){
console.log("[FightConComp]:change_equip_special_attr",data)
this.atk_add_friend_atk=data.atk_add_friend_atk+(this.card_atk_add > 0 ? this.card_atk_add:0) //装备特殊属性 英雄/伙伴 攻击力增加
this.atk_add_friend_atk=data.atk_add_friend_atk+(this.card_atk_add > 0 ? this.card_atk_add:0) //装备特殊属性 英雄/伙伴 攻击力增加
this.atk_add_friend_hp=data.atk_add_friend_hp+(this.card_hp_add > 0 ? this.card_hp_add:0) //装备特殊属性 英雄/伙伴 生命值增加
this.atk_add_glod=data.atk_add_glod
this.atk_add_master_atk=data.atk_add_master_atk+(this.card_atk_add > 0 ? this.card_atk_add:0) //装备特殊属性 英雄/伙伴 攻击力增加
@@ -90,47 +84,6 @@ export class FightConComp extends Component {
this.clearAlls()
}
// 添加临时buff
addTempBuff(target: 'hero'|'ally'|'enemy'|'friend', buffId: number, value: number, count: number) {
const key = `temp_${target}_buff`;
if (!this[key][buffId]) {
this[key][buffId] = { value, count };
} else {
this[key][buffId].value += value;
this[key][buffId].count += count;
}
}
// 触发一次buff效果后减少次数
triggerTempBuff(target: 'hero'|'ally'|'enemy'|'friend', buffId: number) {
const key = `temp_${target}_buff`;
if (this[key][buffId]) {
this[key][buffId].count -= 1;
if (this[key][buffId].count <= 0) {
delete this[key][buffId];
}
}
}
// 初始化所有buff/debuff为0
private getInitTempBuff() {
const obj = {};
for (const key in BuffAttr) {
if (!isNaN(Number(key))) {
obj[Number(key)] = { value: 0, count: 0 };
}
}
return obj;
}
private getInitTempDebuff() {
const obj = {};
for (const key in DebuffAttr) {
if (!isNaN(Number(key))) {
obj[Number(key)] = { value: 0, count: 0 };
}
}
return obj;
}
private use_special_card(e:GameEvent,data:any){
console.log("[FightConComp]:use_special_card:",SuperCards[data.uuid])
@@ -214,13 +167,6 @@ export class FightConComp extends Component {
this.friend_debuff=geDebuffNum()
this.enemy_debuff=geDebuffNum()
this.temp_hero_buff = this.getInitTempBuff()
this.temp_friend_buff = this.getInitTempBuff()
this.temp_enemy_buff = this.getInitTempBuff()
this.temp_hero_debuff = this.getInitTempDebuff()
this.temp_friend_debuff = this.getInitTempDebuff()
this.temp_enemy_debuff = this.getInitTempDebuff()
this.friend_alive_cd=FightSet.FRIEND_LIVE_CD
this.atk_add_friend_atk=0
this.atk_add_friend_hp=0

View File

@@ -3,6 +3,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { BoxSet } from "../common/config/BoxSet";
import { SkillSet } from "../common/config/SkillSet";
import { smc } from "../common/SingletonModuleComp";
import { HeroViewComp } from "../hero/HeroViewComp";
import { FightConComp } from "../map/FightConComp";
import { SkillCom } from "./SkillCom";
import { instantiate, Node, Prefab, Vec3 ,tween, v3,animation,Label,resources,SpriteFrame,Sprite} from "cc";
@@ -79,17 +80,11 @@ export class Skill extends ecs.Entity {
return;
}
SComp.ap = caster.ap*config.ap/100;
if(caster.fac==0){
if(caster.is_master){
SComp.ap=Math.floor(SComp.ap*(100+FIGHTCON.hero_buff.ATK)/100);
}else{
SComp.ap=Math.floor(SComp.ap*(100+FIGHTCON.friend_buff.ATK)/100);
}
}else{
SComp.ap=Math.floor(SComp.ap*(100-FIGHTCON.enemy_buff.ATK)/100);
}
SComp.ap=(100+dmg)/100*SComp.ap // master 主将 技能额外百分比加成
SComp.ap = this.get_ap(caster,dmg)
console.log("[Skill]:caster.box_group=>",caster.box_group,config.name+"scomp.group=>",SComp.group)
// 设置技能组件属性
Object.assign(SComp, {
@@ -108,4 +103,36 @@ export class Skill extends ecs.Entity {
this.add(SComp);
}
get_ap(view:HeroViewComp,dmg:number=0){
let buff_key=null
if(view.is_master) {buff_key="hero"}
if(view.is_friend) {buff_key="friend"}
if(view.is_boss) {buff_key="enemy"}
if(view.is_kalami) {buff_key="enemy"}
if(buff_key==null) return
let debuff=this.FIGHTCON[buff_key+"_debuff"]
let buff=this.FIGHTCON[buff_key+"_buff"]
let buff_ap=(100+buff.ATK-debuff.DEATK)/100 //装备区 总加成
// 汇总DEBUFF_DECD并处理count值
let BUFF_ATK = 0;
for (let i = view.BUFF_ATKS.length - 1; i >= 0; i--) {
BUFF_ATK += view.BUFF_ATKS[i].value;
view.BUFF_ATKS[i].count--;
if (view.BUFF_ATKS[i].count <= 0) {
view.BUFF_ATKS.splice(i, 1);
}
}
let DEBUFF_DEATK = 0;
for (let i = view.DEBUFF_DEATKS.length - 1; i >= 0; i--) {
DEBUFF_DEATK += view.DEBUFF_DEATKS[i].value;
view.DEBUFF_DEATKS[i].count--;
if (view.DEBUFF_DEATKS[i].count <= 0) {
view.DEBUFF_DEATKS.splice(i, 1);
}
}
let BUFF_AP=(100-DEBUFF_DEATK+BUFF_ATK+dmg)/100 //buff区 总加成
return view.ap*buff_ap*BUFF_AP
}
}