68 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-10-30 02:34:11 +08:00
import { TableGRoleSkill } from "../../../resources/config/ts/TableGRoleSkill";
import GRoleBase from "../base/role/GRoleBase";
import { GSkillBase, GSkillState } from "./GSkill";
//冷却技能基类 用于多长时间释放技能
export default abstract class GSkillCDBase implements GSkillBase {
//冷却总时间
2023-10-30 18:53:21 +08:00
cdTatal:number = 0;
2023-10-30 02:34:11 +08:00
//冷却时间
2023-10-30 18:53:21 +08:00
cdTime:number = 0;
2023-10-30 02:34:11 +08:00
bind(role:GRoleBase<{}>,info: TableGRoleSkill):GSkillCDBase {
return this;
}
2023-10-30 18:53:21 +08:00
//是否可以释放技能
2023-10-30 02:34:11 +08:00
isRelease(): boolean {
2023-10-30 18:53:21 +08:00
return this.cdTime >= this.cdTatal;
2023-10-30 02:34:11 +08:00
}
//释放技能
release():boolean {
2023-10-30 18:53:21 +08:00
//是否可以释放技能
if(!this.isRelease()) return false;
this.cdTime = 0;
2023-10-30 02:34:11 +08:00
return this.onRelease();
}
//子类实现释放
abstract onRelease():boolean;
2023-10-30 18:53:21 +08:00
//查询状态
2023-10-30 02:34:11 +08:00
state(): GSkillState {
2023-10-30 18:53:21 +08:00
if(this.isReleasing()){
2023-10-30 02:34:11 +08:00
return GSkillState.Releasing
2023-10-30 18:53:21 +08:00
}
if(this.isRelease())
return GSkillState.Releasable
2023-10-30 02:34:11 +08:00
else
return GSkillState.NoRelease
2023-10-30 18:53:21 +08:00
2023-10-30 02:34:11 +08:00
}
2023-10-30 18:53:21 +08:00
//是否正在释放技能
isReleasing(): boolean{
return false;
}
//更新
onUpdate(dt:number){
if(this.state() == GSkillState.NoRelease){
this.cdTime += (dt / 1000);
}
}
//返回进度
getProgress():number{
return this.cdTime / this.cdTatal;
}
2023-10-30 02:34:11 +08:00
}