物品图标

This commit is contained in:
2024-08-29 23:59:27 +08:00
parent 01fa44c19d
commit 6b4789d07c
22 changed files with 1089 additions and 903 deletions

View File

@@ -0,0 +1,138 @@
import { _decorator,Sprite ,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 { RoleViewComp } from "./RoleViewComp";
import { RoleSpine } from "./RoleSpine";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('RoleBuffComp')
@ecs.register('RoleBuff', false)
export class RoleBuffComp extends CCComp {
as: RoleSpine = null!;
mv!: RoleViewComp
timer:Timer = new Timer(0.1);
buffs:any=[];
group:number=0;
/**
skill_uuid:number=0;
atk:number=0;
hp:number=0;
shield:number=0;
time:number=0;
**/
onLoad() {
this.as = this.node.getComponent(RoleSpine);
this.mv= this.getComponent(RoleViewComp);
} /** 视图层逻辑代码分离演示 */
start () {
}
add_buff(uuid:number=0,args:any[]){
// console.log("add_buff",smc.skills[uuid]);
let new_buff={
skill_uuid:uuid,
skill_name:smc.skills[uuid].name,
atk:smc.skills[uuid].atk,
hp:smc.skills[uuid].hp,
shield:smc.skills[uuid].shield,
time:smc.skills[uuid].bsd,
bcd:smc.skills[uuid].bcd,
sk_uuid:smc.skills[uuid].uuid,
args:args
}
this.buff_add(new_buff);
}
update(dt: number){
if (this.timer.update(dt)) {
this.buff_update()
}
}
reset() {
this.node.destroy();
}
buff_add(buff:any){
if(!this.node.isValid){ return }
let i = 0
if(this.buffs.length >=0){
this.buffs.forEach((b:any,index:number)=>{
if(b.skill_uuid==buff.skill_uuid){
b.time=buff.time;
if(buff.atk>0){
this.node.getChildByName("avatar").setScale(1.2,1.2)
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
this.mv.atk+=(buff.atk+buff.args.atk-b.atk);
}
if(buff.hp>0){
this.mv.hp+=(buff.hp+buff.args.hp);
this.mv.add_hp(buff.hp+buff.args.hp);
// this.mv.hp_max+=(buff.hp-b.hp);
}
if(buff.shield>0){
this.mv.shield=(buff.shield+buff.args.shield);
// this.mv.shield_max=(buff.shield+buff.args.shield);
}
i=index
}
})
}
if (i==0||this.buffs.length==0) {
this.buffs.push(buff);
if(buff.atk>0){
this.mv.atk+=(buff.atk+buff.args.atk);
this.node.getChildByName("avatar").setScale(1.2,1.2)
// this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
}
if(buff.hp>0){
this.mv.hp+=(buff.hp+buff.args.hp);
this.mv.add_hp(buff.hp+buff.args.hp);
// this.mv.hp_max+=buff.hp;
}
if(buff.shield>0){
this.mv.shield=(buff.shield+buff.args.shield);
// this.mv.shield_max=(buff.shield+buff.args.shield);
}
}
console.log("buff add:",this.mv);
}
buff_remove(index:number){
if(this.buffs[index].atk>0){
this.mv.atk-=(this.buffs[index].atk+this.buffs[index].args.atk);
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#FFFFFF");
this.node.getChildByName("avatar").setScale(1,1)
}
if(this.buffs[index].shield>0){
this.mv.shield=0
// this.mv.shield_max-=(this.buffs[index].shield+this.buffs[index].args.shield);
}
// if(this.buffs[index].hp>0){
// this.mv.hp_max-=this.buffs[index].hp;
// }
console.log("buff remove:",this.mv,this.buffs[index]);
}
buff_update(){
this.buffs.forEach((buff:any,index:number)=>{
buff.time -= 0.1;
if(buff.time <= 0){
this.buff_remove(index);
}
})
this.buffs = this.buffs.filter((buff:any) => buff.time > 0);
// console.log(this.buffs,this.buffs);
}
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "93179a96-4683-4d2d-853c-a0f721f19f02",
"uuid": "e5f012c8-982e-4eef-8f95-edc5d4bcef52",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -38,6 +38,8 @@ export class RoleViewComp extends CCComp {
atk:number = 10;
skill_uuid:number = 9003;
max_skill_uuid:number = 1001;
shield:number = 0;
shield_max:number = 200;
skin="Character01";
private atk_time:Timer = new Timer(1);
@@ -79,6 +81,9 @@ export class RoleViewComp extends CCComp {
}
}
add_hp(hp:number){
console.log("role add hp",hp);
}
setSkin(){
this.as.setSkin(this.skin);

View File

@@ -1,9 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "826ec938-411f-429e-9693-747a063877b4",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,74 +0,0 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:26
*/
import { Color, Component, EventTouch, sp, Vec3, _decorator ,Node} from "cc";
import { LayerUtil } from "../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../common/SingletonModuleComp";
import Role2SpineAnimator from "./Role2SpineAnimator";
const { ccclass, property } = _decorator;
/**
* SPINE角色模型
*/
@ccclass('Role2Spine')
export class Role2Spine extends Component {
@property({ type: Role2SpineAnimator, tooltip: '动画控制器' })
animator: Role2SpineAnimator = null!;
private spine!: sp.Skeleton;
onLoad() {
// 角色控制组件
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
}
atk() {
this.spine.setAnimation(1, "atk", false);
}
magic() {
this.spine.setAnimation(1, "magic", false);
}
/** 初始化动画 */
protected initAnimator() {
this.spine = this.animator.getComponent(sp.Skeleton)!;
}
setSkin(value: string): void {
console.log("RoleSpine setSkin", value);
this.spine.setSkin(value);
}
play(animName: string, loop: boolean): void {
this.spine.setAnimation(1, animName, loop);
}
setAlpha(value: number): void {
var color: Color = this.spine.color;
color.a = 255 * (value / 1);
this.spine.color = color;
}
setPos(value: Vec3): void {
this.node.position = value;
}
checkTouch(event: EventTouch): boolean {
return false;
}
onDestroy() {
this.node.destroy();
}
walk() {
}
idle() {
}
}

View File

@@ -1 +0,0 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"a12321b5-d9b0-4eb8-aa4c-9db175d0f9a8","files":[],"subMetas":{},"userData":{}}

View File

@@ -1,71 +0,0 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:38
*/
import { sp, _decorator ,Component} from "cc";
const { ccclass, property, requireComponent } = _decorator;
/**
* Spine状态机组件主状态机trackIndex为0
*/
@ccclass
@requireComponent(sp.Skeleton)
export default class Role2SpineAnimator extends Component {
private animName: string = "Idle";
private loop: boolean = true;
private spine!: sp.Skeleton;
start() {
this.spine = this.getComponent(sp.Skeleton)!;
// console.log("MonsterSpineAnimator start");
this.playAnimation(this.animName, this.loop);
}
mixTime:number= 0.2;
protected onLoad(): void {
this.spine = this.getComponent(sp.Skeleton)!;
// this.spine?.setMix('atk', 'Idle', this.mixTime);
// this.spine?.setMix('Idle','atk', this.mixTime);
this.spine.setEndListener(trackEntry => {
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
// console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
if (animationName == "atk"||animationName == "magic") {
this.spine.setAnimation(1, "Idle", true);
}
});
}
lateUpdate(dt: number) {
//
}
play(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(1 ,this.animName, this.loop);
}
else {
}
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
// console.log("MonsterSpineAnimator playAnimation");
if (animName) {
// console.log("MonsterSpineAnimator playAnimation animName", animName);
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(1, this.animName, this.loop);
}
else {
}
}
}

View File

@@ -1,126 +0,0 @@
/*
* @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");
}
}
}

View File

@@ -1 +0,0 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"4810c3ad-8287-4fcd-bdb3-dd44247d61ed","files":[],"subMetas":{},"userData":{}}