126 lines
4.4 KiB
TypeScript
126 lines
4.4 KiB
TypeScript
/*
|
|
* @Author: dgflash
|
|
* @Date: 2021-11-18 17:42:59
|
|
* @LastEditors: dgflash
|
|
* @LastEditTime: 2022-08-17 12:36:18
|
|
*/
|
|
|
|
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,IPhysics2DContact,Material,Sprite,ProgressBar} 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 { Role2Spine } from "./Role2Spine";
|
|
import {BoxSet} from "../../common/config/BoxSet"
|
|
import { smc } from "../../common/SingletonModuleComp";
|
|
import { SkillCom } from "../../skills/SkillCom";
|
|
import { Skill } from "../../skills/Skill";
|
|
import { SkillSet } from "../../common/config/SkillSet";
|
|
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { RandomManager } from "../../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 角色显示组件 */
|
|
@ccclass('Role2ViewComp') // 定义为 Cocos Creator 组件
|
|
@ecs.register('RoleView2', false) // 定义为 ECS 组件
|
|
export class Role2ViewComp extends CCComp {
|
|
@property(Material)
|
|
hitFlashMaterial: Material;
|
|
orginalFlashMaterial: Material;
|
|
sprite: Sprite;
|
|
/** 角色动画 */
|
|
as: Role2Spine = null!;
|
|
/** 角色属性 */
|
|
hp: number = 1000;
|
|
hp_max:number = 1000;
|
|
power: number = 0;
|
|
stop_cd:number = 0;
|
|
atk_cd:number = 2;
|
|
atk:number = 10;
|
|
skill_uuid:number = 9003;
|
|
max_skill_uuid:number = 1001;
|
|
skin:string ="Character01";
|
|
private atk_time:Timer = new Timer(1);
|
|
|
|
onLoad() {
|
|
this.as = this.getComponent(Role2Spine);
|
|
|
|
}
|
|
start () {
|
|
// this.as.setSkin(this.skin);
|
|
this.atk_time = new Timer(this.atk_cd);
|
|
// this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
|
// this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
|
console.log("Role view start")
|
|
let collider = this.getComponent(Collider2D);
|
|
if (collider) {
|
|
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
}
|
|
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
|
if(otherCollider.tag==BoxSet.SKILL_TAG){
|
|
if(selfCollider.group != otherCollider.group){
|
|
let skill = otherCollider.node.getComponent(SkillCom)!;
|
|
// console.log('onPostSolve',skill);
|
|
// this.in_atked();
|
|
if(this.hp <= 0 ){
|
|
return
|
|
}
|
|
this.hp_change(skill.atk);
|
|
}
|
|
}
|
|
}
|
|
// onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
|
// onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
|
// onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {}
|
|
|
|
update(dt: number){
|
|
if (this.atk_time.update(dt)) {
|
|
this.toAtk(this.skill_uuid);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
toAtk(uuid) {
|
|
this.as.atk();
|
|
this.scheduleOnce(()=>{
|
|
this.shoot(this.skill_uuid);
|
|
},0.4)
|
|
}
|
|
|
|
shoot(skill_uuid:number){
|
|
console.log("monster shoot");
|
|
let skill = ecs.getEntity<Skill>(Skill);
|
|
let pos = v3(60,50)
|
|
let scale = 1
|
|
let speed =smc.skills[skill_uuid].speed;
|
|
let dis = smc.skills[skill_uuid].dis;
|
|
let atk = smc.skills[skill_uuid].atk+this.atk;
|
|
let uuid = skill_uuid;
|
|
skill.load(pos,speed,dis,scale,this.node,uuid,atk,2);
|
|
}
|
|
setSkin(skin:string="Character01"){
|
|
this.as.setSkin(skin);
|
|
}
|
|
|
|
in_atked() {
|
|
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
|
this.scheduleOnce(() => {
|
|
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
|
}, 0.1);
|
|
}
|
|
hp_change(hp: number){
|
|
this.hp -= hp;
|
|
if(this.hp > this.hp_max){
|
|
this.hp = this.hp_max;
|
|
}
|
|
let hp_progress= this.hp/this.hp_max;
|
|
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
|
if(this.hp <= 0){
|
|
console.log("dead");
|
|
}
|
|
}
|
|
|
|
} |