Files
heros/assets/script/game/hero/Hero.ts

171 lines
6.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas} from "cc";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { smc } from "../common/SingletonModuleComp";
import { HeroModelComp } from "./HeroModelComp";
import { HeroViewComp } from "./HeroViewComp";
import { BoxSet, FacSet } from "../common/config/BoxSet";
import { HeroInfo, HeroPos, HType } from "../common/config/heroSet";
import { BattleMoveComp } from "../common/ecs/position/BattleMoveComp";
import { FriendModelComp } from "./FriendModel";
import { MasterModelComp } from "./MasterModel";
import { GameEvent } from "../common/config/GameEvent";
import { BuffAttr, SkillSet } from "../common/config/SkillSet";
import { FightSet } from "../common/config/Mission";
import { Skill } from "../skills/Skill";
/** 角色实体 */
@ecs.register(`Hero`)
export class Hero extends ecs.Entity {
HeroModel!: HeroModelComp;
HeroView!: HeroViewComp;
BattleMove!: BattleMoveComp;
vmHero:any={}
protected init() {
this.addComponents<ecs.Comp>(
BattleMoveComp,
HeroModelComp,
);
}
destroy(): void {
this.remove(HeroViewComp);
this.remove(HeroModelComp);
if(this.get(FriendModelComp)){
this.remove(FriendModelComp);
}
if(this.get(MasterModelComp)){
this.remove(MasterModelComp);
}
super.destroy();
}
/**
* 获取所有英雄槽位
* @returns 英雄槽位数组
*/
private getHeroSlots(): any[] {
return [smc.vmdata.hero1, smc.vmdata.hero2, smc.vmdata.hero3]
}
/**
* 查找可用的英雄槽位
* @returns 可用的英雄槽位对象如果没有可用槽位则返回null
*/
private findAvailableHeroSlot(): any {
return this.getHeroSlots().find(slot => slot.uuid === 0) || null
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,info:any={ap:0,hp:0,lv:1,crit:0,crit_d:0,dod:0,dod_no:false,crit_no:false},fight_pos:number=1) {
// console.log("英雄加载:",uuid,pos,scale,info)
scale = 1
// 查找空闲英雄槽位
this.vmHero = this.findAvailableHeroSlot()
if (!this.vmHero) {
console.log("[Hero] 英雄已满")
return
}
this.vmHero.uuid=uuid
this.vmHero.count=1
var path = "game/heros/"+HeroInfo[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!
node.setPosition(pos)
// console.log("hero load",pos)
var hv = this.hero_init(uuid,node,info)
this.add(hv);
this.addComponents<ecs.Comp>(MasterModelComp)
oops.message.dispatchEvent(GameEvent.MasterCalled,{uuid:uuid})
const move = this.get(BattleMoveComp);
move.direction = 1; // 向右移动
move.targetX = 0; // 右边界'
if(HeroInfo[uuid].type==HType.remote){
move.targetX = -100; // 右边界'
}
if(HeroInfo[uuid].type==HType.mage){
move.targetX = -200; // 右边界'
}
}
hero_init(uuid:number=1001,node:Node,info:any={ap:0,hp:0,lv:1,crit:0,crit_d:0,dod:0,dod_no:false,crit_no:false}) {
var hv = node.getComponent(HeroViewComp)!;
let hero= HeroInfo[uuid] // 共用英雄数据
hv.vmHero=this.vmHero
this.vmHero.name=hero.name
hv.scale = 1;
hv.is_master=true;
hv.lv=1
hv.lv=info.lv
hv.fac = FacSet.HERO;
hv.type = hero.type;
hv.box_group = BoxSet.HERO;
hv.hero_uuid= uuid;
hv.hero_name= hero.name;
hv.speed =hv.ospeed = hero.speed;
hv.dis = hero.dis;
hv.cd = hv.cd_base = hero.cd
this.vmHero.hp=this.vmHero.hp_max= hv.hp = hv.hp_max = hv.hp_base=hero.hp+info.hp
hv.ap = hv.ap_base=hero.ap+info.ap;
hero.buff.forEach((buff:any)=>{
switch(buff.buff_type){
case BuffAttr.CRITICAL:
hv.crit=buff.value
break
case BuffAttr.CRITICAL_DMG:
hv.crit_d=buff.value
break
case BuffAttr.DODGE:
hv.dod=buff.value
break
case BuffAttr.DODGE_NO:
hv.dod_no=buff.value
break
case BuffAttr.CRITICAL_NO:
hv.crit_no=buff.value
break
case BuffAttr.PUNCTURE:
hv.puncture=buff.value
break
case BuffAttr.PUNCTURE_DMG:
hv.puncture_damage=buff.value
break
case BuffAttr.WFUNY:
hv.wfuny=buff.value
break
case BuffAttr.ATK_CD:
hv.cd=hv.cd*(100-buff.value)/100
break
case BuffAttr.HP:
hv.hp_max=hv.hp_max*(100+buff.value)/100
break
case BuffAttr.DEF:
hv.def=buff.value
break
case BuffAttr.ATK:
hv.ap=hv.ap*(100+buff.value)/100
break
case BuffAttr.STUN_RATTO:
hv.stun_ratto=buff.value
break
case BuffAttr.FROST_RATIO:
hv.frost_ratto=buff.value
break
case BuffAttr.KNOCKBACK:
hv.knockback=buff.value
break
case BuffAttr.POWER_UP:
smc.vmdata.hero.POWER_UP+=buff.value
break
}
})
hv.atk_skill=hero.skills[0]
hv.skills=hero.skills
this.vmHero.cd_max=SkillSet[hv.skills[1]].cd
return hv
}
}