装备添加
This commit is contained in:
@@ -1,261 +1,212 @@
|
||||
import { _decorator, resources, Sprite, SpriteAtlas ,Node, 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 { GameEvent } from "../common/config/GameEvent";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { MissionEvent } from "../common/config/MissionEvent";
|
||||
|
||||
import { _decorator, Component, Node, resources, Sprite, SpriteAtlas } from 'cc';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { EquipInfo, EquipType, EquipAttr, EquipAttrTarget } from '../common/config/Equips';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('EquipsCompComp')
|
||||
@ecs.register('EquipsComp', false)
|
||||
export class EquipsCompComp extends CCComp {
|
||||
|
||||
@ccclass('EquipsComp')
|
||||
export class EquipsComp extends Component {
|
||||
weapon:any=null
|
||||
armor:any=null
|
||||
ring:any=null
|
||||
accessory:any=null
|
||||
skill1:any=null
|
||||
skill2:any=null
|
||||
skill3:any=null
|
||||
boxs:Node=null
|
||||
attrs:any={
|
||||
hero:{
|
||||
ap:0,
|
||||
hp:0,
|
||||
atk_count:0,
|
||||
atk_speed:0,
|
||||
skill_dmg:0,
|
||||
skill_cd:0,
|
||||
},
|
||||
ally:{
|
||||
ap:0,
|
||||
hp:0,
|
||||
atk_count:0,
|
||||
atk_speed:0,
|
||||
skill_dmg:0,
|
||||
skill_cd:0,
|
||||
},
|
||||
enemy:{
|
||||
ap:0,
|
||||
hp:0,
|
||||
atk_count:0,
|
||||
atk_speed:0,
|
||||
skill_dmg:0,
|
||||
skill_cd:0,
|
||||
},
|
||||
friend:{
|
||||
ap:0,
|
||||
hp:0,
|
||||
atk_count:0,
|
||||
atk_speed:0,
|
||||
skill_dmg:0,
|
||||
skill_cd:0,
|
||||
}
|
||||
}
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.on(GameEvent.UseSkillCard, this.get_skill, this);
|
||||
this.on(GameEvent.FightReady,this.fight_ready,this)
|
||||
oops.message.on(GameEvent.FightReady,this.fight_ready,this)
|
||||
oops.message.on(GameEvent.EquipAdd,this.equip_add,this)
|
||||
oops.message.on(GameEvent.EquipRemove,this.equip_remove,this)
|
||||
this.boxs=this.node.getChildByName("boxs")
|
||||
}
|
||||
start(){
|
||||
this.fight_ready()
|
||||
}
|
||||
fight_ready(){
|
||||
this.boxs.getChildByName("skill1").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("skill2").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("skill3").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("weapon").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("armor").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("ring").getChildByName("icon").active=false
|
||||
this.boxs.getChildByName("accessory").getChildByName("icon").active=false
|
||||
this.weapon={
|
||||
uuid:0,
|
||||
uuid:2001,
|
||||
name:"weapon",
|
||||
type:"weapon",
|
||||
level:0,
|
||||
quality:0,
|
||||
skill_uuid:0,
|
||||
skill_name:"skill1",
|
||||
skill_type:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
}
|
||||
this.armor={
|
||||
uuid:0,
|
||||
uuid:2002,
|
||||
name:"armor",
|
||||
type:"armor",
|
||||
level:0,
|
||||
quality:0,
|
||||
skill_uuid:0,
|
||||
skill_name:"skill1",
|
||||
skill_type:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
}
|
||||
this.ring={
|
||||
this.accessory={
|
||||
uuid:0,
|
||||
name:"ring",
|
||||
type:"ring",
|
||||
name:"accessory",
|
||||
type:"accessory",
|
||||
level:0,
|
||||
quality:0,
|
||||
skill_uuid:0,
|
||||
skill_name:"skill1",
|
||||
skill_type:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
}
|
||||
this.skill1={
|
||||
uuid:0,
|
||||
name:"skill1",
|
||||
type:0, //1 被动 0 主动
|
||||
level:0,
|
||||
quality:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
this.count_attrs()
|
||||
}
|
||||
equip_add(e:GameEvent,data:any){
|
||||
console.log("equip_add",data)
|
||||
if(data.type==EquipType.WEAPON){
|
||||
this.weapon.uuid=data.uuid
|
||||
this.weapon.name=data.name
|
||||
this.weapon.type=data.type
|
||||
this.weapon.level=data.level
|
||||
this.show_weapon(data.uuid)
|
||||
}
|
||||
this.skill2={
|
||||
uuid:0,
|
||||
name:"skill2",
|
||||
type:0,//
|
||||
level:0,
|
||||
quality:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
if(data.type==EquipType.ARMOR){
|
||||
this.armor.uuid=data.uuid
|
||||
this.armor.name=data.name
|
||||
this.armor.type=data.type
|
||||
this.armor.level=data.level
|
||||
this.show_armor(data.uuid)
|
||||
}
|
||||
this.skill3={
|
||||
uuid:0,
|
||||
name:"skill3",
|
||||
type:0,//
|
||||
level:0,
|
||||
quality:0,
|
||||
cd:0,
|
||||
cd_time:0,
|
||||
if(data.type==EquipType.ACCESSORY){
|
||||
this.accessory.uuid=data.uuid
|
||||
this.accessory.name=data.name
|
||||
this.accessory.type=data.type
|
||||
this.accessory.level=data.level
|
||||
this.show_accessory(data.uuid)
|
||||
}
|
||||
}
|
||||
show_weapon(uuid:number){
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("weapon").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/heros/equips"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(uuid.toString());
|
||||
});
|
||||
|
||||
}
|
||||
show_armor(uuid:number){
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("armor").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/heros/equips"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(uuid.toString());
|
||||
});
|
||||
}
|
||||
show_accessory(uuid:number){
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("accessory").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/heros/equips"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("icon").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(uuid.toString());
|
||||
});
|
||||
}
|
||||
count_attrs(){
|
||||
// 重置所有属性
|
||||
this.reset_attrs();
|
||||
|
||||
// 获取所有装备的属性
|
||||
let weapon_attrs = this.weapon.uuid ? EquipInfo[this.weapon.uuid]?.attributes || [] : [];
|
||||
let armor_attrs = this.armor.uuid ? EquipInfo[this.armor.uuid]?.attributes || [] : [];
|
||||
let accessory_attrs = this.accessory.uuid ? EquipInfo[this.accessory.uuid]?.attributes || [] : [];
|
||||
|
||||
// 合并所有装备属性
|
||||
const allAttrs = [...weapon_attrs, ...armor_attrs, ...accessory_attrs];
|
||||
|
||||
// 计算每个目标的属性加成
|
||||
allAttrs.forEach(attr => {
|
||||
const target = attr.target || EquipAttrTarget.ALL;
|
||||
const targetKey = this.getTargetKey(target);
|
||||
|
||||
if (targetKey) {
|
||||
switch (attr.type) {
|
||||
case EquipAttr.ATK:
|
||||
this.attrs[targetKey].ap += attr.value;
|
||||
break;
|
||||
case EquipAttr.HP:
|
||||
this.attrs[targetKey].hp += attr.value;
|
||||
break;
|
||||
case EquipAttr.ATK_COUNT:
|
||||
this.attrs[targetKey].atk_count += attr.value;
|
||||
break;
|
||||
case EquipAttr.ATK_SPEED:
|
||||
this.attrs[targetKey].atk_speed += attr.value;
|
||||
break;
|
||||
case EquipAttr.SKILL_DMG:
|
||||
this.attrs[targetKey].skill_dmg += attr.value;
|
||||
break;
|
||||
case EquipAttr.SKILL_SPEED:
|
||||
this.attrs[targetKey].skill_cd += attr.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log("count_attrs",this.attrs)
|
||||
}
|
||||
|
||||
// 重置所有属性为0
|
||||
private reset_attrs() {
|
||||
Object.keys(this.attrs).forEach(key => {
|
||||
Object.keys(this.attrs[key]).forEach(attrKey => {
|
||||
this.attrs[key][attrKey] = 0;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 根据目标类型获取对应的key
|
||||
private getTargetKey(target: EquipAttrTarget): string | null {
|
||||
switch (target) {
|
||||
case EquipAttrTarget.ALL:
|
||||
return 'hero'; // 默认作用于英雄
|
||||
case EquipAttrTarget.SELF:
|
||||
return 'hero';
|
||||
case EquipAttrTarget.FRIEND:
|
||||
return 'friend';
|
||||
case EquipAttrTarget.ENEMY:
|
||||
return 'enemy';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
equip_remove(e:GameEvent,data:any){
|
||||
console.log("equip_remove",data)
|
||||
}
|
||||
update(dt: number): void {
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
if(this.skill1.uuid!=0){
|
||||
if(this.skill1.cd_time>0){
|
||||
this.skill1.cd_time-=dt
|
||||
}else{
|
||||
this.skill1.cd_time=0
|
||||
if(this.skill1.type==1){
|
||||
this.do_skill1()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("skill1").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.skill1.cd_time/this.skill1.cd
|
||||
}
|
||||
if(this.skill2.uuid!=0){
|
||||
if(this.skill2.cd_time>0){
|
||||
this.skill2.cd_time-=dt
|
||||
}else{
|
||||
this.skill2.cd_time=0
|
||||
if(this.skill2.type==1){
|
||||
this.do_skill2()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("skill2").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.skill2.cd_time/this.skill2.cd
|
||||
}
|
||||
if(this.skill3.uuid!=0){
|
||||
if(this.skill3.cd_time>0){
|
||||
this.skill3.cd_time-=dt
|
||||
}else{
|
||||
this.skill3.cd_time=0
|
||||
if(this.skill3.type==1){
|
||||
this.do_skill3()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("skill3").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.skill3.cd_time/this.skill3.cd
|
||||
}
|
||||
if(this.weapon.skill_uuid!=0){
|
||||
if(this.weapon.cd_time>0){
|
||||
this.weapon.cd_time-=dt
|
||||
}else{
|
||||
this.weapon.cd_time=0
|
||||
if(this.weapon.skill_type==1){
|
||||
this.do_weapon()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("weapon").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.weapon.cd_time/this.weapon.cd
|
||||
}
|
||||
if(this.armor.skill_uuid!=0){
|
||||
if(this.armor.cd_time>0){
|
||||
this.armor.cd_time-=dt
|
||||
}else{
|
||||
this.armor.cd_time=0
|
||||
if(this.armor.skill_type==1){
|
||||
this.do_armor()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("armor").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.armor.cd_time/this.armor.cd
|
||||
}
|
||||
if(this.ring.skill_uuid!=0){
|
||||
if(this.ring.cd_time>0){
|
||||
this.ring.cd_time-=dt
|
||||
}else{
|
||||
this.ring.cd_time=0
|
||||
if(this.ring.skill_type==1){
|
||||
this.do_ring()
|
||||
}
|
||||
}
|
||||
this.boxs.getChildByName("ring").getChildByName("icon").getChildByName("cd").getComponent(ProgressBar).progress=this.ring.cd_time/this.ring.cd
|
||||
}
|
||||
}
|
||||
do_weapon(){
|
||||
console.log("do_weapon")
|
||||
this.weapon.cd_time=this.weapon.cd
|
||||
this.do_skill(this.weapon.skill_uuid)
|
||||
}
|
||||
do_armor(){
|
||||
console.log("do_armor")
|
||||
this.armor.cd_time=this.armor.cd
|
||||
this.do_skill(this.armor.skill_uuid)
|
||||
}
|
||||
do_ring(){
|
||||
console.log("do_ring")
|
||||
this.ring.cd_time=this.ring.cd
|
||||
this.do_skill(this.ring.skill_uuid)
|
||||
}
|
||||
do_skill1(){
|
||||
console.log("do_skill1")
|
||||
this.skill1.cd_time=this.skill1.cd
|
||||
this.do_skill(this.skill1.uuid)
|
||||
}
|
||||
do_skill2(){
|
||||
console.log("do_skill2")
|
||||
this.skill2.cd_time=this.skill2.cd
|
||||
this.do_skill(this.skill2.uuid)
|
||||
}
|
||||
do_skill3(){
|
||||
console.log("do_skill3")
|
||||
this.skill3.cd_time=this.skill3.cd
|
||||
this.do_skill(this.skill3.uuid)
|
||||
}
|
||||
do_skill(uuid:number){
|
||||
console.log("出发技能:",uuid)
|
||||
oops.message.dispatchEvent(GameEvent.CastHeroSkill,uuid)
|
||||
}
|
||||
get_skill(e:GameEvent,data:any){
|
||||
console.log("get_skill")
|
||||
if(this.skill1.uuid==0){
|
||||
this.skill1.uuid=data.uuid
|
||||
this.skill1.skill_name=SkillSet[data.uuid].name
|
||||
this.skill1.type=1
|
||||
this.skill1.cd=SkillSet[data.uuid].cd
|
||||
this.skill1.cd_time=SkillSet[data.uuid].cd
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("skill1").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/skills/skill_icon"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
||||
});
|
||||
return
|
||||
}
|
||||
if(this.skill2.uuid==0){
|
||||
this.skill2.uuid=data.uuid
|
||||
this.skill2.skill_name=SkillSet[data.uuid].name
|
||||
this.skill2.type=1
|
||||
this.skill2.cd=SkillSet[data.uuid].cd
|
||||
this.skill2.cd_time=SkillSet[data.uuid].cd
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("skill2").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/skills/skill_icon"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
||||
});
|
||||
return
|
||||
}
|
||||
if(this.skill3.uuid==0){
|
||||
this.skill3.uuid=data.uuid
|
||||
this.skill3.skill_name=SkillSet[data.uuid].name
|
||||
this.skill3.type=1
|
||||
this.skill3.cd=SkillSet[data.uuid].cd
|
||||
this.skill3.cd_time=SkillSet[data.uuid].cd
|
||||
let icon = this.node.getChildByName("boxs").getChildByName("skill3").getChildByName("icon")
|
||||
icon.active=true
|
||||
var icon_path = "game/skills/skill_icon"
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = icon.getChildByName("skill").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[data.uuid].path);
|
||||
});
|
||||
return
|
||||
}
|
||||
console.log("技能栏满了")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user