This commit is contained in:
2024-09-12 07:58:03 +08:00
parent 4501876c37
commit 50d192b7b1
64 changed files with 12158 additions and 4612 deletions

View File

@@ -19,7 +19,6 @@ import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/
import { SkillCom } from "../skills/SkillCom";
import { SkillSet } from "../common/config/SkillSet";
import { Tooltip } from "../skills/Tooltip";
import { HeroBuffComp } from "./HeroBuffComp";
import { MoveToComp } from "../common/ecs/position/MoveTo";
import { BoxRangComp } from "./BoxRangComp";
const { ccclass, property } = _decorator;
@@ -36,7 +35,6 @@ export class HeroViewComp extends CCComp {
@property(Node)
BoxRang:Node =null!
buff:HeroBuffComp =null!
is_role:boolean = false;
enemy_pos:Vec3=null!;
enemy:any=null!;
@@ -84,17 +82,18 @@ export class HeroViewComp extends CCComp {
is_stop:boolean = false;
is_atking:boolean = false;
buffs:any=[];
buff_shields:any=[];
buff_atks:any = [];
onLoad() {
this.as = this.getComponent(HeroSpine);
this.buff=this.node.getComponent(HeroBuffComp);
// this.BoxRang = this.node.getChildByName("range_box");
// this.BoxRang = this.node.getChildByName("range_box");
} /** 视图层逻辑代码分离演示 */
start () {
this.as.move()
this.sprite = this.node.getChildByName("anm").getComponent(Sprite);
this.node.getChildByName("top").getChildByName("shield").active = false;
// this.node.getChildByName("top").setScale(this.scale,1);
// this.node.getChildByName("atk").setScale(this.scale,1);
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
@@ -110,7 +109,6 @@ export class HeroViewComp extends CCComp {
// this.enemy=smc.Role.RoleView.node
// // console.log("mon enemy ",this.enemy);
// }
this.buff.group=this.box_group
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
@@ -140,30 +138,8 @@ export class HeroViewComp extends CCComp {
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
// if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
// this.is_atking = true;
// this.stop_cd = 0.1;
// }
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
// if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
// let self_pos=selfCollider.node.getPosition();
// let other_pos=otherCollider.node.getPosition();
// // console.log('mon view group 相同');
// switch (selfCollider.group) {
// case BoxSet.HERO:
// if(self_pos.x < other_pos.x){
// // this.stop_cd=0.1
// }
// break;
// case BoxSet.MONSTER:
// if(self_pos.x > other_pos.x){
// // this.stop_cd=0.1
// }
// break
// }
// }
}
@@ -171,8 +147,9 @@ export class HeroViewComp extends CCComp {
if (this.timer.update(dt)) {
this.power_change(this.power_speed)
}
this.check_buff_atks(dt)
this.in_destroy();
this.in_shield();
this.in_shield(dt);
this.in_stop(dt);
this.in_act(dt);
this.move(dt);
@@ -185,7 +162,7 @@ export class HeroViewComp extends CCComp {
if(this.stop_cd > 0){
return
}
if (this.scale === 1 && this.node.position.x >= BoxSet.MONSTER_START) {
if (this.scale === 1 && this.node.position.x >= BoxSet.MONSTER_START-this.atk_dis) {
return;
}
@@ -286,7 +263,6 @@ export class HeroViewComp extends CCComp {
this.tooltip(3,smc.skills[this.max_skill_uuid].name,this.max_skill_uuid);
}
in_act(dt: number) {
if(this.atk_time >= this.atk_cd){
if(this.is_atking){
this.atk_time = 0;
@@ -300,16 +276,7 @@ export class HeroViewComp extends CCComp {
this.atk_time += dt;
}
}
in_shield(){
let shield_progress= this.shield/this.shield_max;
this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
// if(this.shield <= 0){
// this.node.getChildByName("shield").active=false
// }else{
// this.node.getChildByName("shield").active=true
// }
}
hp_change(hp: number){
if(this.is_dead){
return;
@@ -344,6 +311,10 @@ export class HeroViewComp extends CCComp {
}
add_hp(hp: number=0){
console.log("hero 加血动画");
this.hp+=hp;
if(this.hp > this.hp_max){
this.hp = this.hp_max;
}
this.tooltip(2,hp.toString());
let hp_progress= this.hp/this.hp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
@@ -351,11 +322,25 @@ export class HeroViewComp extends CCComp {
add_atk(atk: number,time:number=0){
if(time > 0){
let buff={atk:atk,time:time}
this.buffs.push(buff);
this.buff_atks.push(buff);
}else{
this.atk += atk;
}
}
check_buff_atks(dt: number){
for(let i=0;i<this.buff_atks.length;i++){
let buff=this.buff_atks[i];
buff.time -= dt;
if(buff.time <= 0){
if(buff.atk > 0)this.atk -= buff.atk;
this.buff_atks.splice(i,1);
}
}
}
add_shield(shield: number,time:number=0){
this.shield =this.shield_max=shield
this.shield_time = time;
}
shield_change(hp: number){
let ls=this.shield - hp;
if(ls <= 0){
@@ -366,15 +351,25 @@ export class HeroViewComp extends CCComp {
return 0;
}
}
check_buffs(dt: number){
for(let i=0;i<this.buffs.length;i++){
let buff=this.buffs[i];
buff.time -= dt;
if(buff.time <= 0){
if(buff.atk > 0)this.atk -= buff.atk;
if(buff.shield > 0)this.shield=this.shield_max=0;
this.buffs.splice(i,1);
in_shield(dt: number){
if(this.shield_time <= 0){
return
}
if(this.shield_time > 0){
this.shield_time -= dt;
if(this.shield_time <= 0){
this.shield_time = 0;
this.shield = this.shield_max=0;
this.node.getChildByName("top").getChildByName("shield").active=false
}
let shield_progress= this.shield/this.shield_max;
this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
}
if(this.shield <= 0){
this.shield_time=0
this.node.getChildByName("top").getChildByName("shield").active=false
}else{
this.node.getChildByName("top").getChildByName("shield").active=true
}
}
tooltip(type:number=1,value:string="",s_uuid:number=1001){
@@ -385,9 +380,7 @@ export class HeroViewComp extends CCComp {
pos.y=pos.y+60;
tip.load(pos,type,value,s_uuid,node);
}
get_mon_pos(){
return this.node.getPosition()
}
/** 静止时间 */
in_stop (dt: number) {
if(this.stop_cd > 0){