890 lines
29 KiB
TypeScript
890 lines
29 KiB
TypeScript
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color, BoxCollider2D} from "cc";
|
||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||
import { HeroSpine } from "./HeroSpine";
|
||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||
import { smc } from "../common/SingletonModuleComp";
|
||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||
import { BuffAttr, DebuffAttr, SkillSet, TGroup, TType } from "../common/config/SkillSet";
|
||
import { BuffComp } from "./BuffComp";
|
||
import { oops } from "db://oops-framework/core/Oops";
|
||
import { GameEvent } from "../common/config/GameEvent";
|
||
import { EquipSpecialAttr } from "../common/config/Equips";
|
||
import { FightSet, getExpDrops, getStoneDrops, TooltipTypes } from "../common/config/Mission";
|
||
import { getApIncrease, getHpIncrease, getUpExp, HeroInfo, HeroPos } from "../common/config/heroSet";
|
||
import { FriendModelComp } from "./FriendModel";
|
||
import { MasterModelComp } from "./MasterModel";
|
||
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
||
import { EnhancementType } from "../common/config/LevelUp";
|
||
const { ccclass, property } = _decorator;
|
||
|
||
|
||
/** 角色显示组件 */
|
||
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
|
||
@ecs.register('HeroView', false) // 定义为 ECS 组件
|
||
export class HeroViewComp extends CCComp {
|
||
BUFFCOMP:BuffComp=null!
|
||
atk_heart:boolean=false;
|
||
as: HeroSpine = null!
|
||
status:String = "idle"
|
||
hero_uuid:number = 1001;
|
||
hero_name : string = "hero";
|
||
fight_pos:number=0;
|
||
lv:number =1;
|
||
exp:number = 0;
|
||
next_exp:number = 100;
|
||
scale: number = 1; /** 角色阵营 1:hero -1 :mon */
|
||
type: number = 0; /**角色类型 0近战-需要贴身 1远程-保持距离 2辅助 */
|
||
fac:number=0; //阵营 0:hero 1:monster
|
||
|
||
vmHero:any={}
|
||
|
||
/**
|
||
* 获取当前血量 - 根据阵营选择正确的变量
|
||
*/
|
||
get currentHp(): number {
|
||
if (this.fac === FacSet.HERO) {
|
||
return this.vmHero.hp || 0;
|
||
}
|
||
return this.hp;
|
||
}
|
||
|
||
/**
|
||
* 设置当前血量 - 根据阵营选择正确的变量
|
||
*/
|
||
set currentHp(value: number) {
|
||
if (this.fac === FacSet.HERO) {
|
||
this.vmHero.hp = value;
|
||
} else {
|
||
this.hp = value;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取最大血量 - 根据阵营选择正确的变量
|
||
*/
|
||
get currentHpMax(): number {
|
||
if (this.fac === FacSet.HERO) {
|
||
return this.vmHero.hp_max || 0;
|
||
}
|
||
return this.hp_max;
|
||
}
|
||
|
||
/**
|
||
* 设置最大血量 - 根据阵营选择正确的变量
|
||
*/
|
||
set currentHpMax(value: number) {
|
||
if (this.fac === FacSet.HERO) {
|
||
this.vmHero.hp_max = value;
|
||
} else {
|
||
this.hp_max = value;
|
||
}
|
||
}
|
||
|
||
box_group:number = BoxSet.HERO;
|
||
|
||
is_dead:boolean = false; //是否摧毁
|
||
is_count_dead:boolean = false; //是否计数死亡
|
||
is_stop:boolean = false;
|
||
is_atking:boolean = false;
|
||
|
||
is_boss:boolean = false;
|
||
is_big_boss:boolean = false;
|
||
is_master:boolean =false;
|
||
is_friend:boolean =false;
|
||
is_kalami:boolean =false;
|
||
|
||
hp: number = 100; /** 血量 */
|
||
hp_max: number = 100; /** 最大血量 */
|
||
hp_buff:number=0;
|
||
hp_base:number=0;
|
||
|
||
pwt:Timer = new Timer(1); //计时器
|
||
ap: number = 10; /**攻击力 */
|
||
ap_buff:number=0;
|
||
ap_base:number=0;
|
||
// atk_speed: number = 1;
|
||
cd_base:number=1.3;
|
||
cd: number = 1.3; /**攻击速度 攻击间隔 */
|
||
cd_buff:number=0;
|
||
dis: number = 80;
|
||
at: number = 0; /** 冷却时间 */
|
||
atk_skill:number=0;
|
||
skills:any[]=[]
|
||
puncture:number=0; //穿刺敌人伤害后方敌人个数
|
||
puncture_damage:number=0; //后伤害加成
|
||
def: number = 0; //免伤
|
||
vun: number = 0; //易伤
|
||
burn_count:number=0; //易伤次数
|
||
burn_value:number=0; //易伤值
|
||
stun_time:number=0; //眩晕加成
|
||
stun_ratto:number=0; //攻击眩晕概率加成
|
||
stun_no:boolean=false; //眩晕免疫
|
||
dod: number = 0; //闪避率
|
||
dod_no:boolean=false;
|
||
crit:number=0; //暴击率
|
||
crit_no:boolean=false; //暴击免疫
|
||
crit_d:number=0; //暴击伤害
|
||
wfuny:number=0; //风怒概率
|
||
frost_ratto:number=0; //冰冻概率
|
||
frost_time:number=0; //冰冻时间
|
||
frost_no:boolean=false; //冰冻免疫
|
||
knockback:number=0; //击退概率
|
||
knockback_no:boolean=false; //击退免疫
|
||
shield:number = 0; //护盾,免伤1次减1
|
||
speed: number = 100; /** 角色移动速度 */
|
||
ospeed: number = 100; /** 角色初始速度 */
|
||
reflect:number=0; //反射伤害比率
|
||
lifesteal:number=0; //吸血比率
|
||
|
||
atk_count: number = 0;
|
||
atked_count: number = 0;
|
||
atk_add_count:number=0;
|
||
stop_cd: number = 0; /*停止倒计时*/
|
||
speek_time:number = 0;
|
||
is_stop_temp:boolean = false
|
||
double_atked:boolean=false
|
||
atk_add_master_atk:number=0
|
||
atk_add_master_hp:number=0
|
||
buff_debuff_down:number=0
|
||
skill_dmg:number=0
|
||
|
||
BUFF_DEFS: Array<{value: number, duration: number}> = [] //防御提升
|
||
BUFF_ATKS: Array<{value: number, duration: number}> = [] //攻击提升
|
||
BUFF_CDS: Array<{value: number, duration: number}> = [] //攻击加速
|
||
BUFF_DEDOWN:Array<{value: number, duration: number}> = [] //debuff 概率降低
|
||
|
||
DEBUFF_BURNS: Array<{value: number, duration: number}> = [] //易伤
|
||
DEBUFF_DEATKS: Array<{value: number, duration: number}> = [] //减攻击
|
||
DEBUFF_DECDS: Array<{value: number, duration: number}> = [] //减攻击速度
|
||
|
||
DEBUFF_SLOW: number = 0; //减速
|
||
DEBUFF_FROST: number = 0; //冰冻
|
||
DEBUFF_STUN: number = 0; //眩晕
|
||
|
||
DEBUFF_VALUE:number=0; //debuff 增益值
|
||
DEBUFF_COUNT:number=0; //debuff 持续次数
|
||
DEBUFF_UP:number=0; //debuff 概率提升
|
||
|
||
TALENT:any={
|
||
[BuffAttr.ATK]:0,
|
||
[BuffAttr.CRITICAL]:0,
|
||
[BuffAttr.CRITICAL_DMG]:0,
|
||
[BuffAttr.DODGE]:0,
|
||
[BuffAttr.DEBUFF_COUNT]:0,
|
||
[BuffAttr.HP]:0,
|
||
[BuffAttr.DEF]:0,
|
||
[BuffAttr.PUNCTURE]:0,
|
||
[BuffAttr.ATK_CD]:0,
|
||
[BuffAttr.SKILL_CD]:0,
|
||
[BuffAttr.FROST_RATIO]:0,
|
||
[BuffAttr.KNOCKBACK]:0,
|
||
[BuffAttr.STUN_RATTO]:0,
|
||
[BuffAttr.REFLECT]:0,
|
||
[BuffAttr.LIFESTEAL]:0,
|
||
}
|
||
|
||
|
||
private damageQueue: Array<{
|
||
damage: number,
|
||
isCrit: boolean,
|
||
delay: number,
|
||
anm:string,
|
||
}> = [];
|
||
private isProcessingDamage: boolean = false;
|
||
private damageInterval: number = 0.01; // 伤害数字显示间隔
|
||
|
||
private timer:Timer=new Timer(1);
|
||
|
||
onLoad() {
|
||
this.as = this.getComponent(HeroSpine);
|
||
//console.log("[HeroViewComp]:hero view comp ",this.FIGHTCON)
|
||
this.on(GameEvent.EXPUP,this.exp_up,this)
|
||
this.on(GameEvent.HeroLvUp,this.to_update_lv,this)
|
||
const collider = this.node.getComponent(BoxCollider2D);
|
||
this.scheduleOnce(()=>{
|
||
if (collider) collider.enabled = true; // 先禁用
|
||
},1)
|
||
// let anm = this.node.getChildByName("anm")
|
||
// anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
|
||
}
|
||
/** 视图层逻辑代码分离演示 */
|
||
start () {
|
||
this.as.idle()
|
||
this.BUFFCOMP=this.node.getComponent(BuffComp);
|
||
// this.update_vmdata()
|
||
/** 方向 */
|
||
this.node.setScale(this.scale,1);
|
||
this.node.getChildByName("top").setScale(this.scale,1);
|
||
if(this.is_boss){
|
||
this.node.getChildByName("top").position=v3(this.node.position.x,this.node.position.y+100,0)
|
||
}
|
||
/* 显示角色血量 */
|
||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||
|
||
}
|
||
update_vmdata(){
|
||
if(this.is_master) this.BUFFCOMP.vmdata_update()
|
||
}
|
||
update(dt: number){
|
||
if(!smc.mission.play||smc.mission.pause) return
|
||
// if(this.is_dead) {
|
||
// this.ent.destroy();
|
||
// return
|
||
// }
|
||
|
||
if(this.timer.update(dt)){
|
||
// this.add_ap(10)
|
||
};
|
||
if(this.DEBUFF_FROST > 0){
|
||
this.DEBUFF_FROST -=dt;
|
||
}
|
||
if(this.DEBUFF_STUN > 0){
|
||
this.DEBUFF_STUN -=dt;
|
||
}
|
||
|
||
// 更新所有按时间减少的buff和debuff
|
||
this.updateBuffsAndDebuffs(dt);
|
||
this.in_stop(dt);
|
||
// 处理伤害队列
|
||
this.processDamageQueue();
|
||
}
|
||
|
||
|
||
|
||
get isActive() {
|
||
return this.ent.has(HeroViewComp) && this.node?.isValid;
|
||
}
|
||
|
||
|
||
|
||
hide_info(){
|
||
|
||
}
|
||
//状态切换
|
||
status_change(type:string){
|
||
this.status=type
|
||
if(type == "idle"){
|
||
this.as.idle()
|
||
// this.as.change_default("idle")
|
||
}
|
||
if(type == "move"){
|
||
this.as.move()
|
||
// this.as.change_default("move")
|
||
}
|
||
}
|
||
|
||
add_shield(shield:number){
|
||
this.shield =shield
|
||
if(this.shield>6) this.shield=6
|
||
if(this.shield>0) this.BUFFCOMP.show_shield(true)
|
||
}
|
||
change_wfuny(wfuny: number){
|
||
this.wfuny+=wfuny
|
||
if(this.wfuny<0) this.wfuny=0
|
||
// this.update_vmdata()
|
||
}
|
||
change_puncture(puncture: number){
|
||
this.puncture+=puncture
|
||
if(this.puncture<1) this.puncture=1
|
||
// this.update_vmdata()
|
||
}
|
||
change_puncture_damage(puncture_damage: number){
|
||
this.puncture_damage+=puncture_damage
|
||
if(this.puncture_damage<0) this.puncture_damage=0
|
||
if(this.puncture_damage>80) this.puncture_damage=80
|
||
// this.update_vmdata()
|
||
}
|
||
change_dodge(dodge: number){
|
||
this.dod+=dodge
|
||
if(this.dod<0) this.dod=0
|
||
if(this.dod>90) this.dod=90
|
||
// this.update_vmdata()
|
||
}
|
||
change_frost_ratto(frost_ratto: number){
|
||
this.frost_ratto+=frost_ratto
|
||
if(this.frost_ratto<0) this.frost_ratto=0
|
||
if(this.frost_ratto>90) this.frost_ratto=90
|
||
// this.update_vmdata()
|
||
}
|
||
|
||
change_knockback(knockback: number){
|
||
this.knockback+=knockback
|
||
if(this.knockback<0) this.knockback=0
|
||
// this.update_vmdata()
|
||
}
|
||
|
||
change_stun_ratto(stun_ratto: number){
|
||
this.stun_ratto+=stun_ratto
|
||
if(this.stun_ratto<0) this.stun_ratto=0
|
||
// this.update_vmdata()
|
||
}
|
||
|
||
change_def(def: number){
|
||
this.def+=def
|
||
if(this.def>90) this.def=90
|
||
if(this.def<0) this.def=0
|
||
// this.update_vmdata()
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.defup,def.toFixed(0));
|
||
}
|
||
change_crit(crit: number){
|
||
this.crit+=crit
|
||
if(this.crit<0) this.crit=0
|
||
// this.update_vmdata()
|
||
}
|
||
change_crit_d(crit_d: number){
|
||
this.crit_d+=crit_d
|
||
if(this.crit_d<0) this.crit_d=0
|
||
// this.update_vmdata()
|
||
}
|
||
change_reflect(reflect: number){
|
||
this.reflect+=reflect
|
||
if(this.reflect<0) this.reflect=0
|
||
// this.update_vmdata()
|
||
}
|
||
change_lifesteal(lifesteal: number){
|
||
this.lifesteal+=lifesteal
|
||
if(this.lifesteal<0) this.lifesteal=0
|
||
// this.update_vmdata()
|
||
}
|
||
|
||
check_atrr(buff:BuffAttr){
|
||
switch(buff){
|
||
case BuffAttr.ATK:
|
||
return Math.floor(this.ap_base*(100+this.ap_buff+this.TALENT[BuffAttr.ATK])/100)
|
||
case BuffAttr.ATK_CD:
|
||
return this.cd_base/((this.cd_buff+this.TALENT[BuffAttr.ATK_CD])/100+1)
|
||
case BuffAttr.HP:
|
||
return Math.floor(this.hp_base*(100+this.hp_buff+this.TALENT[BuffAttr.HP])/100)
|
||
}
|
||
}
|
||
|
||
count_atrr(buff:BuffAttr){
|
||
switch(buff){
|
||
case BuffAttr.ATK:
|
||
this.ap=this.check_atrr(BuffAttr.ATK)
|
||
// this.update_vmdata()
|
||
break
|
||
case BuffAttr.ATK_CD:
|
||
this.cd=this.check_atrr(BuffAttr.ATK_CD)
|
||
// this.update_vmdata()
|
||
break
|
||
case BuffAttr.HP:
|
||
let diff=this.check_atrr(BuffAttr.HP)-this.currentHpMax
|
||
this.currentHpMax=this.check_atrr(BuffAttr.HP)
|
||
this.currentHp+=diff
|
||
// this.update_vmdata()
|
||
break
|
||
}
|
||
}
|
||
|
||
add_speed(cd: number){
|
||
this.cd_buff+=cd
|
||
this.count_atrr(BuffAttr.ATK_CD)
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.speedup,speed.toFixed(0));
|
||
}
|
||
|
||
|
||
add_ap(ap: number,is_num:boolean=true){
|
||
// console.log("[HeroViewComp]:add_ap add:",ap,this.ap)
|
||
if(is_num){
|
||
this.ap_base += Math.floor(ap);
|
||
}else{
|
||
this.ap_base += Math.floor(ap/100*this.ap_base);
|
||
}
|
||
this.count_atrr(BuffAttr.ATK)
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.apup,diff.toFixed(0));
|
||
}
|
||
|
||
de_ap(ap: number,is_num:boolean=true){
|
||
//console.log("[HeroViewComp]:de_ap de:",ap,this.ap)
|
||
if(is_num){
|
||
this.ap_base -= Math.floor(ap);
|
||
}else{
|
||
this.ap_base -= Math.floor(ap/100*this.ap_base);
|
||
}
|
||
this.count_atrr(BuffAttr.ATK)
|
||
}
|
||
|
||
add_hp_max(hp: number=0,is_num:boolean=false){
|
||
// console.log("[HeroViewComp]:add_hp_max add:",hp,this.currentHpMax)
|
||
if(is_num){
|
||
this.hp_base += Math.floor(hp) ;
|
||
}else{
|
||
this.hp_buff+=hp
|
||
}
|
||
this.count_atrr(BuffAttr.HP)
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.hpup,diff.toFixed(0));
|
||
}
|
||
|
||
de_hp_max(hp: number=0,is_num:boolean=true){ //最大值 只存在数值添加, 比例通过hp_buff处理
|
||
//console.log("[HeroViewComp]:de_hp_max de:",hp,this.currentHpMax)
|
||
this.hp_base -= Math.floor(hp) ;
|
||
this.count_atrr(BuffAttr.HP)
|
||
// this.update_vm
|
||
}
|
||
|
||
add_hp(hp: number = 0,is_num:boolean=true) {
|
||
this.BUFFCOMP.heathed();
|
||
let real_hp=0
|
||
let hp_max=Math.floor(this.currentHpMax*(100+this.hp_buff)/100)
|
||
let lost_hp=hp_max-this.currentHp
|
||
if(is_num){
|
||
if(lost_hp > hp){
|
||
real_hp=Math.floor(hp);
|
||
}else{
|
||
real_hp=lost_hp;
|
||
}
|
||
}else{
|
||
if(lost_hp > hp/100*hp_max){
|
||
real_hp=Math.floor(hp/100*hp_max);
|
||
}else{
|
||
real_hp=lost_hp;
|
||
}
|
||
}
|
||
if(real_hp > 0){
|
||
this.currentHp+=real_hp;
|
||
this.BUFFCOMP.tooltip(TooltipTypes.health,real_hp.toFixed(0));
|
||
}
|
||
// this.update_vm
|
||
}
|
||
|
||
|
||
/** 静止时间 */
|
||
in_stop (dt: number) {
|
||
if(this.stop_cd > 0){
|
||
this.stop_cd -= dt;
|
||
if(this.stop_cd <= 0){
|
||
this.stop_cd = 0;
|
||
this.is_atking = false;
|
||
}
|
||
}
|
||
}
|
||
count_atk_count(){ //主将攻击
|
||
if(this.fac==FacSet.MON) return
|
||
this.atk_count+=1
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
do_dead(){
|
||
this.do_dead_trigger()
|
||
//console.log("[HeroViewComp]:角色死亡",this.hero_uuid)
|
||
|
||
if(this.fac==FacSet.MON){
|
||
if(this.is_count_dead) return
|
||
this.is_count_dead=true
|
||
this.scheduleOnce(()=>{
|
||
oops.message.dispatchEvent(GameEvent.MonDead)
|
||
},0.1)
|
||
|
||
}
|
||
|
||
if(this.fac==FacSet.HERO){
|
||
//console.log("[HeroViewComp]:英雄死亡")
|
||
// oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false})
|
||
}
|
||
|
||
|
||
}
|
||
|
||
get_debuff(){
|
||
|
||
}
|
||
add_debuff(type:number,deV:number,deC:number,deR:number){
|
||
let DEBUFF_DOWN=0
|
||
|
||
for(let i=0;i<this.BUFF_DEDOWN.length;i++){
|
||
DEBUFF_DOWN+=this.BUFF_DEDOWN[i].value
|
||
// 不再在这里减少duration,改为在update中按时间减少
|
||
}
|
||
let n_deR=deR-DEBUFF_DOWN-this.buff_debuff_down // 触发概率
|
||
let r=RandomManager.instance.getRandomInt(0,100) // 随机数
|
||
//console.log("[HeroViewComp]:类型,值,次数,技能概率,实际概率,随机数",type,deV,deC,deR,n_deR,r)
|
||
if(r < n_deR) {
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.uskill,"*抵抗*")
|
||
return
|
||
}
|
||
|
||
switch(type){
|
||
case DebuffAttr.BURN:
|
||
this.DEBUFF_BURNS.push({value:deV,duration:deC+FightSet.BURN_COUNT})
|
||
break
|
||
case DebuffAttr.DECD:
|
||
this.DEBUFF_DECDS.push({value:deV,duration:deC})
|
||
break
|
||
case DebuffAttr.SLOW:
|
||
this.DEBUFF_SLOW+=deV
|
||
break
|
||
case DebuffAttr.FROST:
|
||
this.BUFFCOMP.in_iced(deV)
|
||
this.DEBUFF_FROST+=deV
|
||
break
|
||
case DebuffAttr.STUN:
|
||
if(this.DEBUFF_STUN>0) return
|
||
this.at=0 // 眩晕 cd归零
|
||
this.BUFFCOMP.in_yun(deV+FightSet.STUN_TIME) // 眩晕时间
|
||
this.DEBUFF_STUN+=deV+FightSet.STUN_TIME // 眩晕时间
|
||
// this.is_stop=true
|
||
break
|
||
case DebuffAttr.DEHP:
|
||
this.currentHpMax-=deV/100*this.currentHpMax
|
||
if(this.currentHp-this.currentHpMax>0) this.currentHp=this.currentHpMax
|
||
break
|
||
case DebuffAttr.DEATK: //99为具体数字 并且局内永久生效,其他为百分比
|
||
if(deC == 99){
|
||
this.ap-=deV
|
||
}else{
|
||
this.DEBUFF_DEATKS.push({value:deV,duration:deC})
|
||
}
|
||
break
|
||
case DebuffAttr.DECOUNT:
|
||
this.atk_count-=deV
|
||
if(this.atk_count<0) this.atk_count=1
|
||
break
|
||
case DebuffAttr.BACK:
|
||
if(this.fac==FacSet.MON) {
|
||
let tx=this.node.position.x+50
|
||
if(tx > 320) tx=320
|
||
tween(this.node).to(0.3, { position:v3(tx,this.node.position.y,0)}).start()
|
||
}
|
||
break
|
||
}
|
||
//console.log("[HeroViewComp]:debuffs",type,deV,deC,deR,this.DEBUFF_BURNS)
|
||
}
|
||
|
||
// 更新所有按时间减少的buff和debuff
|
||
updateBuffsAndDebuffs(dt: number) {
|
||
// 更新BUFF_DEFS
|
||
for(let i = this.BUFF_DEFS.length - 1; i >= 0; i--) {
|
||
this.BUFF_DEFS[i].duration -= dt;
|
||
if(this.BUFF_DEFS[i].duration <= 0) {
|
||
this.BUFF_DEFS.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新BUFF_ATKS
|
||
for(let i = this.BUFF_ATKS.length - 1; i >= 0; i--) {
|
||
this.BUFF_ATKS[i].duration -= dt;
|
||
if(this.BUFF_ATKS[i].duration <= 0) {
|
||
this.BUFF_ATKS.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新BUFF_CDS
|
||
for(let i = this.BUFF_CDS.length - 1; i >= 0; i--) {
|
||
this.BUFF_CDS[i].duration -= dt;
|
||
if(this.BUFF_CDS[i].duration <= 0) {
|
||
this.BUFF_CDS.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新BUFF_DEDOWN
|
||
for(let i = this.BUFF_DEDOWN.length - 1; i >= 0; i--) {
|
||
this.BUFF_DEDOWN[i].duration -= dt;
|
||
if(this.BUFF_DEDOWN[i].duration <= 0) {
|
||
this.BUFF_DEDOWN.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新DEBUFF_BURNS
|
||
for(let i = this.DEBUFF_BURNS.length - 1; i >= 0; i--) {
|
||
this.DEBUFF_BURNS[i].duration -= dt;
|
||
if(this.DEBUFF_BURNS[i].duration <= 0) {
|
||
this.DEBUFF_BURNS.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新DEBUFF_DEATKS
|
||
for(let i = this.DEBUFF_DEATKS.length - 1; i >= 0; i--) {
|
||
this.DEBUFF_DEATKS[i].duration -= dt;
|
||
if(this.DEBUFF_DEATKS[i].duration <= 0) {
|
||
this.DEBUFF_DEATKS.splice(i, 1);
|
||
}
|
||
}
|
||
|
||
// 更新DEBUFF_DECDS
|
||
for(let i = this.DEBUFF_DECDS.length - 1; i >= 0; i--) {
|
||
this.DEBUFF_DECDS[i].duration -= dt;
|
||
if(this.DEBUFF_DECDS[i].duration <= 0) {
|
||
this.DEBUFF_DECDS.splice(i, 1);
|
||
}
|
||
}
|
||
}
|
||
|
||
add_buff(buff:number,duration:number,type:number){
|
||
switch(type){
|
||
case BuffAttr.DEF:
|
||
this.BUFF_DEFS.push({value:buff,duration:duration})
|
||
break
|
||
case BuffAttr.ATK:
|
||
this.BUFF_ATKS.push({value:buff,duration:duration})
|
||
break
|
||
case BuffAttr.ATK_CD:
|
||
this.BUFF_CDS.push({value:buff,duration:duration})
|
||
break
|
||
case BuffAttr.DEBUFF_DOWN:
|
||
this.BUFF_DEDOWN.push({value:buff,duration:duration})
|
||
break
|
||
}
|
||
}
|
||
|
||
do_atked(remainingDamage:number,
|
||
crit:number=0,crit_d:number=0,
|
||
burn_count:number=0,burn_value:number=0,
|
||
stun_time:number=0,stun_ratto:number=0,
|
||
frost_time:number=0,frost_ratto:number=0,
|
||
atked_anm:string="atked"
|
||
){
|
||
this.do_atked_trigger()
|
||
if(burn_count>0){
|
||
this.add_debuff(DebuffAttr.BURN,burn_value,burn_count,100)
|
||
}
|
||
if(stun_time>0){
|
||
this.add_debuff(DebuffAttr.STUN,stun_time,1,stun_ratto)
|
||
}
|
||
if(this.check_shield()) return
|
||
if(this.check_dodge()) return
|
||
let is_crit = this.check_crit(crit)
|
||
|
||
if(this == null) return;
|
||
let damage = this.count_damage(remainingDamage)
|
||
if(is_crit) {
|
||
damage = Math.floor(damage * (1 + (FightSet.CRIT_DAMAGE+crit_d)/100))
|
||
if(this.fac==FacSet.MON) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.CRIT_TO_POWER //暴击涨能量 怪物被暴击,因为只有一个英雄 直接处理
|
||
}
|
||
this.currentHp -= damage;
|
||
if(this.fac==FacSet.HERO) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.ATKED_TO_POWER //被攻击涨能量
|
||
if(this.fac==FacSet.MON) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.ATK_TO_POWER //攻击命中涨能量 因为是只有1个英雄 直接处理
|
||
|
||
if(this.currentHp <= 0) {
|
||
if(this == null) return;
|
||
this.is_dead=true
|
||
if(this.BUFFCOMP){
|
||
this.BUFFCOMP.dead()
|
||
}
|
||
this.do_dead()
|
||
//console.log("[HeroViewComp]:dead,fac => "+(this.fac==FacSet.HERO?"hero":"monster"))
|
||
if(this.ent == null) return;
|
||
if(this.fac ==FacSet.HERO){
|
||
this.to_grave()
|
||
}else{
|
||
this.ent.destroy();
|
||
}
|
||
}
|
||
|
||
|
||
// this.update_vm
|
||
this.showDamage(damage, is_crit,atked_anm);
|
||
|
||
}
|
||
//伤害计算 debuff 易伤
|
||
count_damage(remainingDamage:number){
|
||
let damage = 0;
|
||
let Burn = 0;
|
||
let def = 0;
|
||
for(let i=0;i<this.DEBUFF_BURNS.length;i++){
|
||
Burn+=this.DEBUFF_BURNS[i].value
|
||
// 不再在这里减少duration,改为在update中按时间减少
|
||
}
|
||
for(let i=0;i<this.BUFF_DEFS.length;i++){
|
||
def+=this.BUFF_DEFS[i].value
|
||
// 不再在这里减少duration,改为在update中按时间减少
|
||
}
|
||
// buff 防御 即免伤
|
||
|
||
damage=remainingDamage*(100-def-this.def+Burn)/100
|
||
////console.log("[HeroViewComp]:最终伤害,敌人伤害值,免伤,防御,易伤",damage,remainingDamage,buff_def,def,Burn)
|
||
return Math.floor(damage)
|
||
}
|
||
count_debuff(){
|
||
|
||
}
|
||
|
||
count_buff(){
|
||
|
||
}
|
||
|
||
check_shield(){
|
||
if(this.shield>0){
|
||
this.shield -= 1
|
||
this.BUFFCOMP.tooltip(TooltipTypes.uskill,"*吸收*");
|
||
if (this.shield <= 0) {
|
||
if(this == null) return;
|
||
this.BUFFCOMP.show_shield(false);
|
||
}
|
||
return true
|
||
}
|
||
return false
|
||
}
|
||
|
||
check_dodge(){
|
||
if(this.fac==FacSet.HERO) smc.vmdata.hero.power+=smc.vmdata.hero.POWER_UP+FightSet.DODGE_TO_POWER //闪避涨能量
|
||
if(this.dod > 0){
|
||
let random = Math.random()*100
|
||
if(random < this.dod) {
|
||
this.BUFFCOMP.tooltip(TooltipTypes.uskill,"*闪避*");
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
check_crit(crit:number=0){
|
||
|
||
if(this.crit_no) return false
|
||
if(crit > 0){
|
||
let random = Math.random()*100
|
||
if(random < crit) {
|
||
//console.log("[HeroViewComp]:crit",crit,random)
|
||
return true
|
||
}
|
||
}
|
||
//console.log("[HeroViewComp]:crit",crit)
|
||
return false
|
||
}
|
||
// dead(){
|
||
// this.BUFFCOMP.dead()
|
||
// this.to_drop()
|
||
|
||
// }
|
||
do_dead_trigger(){ //双倍死亡设定
|
||
if(this.is_dead||this.fac==FacSet.MON) return
|
||
let count = 1
|
||
for(let i=0;i<count;i++){
|
||
//console.log("[HeroViewComp]:dead"+i+"次")
|
||
}
|
||
}
|
||
do_atked_trigger(){ //双倍攻击设定
|
||
if(this.is_dead||this.fac==FacSet.MON) return
|
||
let count = 1
|
||
if(this.double_atked) {
|
||
//console.log("[HeroViewComp]:double_atked")
|
||
count =2
|
||
}
|
||
|
||
}
|
||
|
||
to_grave(){
|
||
tween(this.node).to(0.5, { position:v3(-900,this.node.position.y+300,0)},{
|
||
onComplete: (target?: object) => {
|
||
this.node.setPosition(-900,this.node.position.y-300,0)
|
||
}
|
||
}).start()
|
||
}
|
||
// to_alive(){
|
||
// this.is_dead=false
|
||
// this.currentHp=this.currentHpMax*(100+this.hp_buff)/100
|
||
// this.BUFFCOMP.vmdata_update(true)
|
||
// this.node.setPosition(HeroPos[this.fight_pos].pos)
|
||
// this.BUFFCOMP.heathed()
|
||
// }
|
||
//掉落物品
|
||
to_drop(){
|
||
// let Drops = getMonsterDrops(1, MonsterType.Normal, 1.2);
|
||
// if(this.is_boss) Drops =getMonsterDrops(1, MonsterType.Elite, 1.2);
|
||
// if(this.is_big_boss) Drops =getMonsterDrops(1, MonsterType.Boss, 1.2);
|
||
}
|
||
|
||
to_console(value:any,value2:any=null,value3:any=null){
|
||
//console.log("["+this.scale+this.hero_name+']'+value,value2,value3)
|
||
}
|
||
|
||
reset() {
|
||
this.is_dead = false;
|
||
const collider = this.getComponent(Collider2D);
|
||
if (collider) {
|
||
collider.off(Contact2DType.BEGIN_CONTACT);
|
||
}
|
||
this.scheduleOnce(() => {
|
||
this.node.destroy();
|
||
}, 0.1);
|
||
}
|
||
|
||
playSkillEffect(skill_id:number) {
|
||
let skill = SkillSet[skill_id]
|
||
switch(skill.act){
|
||
case "max":
|
||
this.as.max()
|
||
this.BUFFCOMP.max_show(skill.fname)
|
||
this.BUFFCOMP.tooltip(TooltipTypes.skill,skill.name,skill_id)
|
||
break
|
||
case "atk":
|
||
this.as.atk()
|
||
break
|
||
}
|
||
}
|
||
|
||
exp_up(e:any,data:any){
|
||
if(this.fac==FacSet.MON) return
|
||
// console.log("[HeroViewComp]:经验提高",data.exp)
|
||
smc.vmdata.hero.exp+=data.exp
|
||
// smc.vmdata.hero.next_exp=getUpExp(this.lv)
|
||
if(smc.vmdata.hero.exp >= smc.vmdata.hero.next_exp){
|
||
// console.log("[HeroViewComp]:升级")
|
||
this.to_update_lv("seft",data)
|
||
oops.message.dispatchEvent(GameEvent.CanUpdateLv)
|
||
}
|
||
|
||
}
|
||
|
||
to_update_lv(event:string,data:any){
|
||
if(this.fac==FacSet.MON) return
|
||
console.log("[HeroViewComp]:升级",this.BUFFCOMP)
|
||
if(this.hero_uuid!=data.uuid) return
|
||
this.add_ap(HeroInfo[data.uuid].ap,true)
|
||
this.add_hp_max(HeroInfo[data.uuid].hp,true)
|
||
this.BUFFCOMP.lv_up()
|
||
// this.BUFFCOMP.tooltip(TooltipTypes.lvup)
|
||
}
|
||
/** 显示伤害数字 */
|
||
|
||
showDamage(damage: number, isCrit: boolean,anm:string="atked") {
|
||
this.damageQueue.push({
|
||
damage,
|
||
isCrit,
|
||
delay: this.damageInterval,
|
||
anm
|
||
});
|
||
}
|
||
ex_show(text:string){
|
||
switch(text){
|
||
case "blue":
|
||
this.BUFFCOMP.max_show("max_blue")
|
||
break
|
||
case "red":
|
||
this.BUFFCOMP.max_show("max_red")
|
||
break
|
||
}
|
||
}
|
||
/** 处理伤害队列 */
|
||
private processDamageQueue() {
|
||
if (this.isProcessingDamage || this.damageQueue.length === 0) return;
|
||
|
||
this.isProcessingDamage = true;
|
||
const damageInfo = this.damageQueue.shift()!;
|
||
|
||
this.showDamageImmediate(damageInfo.damage, damageInfo.isCrit,damageInfo.anm);
|
||
|
||
// 设置延时处理下一个伤害
|
||
this.scheduleOnce(() => {
|
||
this.isProcessingDamage = false;
|
||
}, this.damageInterval);
|
||
}
|
||
|
||
/** 立即显示伤害效果 */
|
||
private showDamageImmediate(damage: number, isCrit: boolean,anm:string="atked") {
|
||
// this.as.atked()
|
||
this.BUFFCOMP.in_atked(anm)
|
||
this.atked_count++;
|
||
if (isCrit) {
|
||
this.BUFFCOMP.hp_tip(TooltipTypes.crit, damage.toFixed(0), damage);
|
||
// //console.log("暴击伤害:" + damage);
|
||
} else {
|
||
this.BUFFCOMP.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
||
// //console.log("普通伤害:" + damage);
|
||
}
|
||
}
|
||
} |