假期修改

This commit is contained in:
2024-09-18 12:45:05 +08:00
parent 2095393757
commit cd0dc9fe7c
79 changed files with 7383 additions and 1449 deletions

View File

@@ -26,10 +26,10 @@ export class BoxRangComp extends CCComp {
this.HeroViewComp=this.Hero_node.getComponent(HeroViewComp);
// console.log("range box",this.HeroViewComp);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {

View File

@@ -17,6 +17,8 @@ import { HeroViewComp } from "./HeroViewComp";
import { BoxSet } from "../common/config/BoxSet";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { HeroSet,MonSet } from "../common/config/heroSet";
import { Role } from "../Role/Role";
import { MoveToComp } from "../common/ecs/position/MoveTo";
/** 角色实体 */
@ecs.register(`Hero`)
export class Hero extends ecs.Entity {
@@ -24,6 +26,7 @@ export class Hero extends ecs.Entity {
HeroModel!: HeroModelComp;
// 视图层
HeroView!: HeroViewComp;
protected init() {
this.addComponents<ecs.Comp>( HeroModelComp);
@@ -32,12 +35,12 @@ export class Hero extends ecs.Entity {
destroy(): void {
this.remove(HeroViewComp);
this.remove(MoveToComp);
super.destroy();
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!,index:number=-1) {
var path = "game/hero/"+smc.heros[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
@@ -45,10 +48,33 @@ export class Hero extends ecs.Entity {
// var as = node.getComponent(HeroSpine);
// let ratio=this.set_ratio(uuid);
// node.setScale(node.scale.x*scale*ratio, node.scale.y*ratio, 0);
pos.x=smc.Role.RoleView.node.position.x+pos.x;
pos.y=smc.Role.RoleView.node.position.y+pos.y;
node.setPosition(pos)
this.hero_init(uuid,node)
this.hero_init(uuid,node,index)
oops.message.dispatchEvent("hero_load",this)
}
hero_init(uuid:number=1001,node:Node,index:number=-1){
var hv = node.getComponent(HeroViewComp)!;
// console.log("hero_init",buff)
hv.speed =hv.ospeed = smc.heros[uuid].speed;
hv.hero_name= smc.heros[uuid].name;
hv.hp= hv.hp_max = smc.heros[uuid].hp;
hv.level = smc.heros[uuid].level;
hv.atk = smc.heros[uuid].atk;
hv.atk_cd = smc.heros[uuid].atk_cd;
hv.atk_dis = smc.heros[uuid].atk_dis;
hv.power = smc.heros[uuid].power;
hv.power_max= smc.heros[uuid].power_max;
hv.type = smc.heros[uuid].type;
hv.skill_uuid = smc.heros[uuid].skill_uuid;
hv.max_skill_uuid = smc.heros[uuid].max_skill_uuid;
hv.scale = 1;
hv.role_heros_index = index;
hv.Tpos = v3(0,0,0);
this.add(hv);
}
set_ratio(uuid:number){
let ratio=1;
switch (smc.heros[uuid].level) {
@@ -69,23 +95,4 @@ export class Hero extends ecs.Entity {
}
return ratio;
}
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(HeroViewComp)!;
// console.log("hero_init",buff)
mv.speed =mv.ospeed = smc.heros[uuid].speed;
mv.hero_name= smc.heros[uuid].name;
mv.hp= mv.hp_max = smc.heros[uuid].hp;
mv.level = smc.heros[uuid].level;
mv.atk = smc.heros[uuid].atk;
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.atk_dis = smc.heros[uuid].atk_dis;
mv.power = smc.heros[uuid].power;
mv.power_max= smc.heros[uuid].power_max;
mv.type = smc.heros[uuid].type;
mv.skill_uuid = smc.heros[uuid].skill_uuid;
mv.max_skill_uuid = smc.heros[uuid].max_skill_uuid;
mv.scale = 1;
mv.Tpos = v3(0,0,0);
this.add(mv);
}
}

View File

@@ -21,7 +21,7 @@ export class HeroSpine extends Component {
atk_clip: AnimationClip = null!;
max_clip: AnimationClip = null!;
move_clip: AnimationClip = null!;
default_clip:string = "move";
default_clip:string = "";
onLoad() {
// 角色控制组件
@@ -31,6 +31,7 @@ export class HeroSpine extends Component {
this.atk_clip = this.animator.clips[1];
this.max_clip = this.animator.clips[2];
this.move_clip = this.animator.clips[3];
this.default_clip=this.move_clip.name;
let animation = this.animator.getComponent(Animation);
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
}
@@ -40,6 +41,7 @@ export class HeroSpine extends Component {
/** 初始化动画 */
protected initAnimator() {
this.animator=this.node.getChildByName("anm").getComponent(Animation);
// console.log("mon spine init",this.animator);
}

View File

@@ -33,7 +33,9 @@ export class HeroViewComp extends CCComp {
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
@property(Material)
atkMaterial: Material;
@property(Node)
BoxRang:Node =null!
@@ -57,8 +59,6 @@ export class HeroViewComp extends CCComp {
power_max: number = 1200; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "base"; //技能名称
max_skill_name: string = "base"; //大技能名称
skill_uuid:number = 9001;
max_skill_uuid:number = 1001;
atk: number = 10; /**攻击力 */
@@ -89,6 +89,7 @@ export class HeroViewComp extends CCComp {
buff_atks:any = [];
dir_y:number = 0;
speek_time:number = 0;
role_heros_index:number = -1;
onLoad() {
this.as = this.getComponent(HeroSpine);
// this.BoxRang = this.node.getChildByName("range_box");
@@ -96,6 +97,7 @@ export class HeroViewComp extends CCComp {
} /** 视图层逻辑代码分离演示 */
start () {
this.as.move()
this.node.getChildByName("top").getChildByName("hp").active = false;
this.sprite = this.node.getChildByName("anm").getComponent(Sprite);
// this.node.getChildByName("top").getChildByName("shield").active = false;
// this.node.getChildByName("top").setScale(this.scale,1);
@@ -118,9 +120,9 @@ export class HeroViewComp extends CCComp {
collider.group = this.box_group;
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
@@ -146,6 +148,7 @@ export class HeroViewComp extends CCComp {
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
if(selfCollider.node.position.y < otherCollider.node.position.y){
if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
@@ -164,13 +167,15 @@ 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.check_buff_atks(dt)
this.in_shield(dt);
this.in_stop(dt);
this.in_atk(dt);
this.in_speek(dt);
this.move(dt);
this.hp_show()
// this.in_speek(dt);
// this.move(dt);
this.move_to()
// if(this.m_timer.update(dt)){
// this.move_to()
// }
@@ -186,15 +191,24 @@ export class HeroViewComp extends CCComp {
if(this.enemy){
return
}
// this.set_diry()
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y+dt*this.dir_y, this.node.position.z);
}
set_diry(){
this.dir_y=-(this.node.position.y-BoxSet.GAME_LINE)/20
hp_show(){
if(this.hp == this.hp_max){
this.node.getChildByName("top").getChildByName("hp").active = false;
} else{
this.node.getChildByName("top").getChildByName("hp").active = true;
}
}
move_to(){
// if(this.stop_cd > 0){
// return
// }
// if(this.enemy){
// return
// }
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
move.target = v3(smc.Role.RoleView.node.position.x+10,smc.Role.RoleView.node.position.y);
move.target = v3(smc.Role.RoleView.node.position.x+smc.role_heros[this.role_heros_index].x,smc.Role.RoleView.node.position.y+smc.role_heros[this.role_heros_index].y);
move.node = this.node;
move.speed = this.ospeed;
}
@@ -202,7 +216,7 @@ export class HeroViewComp extends CCComp {
this.power += power;
if(this.power >= this.power_max&&this.check_enemy_alive()){
this.as.atk()
this.to_speek(smc.skills[this.max_skill_uuid].name)
// this.to_speek(smc.skills[this.max_skill_uuid].name)
this.scheduleOnce(()=>{
this.handle_skill(this.max_skill_uuid);
},0.5)
@@ -237,10 +251,10 @@ export class HeroViewComp extends CCComp {
}
return {pos,t_pos}
}
shoot(skill_uuid:number,y:number=0,x:number=0){
// console.log("mon shoot");
shoot_enemy(skill_uuid:number,y:number=0,x:number=0){
// console.log("mon shoot_enemy");
let skill = ecs.getEntity<Skill>(Skill);
let atk = smc.skills[skill_uuid].atk+this.atk;
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk;
let {pos,t_pos}=this.get_enemy_pos()
pos.y=pos.y + y
pos.x=pos.x + x
@@ -252,21 +266,32 @@ export class HeroViewComp extends CCComp {
let atk = smc.skills[s_uuid].atk+this.atk;
let {pos,t_pos}=this.get_hero_pos(hero)
skill.load(pos,BoxSet.HERO,this.node,this.max_skill_uuid,atk,t_pos);
hero.HeroView.add_hp(smc.skills[s_uuid].atk)
if(smc.skills[s_uuid].hp > 0){ //buff加血
hero.HeroView.add_hp(smc.skills[s_uuid].hp)
}
if(smc.skills[s_uuid].atk > 0){ //buff加攻击
hero.HeroView.add_atk(smc.skills[s_uuid].atk,smc.skills[s_uuid].bsd)
}
if(smc.skills[s_uuid].shield > 0){ //buff护盾
hero.HeroView.add_shield(smc.skills[s_uuid].shield,smc.skills[s_uuid].bsd)
}
}
push_least_buff(skill:number){
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
let least_hp:number=999999
let least_hp:number=0
let t_hero:any= null
if (heros.length > 0) {
if(smc.skills[skill].type==92){ //随机添加buff
let i = RandomManager.instance.getRandomInt(0,heros.length-1,3)
this.to_add_buff(heros[i],skill)
}else{
for (let i = 0; i < heros.length; i++) {
let hero = heros[i];
if(!hero.HeroView) continue
if(smc.skills[skill].type==91){ //血量最少单体
if(hero.HeroView.hp < least_hp){
least_hp = hero.HeroView.hp
if((hero.HeroView.hp_max-hero.HeroView.hp) > least_hp){
least_hp = (hero.HeroView.hp_max-hero.HeroView.hp)
t_hero = hero
}
}else{ //群体
@@ -287,19 +312,21 @@ export class HeroViewComp extends CCComp {
handle_skill(skill:number){
switch (smc.skills[skill].tg) {
case 0: //自己
this.to_add_buff(this.ent,skill)
break;
case 1: //伙伴
this.push_least_buff(skill)
break;
case 2: //自己和伙伴
this.to_add_buff(this.ent,skill)
this.push_least_buff(skill)
break;
case 3: //敌人
this.shoot(skill)
this.shoot_enemy(skill)
break;
case 4: //敌人和自己
this.shoot(skill)
this.to_add_buff(this.ent,skill)
this.shoot_enemy(skill)
break;
}
}
@@ -346,6 +373,22 @@ export class HeroViewComp extends CCComp {
}
}
heathed(){
this.node.getChildByName("heathed").active=true
}
add_hp(hp: number=0){
this.heathed();
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;
}
hp_change(hp: number){
if(this.is_dead){
return;
@@ -364,26 +407,15 @@ export class HeroViewComp extends CCComp {
if(this.hp <= 0){
this.dead();
this.is_dead = true;
smc.role_heros[this.role_heros_index].eid == 0
setTimeout(() => {
this.ent.destroy();
}, 15);
}
}
heathed(){
this.node.getChildByName("heathed").active=true
}
add_hp(hp: number=0){
this.heathed();
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;
}
add_atk(atk: number,time:number=0){
if(time > 0){
this.buff_atk=0
let buff={atk:atk,time:time}
this.buff_atks.push(buff);
this.buff_atks.forEach((element: { atk: number; }) => {
@@ -392,15 +424,20 @@ export class HeroViewComp extends CCComp {
}else{
this.atk += atk;
}
this.sprite.setSharedMaterial(this.atkMaterial, 0);
this.scheduleOnce(() => {
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
}, 0.3);
console.log(this.buff_atks)
}
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){
this.buff_atk -= buff.atk
this.buff_atks.splice(i,1);
}else{
this.buff_atk += buff.atk
}
}
if(this.buff_atks.length <= 0){
@@ -410,9 +447,14 @@ export class HeroViewComp extends CCComp {
this.buff_icon_change("atk",true)
}
}
buff_icon_change(icon:string,value:boolean){
this.node.getChildByName("top").getChildByName("buff").getChildByName(icon).active=value
}
add_shield(shield: number,time:number=0){
this.shield =this.shield_max=shield
this.shield_time = time;
@@ -428,7 +470,15 @@ export class HeroViewComp extends CCComp {
}
}
in_shield(dt: number){
if(this.shield <= 0){
this.shield_time=0
this.node.getChildByName("shielded").active=false
}else{
this.node.getChildByName("shielded").active=true
}
if(this.shield_time <= 0){
this.shield = this.shield_max=0;
this.node.getChildByName("shielded").active=false
return
}
if(this.shield_time > 0){
@@ -441,12 +491,6 @@ export class HeroViewComp extends CCComp {
// 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,y:number=60){
// console.log("tooltip",type);