实现英雄天赋系统核心功能,包括: 1. 新增 TalComp 组件管理天赋的获取、触发和效果应用 2. 重构 TalSet 配置结构,完善天赋类型和效果枚举 3. 在 Hero/Monster 实体中集成天赋组件 4. 为 SkillConComp 和 HeroViewComp 添加天赋相关引用
780 lines
27 KiB
TypeScript
780 lines
27 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 { SkillSet,BuffConf,} from "../common/config/SkillSet";
|
||
import { BuffComp } from "./BuffComp";
|
||
import { oops } from "db://oops-framework/core/Oops";
|
||
import { GameEvent } from "../common/config/GameEvent";
|
||
import { FightSet, TooltipTypes } from "../common/config/Mission";
|
||
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
||
import { AttrSet, HeroInfo, HeroUpSet } from "../common/config/heroSet";
|
||
import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||
import { TalComp } from "./TalComp";
|
||
const { ccclass, property } = _decorator;
|
||
|
||
/**
|
||
* ==================== BUFF 系统使用说明 ====================
|
||
*
|
||
* 1. 系统架构 - 支持多次叠加(简化设计)
|
||
* - BUFFS: 持久型buff数组(持久存在,直到主动移除)
|
||
* - BUFFS_TEMP: 临时型buff数组(持续指定时间,时间到自动移除)
|
||
* - 每个buff实例内包含BType字段,区分数值型(VALUE)和百分比型(RATIO)
|
||
*
|
||
* 2. 叠加规则 - 核心特性
|
||
* - 同一属性允许多个buff实例同时存在(数值型和百分比型混合)
|
||
* - 每个buff实例保持独立的数据(value、BType、remainTime)
|
||
* - 所有buff实例在属性计算时都被纳入求和计算
|
||
* - 示例:若添加两个+10 AP的buff,最终会累加 +20 AP
|
||
*
|
||
* 3. 数据结构 - 统一数组设计
|
||
* - BUFFS: Record<attrIndex: number, Array<{value, BType}>>
|
||
* - BUFFS_TEMP: Record<attrIndex: number, Array<{value, BType, remainTime}>>
|
||
* - 每个属性对应一个buff数组,可混合存储数值型和百分比型buff
|
||
*
|
||
* 4. 属性计算公式 - 按BType区分
|
||
* - 数值型: (基础值 + 所有数值型buff之和) × (1 + 所有百分比buff之和/100)
|
||
* - 百分比: 基础值 + 所有数值型buff之和 + 所有百分比buff之和
|
||
*
|
||
* 5. API 使用示例
|
||
* // 添加buff(自动根据time判断持久或临时)
|
||
* const buffConf: BuffConf = {
|
||
* buff: Attrs.AP,
|
||
* BType: BType.VALUE,
|
||
* value: 10,
|
||
* time: 5, // 0表示持久,>0表示临时
|
||
* chance: 100
|
||
* };
|
||
* hero.addBuff(buffConf);
|
||
*
|
||
* // 移除特定buff
|
||
* hero.removeBuff(Attrs.AP, 10, true); // 移除临时的+10 AP
|
||
*
|
||
* // 清空属性所有buff
|
||
* hero.clearBuffs(Attrs.AP);
|
||
*
|
||
* // 查询激活的buff数量
|
||
* const count = hero.getActiveBuffCount(Attrs.AP);
|
||
*
|
||
* 6. 临时buff自动更新
|
||
* - 每帧update中自动调用updateTemporaryBuffsDebuffs(dt)
|
||
* - 递减所有临时buff的remainTime
|
||
* - 当remainTime <= 0时自动移除buff并重新计算属性
|
||
*/
|
||
/** 角色显示组件 */
|
||
export interface BuffInfo {
|
||
attr: Attrs;
|
||
value: number;
|
||
remainTime?: number;
|
||
}
|
||
@ccclass('HeroViewComp') // 定义Cocos Creator 组件
|
||
@ecs.register('HeroView', false) // 定义ECS 组件
|
||
export class HeroViewComp extends CCComp {
|
||
BUFFCOMP:BuffComp=null!
|
||
TALCOMP:any=null!
|
||
as: HeroSpine = null!
|
||
status:String = "idle"
|
||
hero_uuid:number = 1001;
|
||
hero_name : string = "hero";
|
||
lv:number =1;
|
||
scale: number = 1; /** 角色阵营 1:hero -1 :mon */
|
||
type: number = 0; /**角色类型 0近战-需要贴1远程-保持距离 2辅助 */
|
||
fac:number=0; //阵营 0:hero 1:monster
|
||
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;
|
||
skills:any=[]
|
||
mp: number = 100;
|
||
hp: number = 100; /** 血*/
|
||
shield:number=0; //当前护甲
|
||
/** 基础属有初始值的基础属后续Attrs 属性计算时用到*/
|
||
base_ap: number = 0; //基础攻击
|
||
base_map: number = 0;
|
||
base_def: number = 5;
|
||
base_hp: number = 100;
|
||
base_mp: number = 100;
|
||
base_speed: number = 100; /** 角色移动速度 */
|
||
base_dis: number = 100;
|
||
Attrs:any=[]
|
||
NeAttrs:any=[]
|
||
// Buff debuff 统一管理
|
||
// 每个buff实例内包含BType,用于区分数值型(VALUE)和百分比型(RATIO)
|
||
// [attrIndex: number]: Array<BuffInstance> - 允许多个buff实例独立存在
|
||
|
||
/** 持久型buff数组 - 不会自动过期 */
|
||
BUFFS: Record<number, Array<{value: number, BType: BType}>> = {}
|
||
|
||
/** 临时型buff数组 - 按时间自动过期 */
|
||
BUFFS_TEMP: Record<number, Array<{value: number, BType: BType, remainTime: number}>> = {}
|
||
|
||
atk_count: number = 0;
|
||
atked_count: number = 0;
|
||
|
||
|
||
private damageQueue: Array<{
|
||
damage: number,
|
||
isCrit: boolean,
|
||
delay: number,
|
||
anm:string,
|
||
}> = [];
|
||
private isProcessingDamage: boolean = false;
|
||
private damageInterval: number = 0.01; // 伤害数字显示间隔
|
||
onLoad() {
|
||
this.as = this.getComponent(HeroSpine);
|
||
//console.log("[HeroViewComp]:hero view comp ",this.FIGHTCON)
|
||
this.on(GameEvent.FightEnd,this.do_fight_end,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.TALCOMP=this.node.getComponent(TalComp);
|
||
// console.log("[HeroViewComp]:heroview"+this.hero_name,this.Attrs)
|
||
/** 方向 */
|
||
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;
|
||
this.node.getChildByName("top").getChildByName("pow").active = true;
|
||
}
|
||
|
||
// ==================== BUFF系统初始====================
|
||
/**
|
||
* 初始化角色的 buff debuff
|
||
* HeroInfo 读取初始配置,建立属性系
|
||
*/
|
||
initAttrs() {
|
||
// 清空现有 buff/debuff
|
||
this.BUFFS = {
|
||
};
|
||
this.BUFFS_TEMP = {
|
||
};
|
||
// 获取英雄配置
|
||
const heroInfo = HeroInfo[this.hero_uuid];
|
||
if (!heroInfo) return;
|
||
|
||
|
||
// 1. 重置为基础
|
||
this.Attrs[Attrs.HP_MAX] = this.base_hp;
|
||
this.Attrs[Attrs.MP_MAX] = this.base_mp;
|
||
this.Attrs[Attrs.DEF] = this.base_def;
|
||
this.Attrs[Attrs.AP] = this.base_ap;
|
||
this.Attrs[Attrs.MAP] = this.base_map;
|
||
this.Attrs[Attrs.SPEED] = this.base_speed;
|
||
this.Attrs[Attrs.DIS] = this.base_dis;
|
||
|
||
// 2. 初始化其他属性(无初始值的
|
||
for (const attrKey in this.Attrs) {
|
||
const attrIndex = parseInt(attrKey);
|
||
if(
|
||
attrIndex !== Attrs.HP_MAX &&
|
||
attrIndex !== Attrs.MP_MAX&&
|
||
attrIndex !== Attrs.DEF &&
|
||
attrIndex !== Attrs.AP &&
|
||
attrIndex !== Attrs.MAP &&
|
||
attrIndex !== Attrs.SPEED &&
|
||
attrIndex !== Attrs.DIS
|
||
|
||
) {
|
||
this.Attrs[attrIndex] = 0;
|
||
}
|
||
}
|
||
// 加载初始 buff
|
||
if (heroInfo.buff && heroInfo.buff.length > 0) {
|
||
for (const buffConf of heroInfo.buff) {
|
||
this.addBuff(buffConf);
|
||
}
|
||
}
|
||
}
|
||
// ==================== BUFF管理 ====================
|
||
/**
|
||
* 添加 buff 效果(支持多次叠加)
|
||
* @param buffConf buff 配置 (来自 SkillSet.BuffConf heroSet.buff)
|
||
*
|
||
* 叠加规则
|
||
* 1. 持久型buff:直接添加到数组中,与现有buff独立存在
|
||
* 2. 临时型buff:直接添加到数组中,保持独立的剩余时间计算
|
||
* 3. 所有buff实例在属性计算时都被纳入求和计算
|
||
*/
|
||
addBuff(buffConf: BuffConf) {
|
||
const isPermanent = buffConf.time === 0;
|
||
const attrIndex = buffConf.buff;
|
||
|
||
if (isPermanent) {
|
||
// 添加持久buff到BUFFS - 直接追加到数组
|
||
if (!this.BUFFS[attrIndex]) {
|
||
this.BUFFS[attrIndex] = [];
|
||
}
|
||
this.BUFFS[attrIndex].push({ value: buffConf.value, BType: buffConf.BType });
|
||
} else {
|
||
// 添加临时buff到BUFFS_TEMP - 直接追加到数组
|
||
if (!this.BUFFS_TEMP[attrIndex]) {
|
||
this.BUFFS_TEMP[attrIndex] = [];
|
||
}
|
||
this.BUFFS_TEMP[attrIndex].push({
|
||
value: buffConf.value,
|
||
BType: buffConf.BType,
|
||
remainTime: buffConf.time
|
||
});
|
||
}
|
||
|
||
// 重新计算受影响的属性
|
||
this.recalculateSingleAttr(attrIndex);
|
||
}
|
||
|
||
|
||
// ==================== 属性计算系====================
|
||
/**
|
||
* 重新计算单个属性
|
||
* @param attrIndex 属性索引
|
||
*
|
||
* 计算公式:
|
||
* - 数值型属性:最终值 = (基础值 + 所有数值型buff之和 - 所有数值型debuff之和) × (1 + 所有百分比buff之和/100 - 所有百分比debuff之和/100)
|
||
* - 百分比型属性:最终值 = 基础值 + 所有数值型buff之和 - 所有数值型debuff之和 + 所有百分比buff之和 - 所有百分比debuff之和
|
||
*/
|
||
private recalculateSingleAttr(attrIndex: number) {
|
||
// 1. 获取基础值
|
||
const baseValues: Record<number, number> = {
|
||
[Attrs.HP_MAX]: this.base_hp,
|
||
[Attrs.MP_MAX]: this.base_mp,
|
||
[Attrs.DEF]: this.base_def,
|
||
[Attrs.AP]: this.base_ap,
|
||
[Attrs.MAP]: this.base_map,
|
||
[Attrs.SPEED]: this.base_speed,
|
||
[Attrs.SHIELD_MAX]: 0
|
||
};
|
||
|
||
const baseVal = baseValues[attrIndex] !== undefined ? baseValues[attrIndex] : 0;
|
||
|
||
// 2. 收集所有数值型 buff/debuff - 遍历所有buff数组并按BType筛选求和
|
||
let totalValue = baseVal;
|
||
|
||
// 遍历持久buff数组
|
||
if (this.BUFFS[attrIndex] && this.BUFFS[attrIndex].length > 0) {
|
||
for (const buff of this.BUFFS[attrIndex]) {
|
||
if (buff.BType === BType.VALUE) {
|
||
totalValue += buff.value;
|
||
}
|
||
}
|
||
}
|
||
// 遍历临时buff数组
|
||
if (this.BUFFS_TEMP[attrIndex] && this.BUFFS_TEMP[attrIndex].length > 0) {
|
||
for (const buff of this.BUFFS_TEMP[attrIndex]) {
|
||
if (buff.BType === BType.VALUE) {
|
||
totalValue += buff.value;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 3. 收集所有百分比型 buff/debuff - 遍历所有buff数组并按BType筛选求和
|
||
let totalRatio = 0; // 总百分比(可正可负)
|
||
|
||
// 遍历持久buff数组
|
||
if (this.BUFFS[attrIndex] && this.BUFFS[attrIndex].length > 0) {
|
||
for (const buff of this.BUFFS[attrIndex]) {
|
||
if (buff.BType === BType.RATIO) {
|
||
totalRatio += buff.value;
|
||
}
|
||
}
|
||
}
|
||
// 遍历临时buff数组
|
||
if (this.BUFFS_TEMP[attrIndex] && this.BUFFS_TEMP[attrIndex].length > 0) {
|
||
for (const buff of this.BUFFS_TEMP[attrIndex]) {
|
||
if (buff.BType === BType.RATIO) {
|
||
totalRatio += buff.value;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 4. 根据属性类型计算最终值
|
||
const attrType = AttrsType[attrIndex];
|
||
const isRatioAttr = attrType === BType.RATIO;
|
||
|
||
if (isRatioAttr) {
|
||
// 百分比型属性:直接加减
|
||
this.Attrs[attrIndex] = totalValue + totalRatio;
|
||
} else {
|
||
// 数值型属性:(基础值+数值) × (1 + 百分比/100)
|
||
this.Attrs[attrIndex] = Math.floor(totalValue * (1 + totalRatio / 100));
|
||
}
|
||
|
||
// 5. 确保属性值合理
|
||
this.clampSingleAttr(attrIndex);
|
||
}
|
||
/**
|
||
* 确保单个属性值合
|
||
*/
|
||
private clampSingleAttr(attrIndex: number) {
|
||
switch(attrIndex) {
|
||
case Attrs.HP_MAX:
|
||
case Attrs.MP_MAX:
|
||
this.Attrs[attrIndex] = Math.max(1, this.Attrs[attrIndex]);
|
||
break;
|
||
case Attrs.DEF:
|
||
case Attrs.AP:
|
||
case Attrs.MAP:
|
||
this.Attrs[attrIndex] = Math.max(1, this.Attrs[attrIndex]);
|
||
break;
|
||
case Attrs.CRITICAL:
|
||
case Attrs.DODGE:
|
||
case Attrs.HIT:
|
||
this.Attrs[attrIndex] = Math.max(0, Math.min(AttrSet.ATTR_MAX, this.Attrs[attrIndex])); //AttrSet.ATTR_MAX =85
|
||
break;
|
||
}
|
||
}
|
||
|
||
// ==================== 临时 BUFF/DEBUFF 更新 ====================
|
||
/**
|
||
* 更新临时 buff/debuff 的剩余时
|
||
* 应在 update 中定期调
|
||
* @param dt 时间
|
||
*/
|
||
updateTemporaryBuffsDebuffs(dt: number) {
|
||
const affectedAttrs = new Set<number>();
|
||
// 更新临时型数buff
|
||
for (const attrIndex in this.BUFFS_TEMP) {
|
||
const buffs = this.BUFFS_TEMP[attrIndex];
|
||
buffs.forEach(buff => {
|
||
buff.remainTime -= dt;
|
||
if (buff.remainTime <= 0) {
|
||
// 从数组中移除
|
||
const index = buffs.indexOf(buff);
|
||
if (index > -1) {
|
||
buffs.splice(index, 1);
|
||
}
|
||
}
|
||
});
|
||
if (buffs.length === 0) {
|
||
delete this.BUFFS_TEMP[attrIndex];
|
||
affectedAttrs.add(parseInt(attrIndex));
|
||
}
|
||
}
|
||
// 更新临时型百分比 buff
|
||
for (const attrIndex in this.BUFFS_TEMP) {
|
||
const buffs = this.BUFFS_TEMP[attrIndex];
|
||
buffs.forEach(buff => {
|
||
buff.remainTime -= dt;
|
||
if (buff.remainTime <= 0) {
|
||
// 从数组中移除
|
||
const index = buffs.indexOf(buff);
|
||
if (index > -1) {
|
||
buffs.splice(index, 1);
|
||
}
|
||
}
|
||
});
|
||
if (buffs.length === 0) {
|
||
delete this.BUFFS_TEMP[attrIndex];
|
||
affectedAttrs.add(parseInt(attrIndex));
|
||
}
|
||
}
|
||
|
||
// 负面状态更新
|
||
for (const key in this.NeAttrs) {
|
||
const debuff = this.NeAttrs[key];
|
||
debuff.remainTime -= dt;
|
||
if (debuff.remainTime <= 0) {
|
||
debuff.remainTime = 0;
|
||
}
|
||
}
|
||
|
||
// 只重新计算受影响的属
|
||
affectedAttrs.forEach(attrIndex => {
|
||
this.recalculateSingleAttr(attrIndex);
|
||
});
|
||
}
|
||
|
||
// ==================== BUFF 辅助方法 ====================
|
||
/**
|
||
* 清空buff
|
||
* @param attrIndex 属性索引,如果为空则清理所有buff(包括临时和持久)
|
||
* @param isBuff true时清理value>0的增益buff,false时清理value<0的减益buff
|
||
*/
|
||
clearBuffs(attrIndex?: number, isBuff: boolean = true): void {
|
||
if (attrIndex === undefined) {
|
||
// 清理所有buff,根据isBuff过滤
|
||
for (const attrIndex in this.BUFFS_TEMP) {
|
||
this.clearBuffsForAttr(parseInt(attrIndex), isBuff);
|
||
}
|
||
|
||
} else {
|
||
// 清理指定属性的buff,根据isBuff过滤
|
||
this.clearBuffsForAttr(attrIndex, isBuff);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 清理指定属性的buff,根据增益/减益类型过滤
|
||
* @param attrIndex 属性索引
|
||
* @param isBuff true清理增益buff,false清理减益buff
|
||
*/
|
||
private clearBuffsForAttr(attrIndex: number, isBuff: boolean): void {
|
||
const buffContainer = this.BUFFS_TEMP;
|
||
|
||
if (!buffContainer[attrIndex]) return;
|
||
|
||
// 过滤buff数组,保留不符合清理条件的buff
|
||
buffContainer[attrIndex] = buffContainer[attrIndex].filter(buff => {
|
||
const shouldClear = isBuff ? buff.value > 0 : buff.value < 0;
|
||
return !shouldClear;
|
||
});
|
||
|
||
// 如果数组为空,删除该属性条目
|
||
if (buffContainer[attrIndex].length === 0) {
|
||
delete buffContainer[attrIndex];
|
||
}
|
||
|
||
// 重新计算该属性
|
||
this.recalculateSingleAttr(attrIndex);
|
||
}
|
||
|
||
// ==================== NeAttrs(负面状态)管理 ====================
|
||
/**
|
||
* 清理单个NeAttr(负面状态)
|
||
* @param neAttrIndex NeAttrs索引(如NeAttrs.IN_STUN、NeAttrs.IN_FROST等)
|
||
* 清理即将该状态的value和time都设为0
|
||
*/
|
||
clearNeAttr(neAttrIndex: number): void {
|
||
if (this.NeAttrs[neAttrIndex]) {
|
||
this.NeAttrs[neAttrIndex].value = 0;
|
||
this.NeAttrs[neAttrIndex].time = 0;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 清理所有NeAttrs(负面状态)
|
||
* 清理即将所有状态的value和time都设为0
|
||
*/
|
||
clearAllNeAttrs(): void {
|
||
for (const key in this.NeAttrs) {
|
||
this.NeAttrs[key].value = 0;
|
||
this.NeAttrs[key].time = 0;
|
||
}
|
||
}
|
||
|
||
public isStun() {
|
||
return this.NeAttrs[NeAttrs.IN_STUN].time > 0;
|
||
}
|
||
public isFrost() {
|
||
return this.NeAttrs[NeAttrs.IN_FROST].time > 0;
|
||
}
|
||
|
||
update(dt: number){
|
||
if(!smc.mission.play||smc.mission.pause) return
|
||
// if(this.is_dead) {
|
||
// this.ent.destroy();
|
||
// return
|
||
// }
|
||
this.BaseUp(dt)
|
||
|
||
// 更新所有按时间减少的buff和debuff
|
||
this.in_stop(dt);
|
||
// 处理伤害队列
|
||
this.processDamageQueue();
|
||
// 更新临时 buff/debuff 时间
|
||
this.updateTemporaryBuffsDebuffs(dt);
|
||
this.BUFFCOMP.hp_show(this.hp,this.Attrs[Attrs.HP_MAX])
|
||
this.BUFFCOMP.mp_show(this.mp,this.Attrs[Attrs.MP_MAX])
|
||
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||
}
|
||
BaseUp(dt:number){
|
||
this.mp += HeroUpSet.MP*dt
|
||
this.hp += HeroUpSet.HP*dt
|
||
if(this.mp > this.Attrs[Attrs.MP_MAX]) this.mp = this.Attrs[Attrs.MP_MAX]
|
||
if(this.hp > this.Attrs[Attrs.HP_MAX]) this.hp = this.Attrs[Attrs.HP_MAX]
|
||
|
||
}
|
||
do_fight_end(){
|
||
this.as.do_buff()
|
||
}
|
||
get isActive() {
|
||
return this.ent.has(HeroViewComp) && this.node?.isValid;
|
||
}
|
||
//状态切
|
||
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 = this.Attrs[Attrs.SHIELD_MAX] +=shield
|
||
if(this.shield>0) this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||
}
|
||
|
||
health(hp: number = 0,is_num:boolean=true) {
|
||
this.BUFFCOMP.heathed();
|
||
let real_hp=0
|
||
let hp_max=this.Attrs[Attrs.HP_MAX]
|
||
let lost_hp=hp_max-this.hp
|
||
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.hp+=real_hp;
|
||
this.BUFFCOMP.tooltip(TooltipTypes.health,real_hp.toFixed(0));
|
||
}
|
||
this.BUFFCOMP.hp_show(this.hp,this.Attrs[Attrs.HP_MAX])
|
||
// this.update_vm
|
||
}
|
||
|
||
|
||
/** 静止时间 */
|
||
in_stop (dt: number) {
|
||
|
||
}
|
||
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.is_count_dead) return
|
||
this.is_count_dead=true
|
||
if(this.fac==FacSet.MON){
|
||
this.scheduleOnce(()=>{
|
||
this.do_drop()
|
||
},0.1)
|
||
}
|
||
if(this.fac==FacSet.HERO){
|
||
this.scheduleOnce(()=>{
|
||
oops.message.dispatchEvent(GameEvent.HeroDead,{hero_uuid:this.hero_uuid})
|
||
},0.1)
|
||
}
|
||
|
||
if(this.fac==FacSet.HERO){
|
||
//console.log("[HeroViewComp]:英雄死亡")
|
||
// oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false})
|
||
}
|
||
|
||
|
||
}
|
||
do_drop(){
|
||
|
||
}
|
||
|
||
do_atked(remainingDamage:number,CAttrs:any,s_uuid:number){
|
||
let SConf=SkillSet[s_uuid]
|
||
this.do_atked_trigger()
|
||
if(this.check_dodge()) return
|
||
let is_crit = this.check_crit(CAttrs[Attrs.CRITICAL])
|
||
if(this == null) return;
|
||
let damage = this.count_damage(remainingDamage)
|
||
if(is_crit) {
|
||
damage = Math.floor(damage * (1 + (FightSet.CRIT_DAMAGE+CAttrs[Attrs.CRITICAL_DMG])/100))
|
||
}
|
||
// console.log(this.hero_name+"[HeroViewComp]:heroview :damage|hp|hp_max",damage,this.hp,this.Attrs[BuffAttr.HP_MAX])
|
||
damage=this.check_shield(damage)
|
||
if(damage <= 0) return
|
||
this.hp -= damage;
|
||
if(this.hp <= 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.back()
|
||
this.showDamage(damage, is_crit,SConf.AtkedName);
|
||
}
|
||
//后退
|
||
back(){
|
||
if(this.fac==FacSet.MON) {
|
||
let tx=this.node.position.x+5
|
||
if(tx > 320) tx=320
|
||
tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start()
|
||
}
|
||
if(this.fac==FacSet.HERO) {
|
||
let tx=this.node.position.x-5
|
||
if(tx < -320) tx=-320
|
||
tween(this.node).to(0.1, { position:v3(tx,this.node.position.y,0)}).start()
|
||
}
|
||
}
|
||
//伤害计算 debuff 易伤
|
||
count_damage(remainingDamage:number){
|
||
|
||
return remainingDamage
|
||
}
|
||
|
||
check_shield(damage:number){
|
||
if(this.shield <= 0 ) return damage
|
||
if(this.shield >= damage){
|
||
this.shield -= damage
|
||
this.BUFFCOMP.tooltip(TooltipTypes.uskill,"*吸收*");
|
||
if(this.shield <= 0){
|
||
this.shield=this.Attrs[Attrs.SHIELD_MAX]=0
|
||
}
|
||
damage = 0
|
||
}
|
||
if(this.shield < damage){
|
||
damage=damage-this.shield
|
||
this.shield=0
|
||
this.Attrs[Attrs.SHIELD_MAX]=0
|
||
}
|
||
this.BUFFCOMP.show_shield(this.shield,this.Attrs[Attrs.SHIELD_MAX])
|
||
return damage
|
||
}
|
||
|
||
check_dodge(){
|
||
if(this.Attrs[Attrs.DODGE] > 0){
|
||
let random = Math.random()*100
|
||
if(random < this.Attrs[Attrs.DODGE]) {
|
||
this.BUFFCOMP.tooltip(TooltipTypes.uskill,"*闪避*");
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
check_crit(crit:number=0){
|
||
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
|
||
}
|
||
|
||
do_dead_trigger(){ //死亡特殊处理
|
||
if(this.is_dead||this.fac==FacSet.MON) return
|
||
|
||
}
|
||
do_atked_trigger(){ //受伤特殊处理
|
||
if(this.is_dead||this.fac==FacSet.MON) return
|
||
|
||
}
|
||
|
||
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_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.tooltip(TooltipTypes.skill,skill.name,skill_id)
|
||
break
|
||
case "atk":
|
||
this.as.atk()
|
||
break
|
||
}
|
||
}
|
||
|
||
|
||
/** 显示伤害数字 */
|
||
|
||
showDamage(damage: number, isCrit: boolean,anm:string="atked") {
|
||
this.damageQueue.push({
|
||
damage,
|
||
isCrit,
|
||
delay: this.damageInterval,
|
||
anm
|
||
});
|
||
}
|
||
|
||
/** 处理伤害队列 */
|
||
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.BUFFCOMP.hp_show(this.hp,this.Attrs[Attrs.HP_MAX])
|
||
this.BUFFCOMP.in_atked(anm,this.fac==FacSet.HERO?1:-1)
|
||
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);
|
||
}
|
||
}
|
||
}
|