技能碰撞改回物理碰撞
This commit is contained in:
@@ -6,7 +6,6 @@ import { HeroModelComp } from "./HeroModelComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { Talents } from "../common/config/TalentSet";
|
||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||
/** 角色实体 */
|
||||
@@ -25,12 +24,13 @@ export class Hero extends ecs.Entity {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);;
|
||||
this.remove(HeroViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,is_call:boolean=false,lv:number=1) {
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,info:any={ap:0,hp:0}) {
|
||||
console.log("英雄加载:",uuid,pos,scale,info)
|
||||
scale = 1
|
||||
let box_group=BoxSet.HERO
|
||||
var path = "game/heros/"+HeroInfo[uuid].path;
|
||||
@@ -39,10 +39,7 @@ export class Hero extends ecs.Entity {
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!
|
||||
node.setPosition(pos)
|
||||
this.hero_init(uuid,node,scale,box_group,is_call,lv)
|
||||
oops.message.dispatchEvent("hero_load",this)
|
||||
}
|
||||
hero_init(uuid:number=1001,node:Node,scale:number=1,box_group=BoxSet.HERO,is_call:boolean=false,lv:number=1){
|
||||
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
let hero= HeroInfo[uuid] // 共用英雄数据
|
||||
hv.scale = scale;
|
||||
@@ -53,25 +50,22 @@ export class Hero extends ecs.Entity {
|
||||
hv.hero_name= hero.name;
|
||||
hv.speed =hv.ospeed = hero.speed;
|
||||
hv.dis = hero.dis;
|
||||
hv.hp= hv.hp_max =hero.hp;
|
||||
hv.ap = hero.ap;
|
||||
hv.hp= hv.hp_max =hero.hp+info.hp;
|
||||
hv.ap = hero.ap+info.ap;
|
||||
hv.cd = hero.a_cd
|
||||
hv.rate=hero.rate
|
||||
hv.r_up=hero.ra_up
|
||||
hv.atk_skill=hero.skills[0]
|
||||
this.add(hv);
|
||||
|
||||
// // 初始化多个技能组件
|
||||
// const skillsComp = this.get(HeroSkillsComp);
|
||||
// // 正确初始化已有技能
|
||||
// hero.skills.forEach(skillId => {
|
||||
// this.addSkill(skillId); // 使用addSkill方法确保初始化
|
||||
// });
|
||||
|
||||
// 初始化移动参数
|
||||
const move = this.get(BattleMoveComp);
|
||||
move.direction = 1; // 向右移动
|
||||
move.targetX = 800; // 右边界
|
||||
move.targetX = 800; // 右边界'
|
||||
|
||||
|
||||
oops.message.dispatchEvent("hero_load",this)
|
||||
}
|
||||
|
||||
|
||||
// 添加技能
|
||||
public addSkill(skillId: number) {
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
|
||||
@@ -10,21 +10,21 @@ export default class HeroAnmComp extends Component{
|
||||
private _hasStop = true;
|
||||
onLoad () {
|
||||
var spine = this.spine = this.getComponent('sp.Skeleton') as sp.Skeleton;
|
||||
this._setMix('Walking', 'Idle');
|
||||
this._setMix('Walking', 'Attacking');
|
||||
this._setMix('Walking', 'Taunt');
|
||||
this._setMix('Idle', 'Attacking');
|
||||
this._setMix('Idle', 'Taunt');
|
||||
this._setMix('Idle', 'Walking');
|
||||
this._setMix('Attacking', 'Idle');
|
||||
this._setMix('Attacking', 'Walking');
|
||||
this._setMix('Taunt', 'Walking');
|
||||
this._setMix('Taunt', 'Idle');
|
||||
// this._setMix('Walking', 'Idle');
|
||||
// this._setMix('Walking', 'Attacking');
|
||||
// this._setMix('Walking', 'Taunt');
|
||||
// this._setMix('Idle', 'Attacking');
|
||||
// this._setMix('Idle', 'Taunt');
|
||||
// this._setMix('Idle', 'Walking');
|
||||
// this._setMix('Attacking', 'Idle');
|
||||
// this._setMix('Attacking', 'Walking');
|
||||
// this._setMix('Taunt', 'Walking');
|
||||
// this._setMix('Taunt', 'Idle');
|
||||
|
||||
spine.setCompleteListener((trackEntry) => {
|
||||
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
|
||||
if (animationName === 'Attacking'||animationName==='Taunt'||animationName==='Hurt') {
|
||||
this.spine!.clearTrack(1);
|
||||
// this.spine!.clearTrack(1);
|
||||
}
|
||||
var loopCount = Math.floor(trackEntry.trackTime / trackEntry.animationEnd);
|
||||
// console.log("[track %s][animation %s] complete: %s", trackEntry.trackIndex, animationName, loopCount);
|
||||
@@ -67,7 +67,7 @@ export default class HeroAnmComp extends Component{
|
||||
// ANIMATIONS
|
||||
|
||||
stop () {
|
||||
this.spine?.clearTrack(0);
|
||||
// this.spine?.clearTrack(0);
|
||||
this._hasStop = true;
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ export default class HeroAnmComp extends Component{
|
||||
this.spine?.setAnimation(0, 'Idle', true);
|
||||
}
|
||||
|
||||
_setMix (anim1: string, anim2: string) {
|
||||
this.spine?.setMix(anim1, anim2, this.mixTime);
|
||||
this.spine?.setMix(anim2, anim1, this.mixTime);
|
||||
}
|
||||
// _setMix (anim1: string, anim2: string) {
|
||||
// this.spine?.setMix(anim1, anim2, this.mixTime);
|
||||
// this.spine?.setMix(anim2, anim1, this.mixTime);
|
||||
// }
|
||||
}
|
||||
68
assets/script/game/hero/HeroInfoComp.ts
Normal file
68
assets/script/game/hero/HeroInfoComp.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { _decorator, Label, resources, Sprite, SpriteAtlas } 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 { smc } from "../common/SingletonModuleComp";
|
||||
import { HeroModelComp } from "./HeroModelComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { HeroInfo, HeroPos, HeroSet } from "../common/config/heroSet";
|
||||
import { MissionComp } from "../map/MissionComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroInfoCompComp')
|
||||
@ecs.register('HeroInfoComp', false)
|
||||
export class HeroInfoCompComp extends CCComp {
|
||||
@property(Number)
|
||||
c_id:number=0
|
||||
@property(Boolean)
|
||||
is_Change:boolean=false
|
||||
|
||||
has_hero:boolean=false
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
this.init()
|
||||
}
|
||||
init(){
|
||||
this.has_hero=false
|
||||
}
|
||||
update(dt: number): void {
|
||||
if(!smc.mission.play) return
|
||||
this.update_info()
|
||||
}
|
||||
update_info(){
|
||||
let heros=ecs.query(ecs.allOf(HeroModelComp))
|
||||
for(let hero of heros){
|
||||
let info=hero.get(HeroViewComp)
|
||||
if(info.node.position.x==HeroPos[this.c_id].pos.x){
|
||||
this.has_hero=true
|
||||
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=info.ap.toString()
|
||||
this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=info.hp.toString()
|
||||
this.node.getChildByName("name").getComponent(Label).string=HeroInfo[info.hero_uuid].name
|
||||
var icon_path = "game/heros/herois"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = this.node.getChildByName("mask").getChildByName("icon").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(HeroInfo[info.hero_uuid].path);
|
||||
});
|
||||
}
|
||||
}
|
||||
if(this.is_Change){
|
||||
this.node.getChildByName("change").active=this.has_hero
|
||||
this.node.getChildByName("select").active=!this.has_hero
|
||||
}
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/hero/HeroInfoComp.ts.meta
Normal file
9
assets/script/game/hero/HeroInfoComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e8cba331-88b0-4b08-9756-374a422d3c28",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color, RigidBody, RigidBody2D} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween, Color} 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";
|
||||
@@ -39,7 +39,6 @@ export class HeroViewComp extends CCComp {
|
||||
atk_range:number = 150;
|
||||
|
||||
box_group:number = BoxSet.HERO;
|
||||
rigid:RigidBody2D=null!;
|
||||
|
||||
|
||||
is_dead:boolean = false; //是否摧毁
|
||||
@@ -47,7 +46,8 @@ export class HeroViewComp extends CCComp {
|
||||
is_atking:boolean = false;
|
||||
is_boss:boolean = false;
|
||||
is_big_boss:boolean = false;
|
||||
|
||||
rate:number=0;
|
||||
r_up:number=0;
|
||||
hp: number = 100; /** 血量 */
|
||||
hp_max: number = 100; /** 最大血量 */
|
||||
hp_speed: number = 0; //每秒回复量
|
||||
@@ -90,7 +90,7 @@ export class HeroViewComp extends CCComp {
|
||||
onLoad() {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
let anm = this.node.getChildByName("anm")
|
||||
anm.setScale(anm.scale.x*0.7,anm.scale.y*0.7);
|
||||
anm.setScale(anm.scale.x*0.8,anm.scale.y*0.8);
|
||||
// 注册单个碰撞体的回调函数
|
||||
|
||||
// let collider = this.getComponent(Collider2D);
|
||||
@@ -102,16 +102,10 @@ export class HeroViewComp extends CCComp {
|
||||
// collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
|
||||
// // collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
// }
|
||||
// this.rigid = this.getComponent(RigidBody2D);
|
||||
// if(this.rigid.sleep){
|
||||
// console.log("hero rigid sleep ",this.scale,this.rigid);
|
||||
// this.rigid.wakeUp();
|
||||
// }
|
||||
|
||||
}
|
||||
// onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
// console.log("碰撞开始 ",this.scale,seCol,oCol);
|
||||
|
||||
|
||||
// }
|
||||
// onEndContact (seCol: Collider2D, oCol: Collider2D) { console.log("碰撞结束 ",this.scale,seCol,oCol);}
|
||||
// onPreSolve (seCol: Collider2D, oCol: Collider2D) {console.log("碰撞预处理 ",this.scale,seCol,oCol);}
|
||||
@@ -133,10 +127,10 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
update(dt: number){
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
if(this.is_dead) {
|
||||
if(!this.in_grave()) this.to_grave()
|
||||
return
|
||||
}
|
||||
// if(this.is_dead) {
|
||||
// this.ent.destroy();
|
||||
// return
|
||||
// }
|
||||
this.hp_show()
|
||||
if(this.ice_cd > 0){
|
||||
this.ice_cd -=dt;
|
||||
@@ -248,31 +242,23 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
//掉落物品
|
||||
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);
|
||||
// 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_grave(){
|
||||
let pos =v3(-1000,this.node.position.y,this.node.position.z)
|
||||
if(this.fac==1) pos.x=1000
|
||||
this.node.setPosition(pos)
|
||||
}
|
||||
//是否在墓地
|
||||
in_grave(){
|
||||
return this.node.position.y <= -900;
|
||||
}
|
||||
to_alive(){
|
||||
let pos =v3(HeroSet.Start_x[this.type],HeroSet.Start_y[this.type],this.node.position.z)
|
||||
this.node.setPosition(pos)
|
||||
this.revive()
|
||||
}
|
||||
|
||||
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;
|
||||
this.node.destroy();
|
||||
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]
|
||||
|
||||
@@ -1,37 +1,22 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:47:56
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:43:04
|
||||
*/
|
||||
import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas} from "cc";
|
||||
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { HeroModelComp } from "./HeroModelComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
||||
import { HeroInfo } from "../common/config/heroSet";
|
||||
import { Talents } from "../common/config/TalentSet";
|
||||
import { MonModelComp } from "./MonModelComp";
|
||||
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
|
||||
import { HeroSkillsComp } from "../skill/heroSkillsComp";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
HeroModel!: MonModelComp;
|
||||
HeroView!: HeroViewComp;
|
||||
BattleMove!: BattleMoveComp;
|
||||
HeroSkills!: HeroSkillsComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
BattleMoveComp,
|
||||
HeroSkillsComp,
|
||||
MonModelComp
|
||||
);
|
||||
}
|
||||
@@ -46,7 +31,7 @@ export class Monster extends ecs.Entity {
|
||||
scale=-1
|
||||
let box_group=BoxSet.MONSTER
|
||||
console.log("mon load",uuid)
|
||||
this.addComponents<ecs.Comp>( MonModelComp, BattleMoveComp);
|
||||
// this.addComponents<ecs.Comp>( MonModelComp, BattleMoveComp);
|
||||
var path = "game/heros/"+HeroInfo[uuid].path;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
@@ -67,8 +52,6 @@ export class Monster extends ecs.Entity {
|
||||
var hv = node.getComponent(HeroViewComp)!;
|
||||
// console.log("hero_init",buff)
|
||||
let hero= HeroInfo[uuid] // 共用英雄数据
|
||||
let talent= smc.vmdata.talent //角色英雄数据
|
||||
let talents=Talents;
|
||||
hv.scale = scale;
|
||||
hv.fac = 1;
|
||||
hv.type = hero.type;
|
||||
@@ -84,42 +67,7 @@ export class Monster extends ecs.Entity {
|
||||
hv.atk_skill=hero.skills[0]
|
||||
this.add(hv);
|
||||
|
||||
// // 初始化多个技能组件
|
||||
// const skillsComp = this.get(HeroSkillsComp);
|
||||
// // 正确初始化已有技能
|
||||
// hero.skills.forEach(skillId => {
|
||||
// this.addSkill(skillId); // 使用addSkill方法确保初始化
|
||||
// });
|
||||
|
||||
// 初始化移动参数
|
||||
const move = this.get(BattleMoveComp);
|
||||
move.direction = 1; // 向右移动
|
||||
move.targetX = 800; // 右边界
|
||||
}
|
||||
// 添加技能
|
||||
public addSkill(skillId: number) {
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
if (comp.skills.indexOf(skillId) === -1) {
|
||||
comp.skills.push(skillId);
|
||||
comp.cooldowns.set(skillId, 0);
|
||||
comp.counters.set(skillId, 0);
|
||||
console.log(`技能${skillId}初始化完成`,
|
||||
'当前cooldowns:', comp.cooldowns,
|
||||
'当前counters:', comp.counters);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 移除技能
|
||||
public removeSkill(skillId: number) {
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
comp.skills = comp.skills.filter(id => id !== skillId);
|
||||
}
|
||||
|
||||
public levelUp() {
|
||||
// ...升级逻辑...
|
||||
const comp = this.get(HeroSkillsComp);
|
||||
comp.skills.forEach(skillId => {
|
||||
comp.resetCooldown(skillId);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user