奖励已经双倍奖励
This commit is contained in:
222
assets/script/game/map/ItemComp.ts
Normal file
222
assets/script/game/map/ItemComp.ts
Normal file
@@ -0,0 +1,222 @@
|
||||
import { _decorator, Component, Node, Label, Sprite, resources, SpriteFrame } from 'cc';
|
||||
import { Items } from '../common/config/Items';
|
||||
import { QualitySet } from '../common/config/BoxSet';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { UIID } from '../common/config/GameUIConfig';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ItemComp')
|
||||
export class ItemComp extends Component {
|
||||
item_uuid: number = 0;
|
||||
item_count: number = 1;
|
||||
type: number = 0;
|
||||
slot: number = 0;
|
||||
no_show:boolean=false
|
||||
|
||||
|
||||
|
||||
start() {
|
||||
console.log("[ItemComp]:start");
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物品数据
|
||||
* @param hero_uuid 物品ID
|
||||
* @param count 物品数量
|
||||
* @param args 额外参数
|
||||
*/
|
||||
update_data(hero_uuid: number, count: number = 1, args: any = {}) {
|
||||
this.item_uuid = hero_uuid;
|
||||
this.item_count = count;
|
||||
this.type = args.type || 0;
|
||||
this.slot = args.slot || 0;
|
||||
this.no_show = args.no_show || false;
|
||||
console.log("[ItemComp]:update_data", hero_uuid, count, this.type, this.slot, args);
|
||||
|
||||
// 获取物品配置
|
||||
const itemData = Items[hero_uuid];
|
||||
if (!itemData) {
|
||||
console.error("[ItemComp]: Item not found", hero_uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置物品图标
|
||||
this.setItemIcon(itemData.path);
|
||||
|
||||
// 设置品质边框
|
||||
this.setQualityFrame(itemData.quality);
|
||||
|
||||
// 设置数量显示
|
||||
this.setItemCount(count);
|
||||
|
||||
// 设置选中状态
|
||||
if (args.selected) {
|
||||
this.setSelected(true);
|
||||
} else {
|
||||
this.setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品图标
|
||||
* @param iconPath 图标路径
|
||||
*/
|
||||
private setItemIcon(iconPath: string) {
|
||||
let path=`gui/items/${iconPath}`
|
||||
console.log("[ItemComp]: setItemIcon", path);
|
||||
resources.load(path, SpriteFrame, (err, spriteFrame) => {
|
||||
if (err) {
|
||||
console.error("[ItemComp]: Failed to load item icon", iconPath, err);
|
||||
return;
|
||||
}
|
||||
console.log("[ItemComp]: setItemIcon", iconPath, spriteFrame);
|
||||
this.node.getChildByName("icon").getComponent(Sprite)!.spriteFrame = spriteFrame;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置品质边框
|
||||
* @param quality 品质类型
|
||||
*/
|
||||
private setQualityFrame(quality: QualitySet) {
|
||||
// 隐藏所有品质边框
|
||||
this.hideAllQualityFrames();
|
||||
|
||||
// 根据品质显示对应边框
|
||||
switch (quality) {
|
||||
case QualitySet.GREEN:
|
||||
this.node.getChildByName("q1").active = true;
|
||||
break;
|
||||
case QualitySet.BLUE:
|
||||
this.node.getChildByName("q2").active = true;
|
||||
break;
|
||||
case QualitySet.PURPLE:
|
||||
this.node.getChildByName("q3").active = true;
|
||||
break;
|
||||
case QualitySet.ORANGE:
|
||||
this.node.getChildByName("q4").active = true;
|
||||
break;
|
||||
default:
|
||||
// 默认使用绿色边框
|
||||
this.node.getChildByName("q").active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏所有品质边框
|
||||
*/
|
||||
private hideAllQualityFrames() {
|
||||
this.node.getChildByName("q").active = false;
|
||||
this.node.getChildByName("q1").active = false;
|
||||
this.node.getChildByName("q2").active = false;
|
||||
this.node.getChildByName("q3").active = false;
|
||||
this.node.getChildByName("q4").active = false;
|
||||
this.node.getChildByName("focus").active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品数量
|
||||
* @param count 数量
|
||||
*/
|
||||
private setItemCount(count: number) {
|
||||
this.node.getChildByName("num").getComponent(Label)!.string = count.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置选中状态
|
||||
* @param selected 是否选中
|
||||
*/
|
||||
private setSelected(selected: boolean) {
|
||||
this.node.getChildByName("focus").active = selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* 物品点击事件
|
||||
*/
|
||||
do_click() {
|
||||
console.log("[ItemComp]: Item clicked", this.item_uuid, this.item_count);
|
||||
|
||||
// 根据类型处理不同逻辑
|
||||
switch (this.type) {
|
||||
case 1: // 普通点击
|
||||
this.onItemClick();
|
||||
break;
|
||||
case 2: // 选择物品
|
||||
this.onItemSelect();
|
||||
break;
|
||||
case 3: // 使用物品
|
||||
this.onItemUse();
|
||||
break;
|
||||
default:
|
||||
this.onItemClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通物品点击
|
||||
*/
|
||||
private onItemClick() {
|
||||
// 显示物品信息或执行其他逻辑
|
||||
console.log("[ItemComp]: Show item info", this.item_uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择物品
|
||||
*/
|
||||
private onItemSelect() {
|
||||
// 处理物品选择逻辑
|
||||
console.log("[ItemComp]: Item selected", this.item_uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用物品
|
||||
*/
|
||||
private onItemUse() {
|
||||
// 处理物品使用逻辑
|
||||
console.log("[ItemComp]: Use item", this.item_uuid);
|
||||
}
|
||||
show_item_info(){
|
||||
if(this.no_show){
|
||||
return
|
||||
}
|
||||
oops.gui.open(UIID.ItemInfo, { item_uuid: this.item_uuid ,count:this.item_count});
|
||||
}
|
||||
/**
|
||||
* 获取物品UUID
|
||||
*/
|
||||
getItemUUID(): number {
|
||||
return this.item_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品数量
|
||||
*/
|
||||
getItemCount(): number {
|
||||
return this.item_count;
|
||||
}
|
||||
addItemCount(count:number){
|
||||
this.item_count+=count
|
||||
this.setItemCount(this.item_count)
|
||||
}
|
||||
/**
|
||||
* 设置物品类型
|
||||
*/
|
||||
setItemType(type: number) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品槽位
|
||||
*/
|
||||
setItemSlot(slot: number) {
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/map/ItemComp.ts.meta
Normal file
9
assets/script/game/map/ItemComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "691f8376-3937-42db-ae4b-771d4cc67b25",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
295
assets/script/game/map/ItemInfoComp.ts
Normal file
295
assets/script/game/map/ItemInfoComp.ts
Normal file
@@ -0,0 +1,295 @@
|
||||
import { _decorator, Component, Node, Label, Sprite, resources, SpriteFrame, input, Input, EventTouch, EventMouse, Vec3, Vec2, UITransform, Color } from 'cc';
|
||||
import { Items } from '../common/config/Items';
|
||||
import { QualitySet } from '../common/config/BoxSet';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ItemInfoComp')
|
||||
export class ItemInfoComp extends Component {
|
||||
item_uuid: number = 0;
|
||||
item_count: number = 1;
|
||||
|
||||
// 触摸监听相关
|
||||
private touchListener: any = null;
|
||||
private isListening: boolean = false;
|
||||
|
||||
start() {
|
||||
console.log("[ItemInfoComp]:start");
|
||||
}
|
||||
|
||||
onAdded(args: any) {
|
||||
console.log("[ItemInfoComp]:onAdded", args);
|
||||
this.setupTouchListener();
|
||||
this.update_data(args);
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
this.removeTouchListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置触摸监听
|
||||
*/
|
||||
private setupTouchListener() {
|
||||
if (this.isListening) return;
|
||||
// 监听触摸开始事件
|
||||
this.touchListener = input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
||||
this.isListening = true;
|
||||
|
||||
console.log("[ItemInfoComp]: Touch listener setup");
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除触摸监听
|
||||
*/
|
||||
private removeTouchListener() {
|
||||
if (this.touchListener && this.isListening) {
|
||||
input.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
|
||||
this.isListening = false;
|
||||
this.touchListener = null;
|
||||
|
||||
console.log("[ItemInfoComp]: Touch listener removed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触摸开始事件处理
|
||||
* @param event 触摸事件
|
||||
*/
|
||||
private onTouchStart(event: EventTouch) {
|
||||
const touchPos = event.getLocation();
|
||||
const nodePos = this.node.getWorldPosition();
|
||||
|
||||
// 检查触摸点是否在弹窗范围内
|
||||
if (!this.isTouchInNodeBounds(touchPos, nodePos)) {
|
||||
console.log("[ItemInfoComp]: Touch outside bounds, closing popup");
|
||||
this.closeItemInfo();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查触摸点是否在节点范围内
|
||||
* @param touchPos 触摸点世界坐标
|
||||
* @param nodePos 节点世界坐标
|
||||
* @returns 是否在范围内
|
||||
*/
|
||||
private isTouchInNodeBounds(touchPos: Vec2, nodePos: Vec3): boolean {
|
||||
const nodeSize = this.node.getComponent(UITransform)?.contentSize;
|
||||
if (!nodeSize) return false;
|
||||
|
||||
// 计算节点的边界
|
||||
const halfWidth = nodeSize.width * 0.5;
|
||||
const halfHeight = nodeSize.height * 0.5;
|
||||
|
||||
// 检查触摸点是否在节点范围内
|
||||
const inX = Math.abs(touchPos.x - nodePos.x) <= halfWidth;
|
||||
const inY = Math.abs(touchPos.y - nodePos.y) <= halfHeight;
|
||||
|
||||
return inX && inY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物品数据
|
||||
* @param args 物品参数 {item_uuid: number, count?: number}
|
||||
*/
|
||||
update_data(args: any) {
|
||||
console.log("[ItemInfoComp]:update_data", args);
|
||||
|
||||
if (!args || !args.item_uuid) {
|
||||
console.error("[ItemInfoComp]: Invalid args", args);
|
||||
return;
|
||||
}
|
||||
|
||||
this.item_uuid = args.item_uuid;
|
||||
this.item_count = args.count || 1;
|
||||
|
||||
// 获取物品配置
|
||||
const itemData = Items[this.item_uuid];
|
||||
if (!itemData) {
|
||||
console.error("[ItemInfoComp]: Item not found", this.item_uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置物品图标
|
||||
this.setItemIcon(itemData.path);
|
||||
|
||||
// 设置品质边框
|
||||
this.setQualityFrame(itemData.quality);
|
||||
|
||||
// 设置品质文字描述
|
||||
this.setQualityText(itemData.quality);
|
||||
|
||||
// 设置数量显示
|
||||
this.setItemCount(this.item_count);
|
||||
|
||||
// 设置物品名称
|
||||
this.setItemName(itemData.name);
|
||||
|
||||
// 设置物品描述
|
||||
this.setItemInfo(itemData.info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品图标
|
||||
* @param iconPath 图标路径
|
||||
*/
|
||||
private setItemIcon(iconPath: string) {
|
||||
let path=`gui/items/${iconPath}`
|
||||
console.log("[ItemComp]: setItemIcon", path);
|
||||
resources.load(path, SpriteFrame, (err, spriteFrame) => {
|
||||
if (err) {
|
||||
console.error("[ItemComp]: Failed to load item icon", iconPath, err);
|
||||
return;
|
||||
}
|
||||
console.log("[ItemComp]: setItemIcon", iconPath, spriteFrame);
|
||||
this.node.getChildByName("item").getChildByName("icon").getComponent(Sprite)!.spriteFrame = spriteFrame;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置品质边框
|
||||
* @param quality 品质类型
|
||||
*/
|
||||
private setQualityFrame(quality: QualitySet) {
|
||||
// 隐藏所有品质边框
|
||||
this.hideAllQualityFrames();
|
||||
|
||||
// 根据品质显示对应边框
|
||||
switch (quality) {
|
||||
case QualitySet.GREEN:
|
||||
this.node.getChildByName("item").getChildByName("q1").active = true;
|
||||
break;
|
||||
case QualitySet.BLUE:
|
||||
this.node.getChildByName("item").getChildByName("q2").active = true;
|
||||
break;
|
||||
case QualitySet.PURPLE:
|
||||
this.node.getChildByName("item").getChildByName("q3").active = true;
|
||||
break;
|
||||
case QualitySet.ORANGE:
|
||||
this.node.getChildByName("item").getChildByName("q4").active = true;
|
||||
break;
|
||||
default:
|
||||
// 默认使用绿色边框
|
||||
this.node.getChildByName("item").getChildByName("q").active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏所有品质边框
|
||||
*/
|
||||
private hideAllQualityFrames() {
|
||||
this.node.getChildByName("item").getChildByName("q").active = false;
|
||||
this.node.getChildByName("item").getChildByName("q1").active = false;
|
||||
this.node.getChildByName("item").getChildByName("q2").active = false;
|
||||
this.node.getChildByName("item").getChildByName("q3").active = false;
|
||||
this.node.getChildByName("item").getChildByName("q4").active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品数量
|
||||
* @param count 数量
|
||||
*/
|
||||
private setItemCount(count: number) {
|
||||
if (count > 1) {
|
||||
this.node.getChildByName("item").getChildByName("num").getComponent(Label)!.string = count.toString();
|
||||
this.node.getChildByName("item").getChildByName("num").active = true;
|
||||
} else {
|
||||
this.node.getChildByName("item").getChildByName("num").active = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品名称
|
||||
* @param name 物品名称
|
||||
*/
|
||||
private setItemName(name: string) {
|
||||
this.node.getChildByName("name").getComponent(Label)!.string = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置物品描述
|
||||
* @param info 物品描述
|
||||
*/
|
||||
private setItemInfo(info: string) {
|
||||
this.node.getChildByName("info").getComponent(Label)!.string = info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置品质文字描述
|
||||
* @param quality 品质类型
|
||||
*/
|
||||
private setQualityText(quality: QualitySet) {
|
||||
|
||||
switch (quality) {
|
||||
case QualitySet.GREEN:
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.string = "优秀";
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.color = new Color(76, 175, 80, 255); // 现代绿色
|
||||
break;
|
||||
case QualitySet.BLUE:
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.string = "精良";
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.color = new Color(33, 150, 243, 255); // 现代蓝色
|
||||
break;
|
||||
case QualitySet.PURPLE:
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.string = "史诗";
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.color = new Color(156, 39, 176, 255); // 现代紫色
|
||||
break;
|
||||
case QualitySet.ORANGE:
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.string = "传说";
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.color = new Color(255, 87, 34, 255); // 现代橙色
|
||||
break;
|
||||
default:
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.string = "普通";
|
||||
this.node.getChildByName("quality").getChildByName("Label").getComponent(Label)!.color = new Color(158, 158, 158, 255); // 现代灰色
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品UUID
|
||||
*/
|
||||
getItemUUID(): number {
|
||||
return this.item_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品数量
|
||||
*/
|
||||
getItemCount(): number {
|
||||
return this.item_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭物品信息弹窗
|
||||
*/
|
||||
closeItemInfo() {
|
||||
console.log("[ItemInfoComp]: Close item info");
|
||||
this.removeTouchListener();
|
||||
oops.gui.removeByNode(this.node)
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用物品
|
||||
*/
|
||||
useItem() {
|
||||
console.log("[ItemInfoComp]: Use item", this.item_uuid);
|
||||
// 这里可以添加使用物品的逻辑
|
||||
// 比如消耗物品、触发效果等
|
||||
}
|
||||
|
||||
/**
|
||||
* 丢弃物品
|
||||
*/
|
||||
dropItem() {
|
||||
console.log("[ItemInfoComp]: Drop item", this.item_uuid);
|
||||
// 这里可以添加丢弃物品的逻辑
|
||||
// 比如从背包中移除、显示确认对话框等
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/map/ItemInfoComp.ts.meta
Normal file
9
assets/script/game/map/ItemInfoComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "627ed4fe-6a6c-4591-96fb-df08a6ebed95",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { _decorator,Button,EventHandler,EventTouch,Label,NodeEventType,resources,Sprite,SpriteAtlas,tween,UITransform,v3, Vec3,Animation, UI, instantiate, Prefab, screen } from "cc";
|
||||
import { _decorator, Vec3,Animation, instantiate, Prefab, Node } 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";
|
||||
@@ -10,6 +10,7 @@ import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
import { MonModelComp } from "../hero/MonModelComp";
|
||||
import { SkillCom } from "../skills/SkillCom";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { ItemComp } from "./ItemComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
@@ -22,7 +23,7 @@ export class MissionComp extends CCComp {
|
||||
// VictoryComp:any = null;
|
||||
// reward:number = 0;
|
||||
// reward_num:number = 0;
|
||||
|
||||
rewards:any[]=[]
|
||||
|
||||
onLoad(){
|
||||
this.on(GameEvent.MissionStart,this.mission_start,this)
|
||||
@@ -45,10 +46,61 @@ export class MissionComp extends CCComp {
|
||||
do_reward(){
|
||||
// 奖励发放
|
||||
}
|
||||
|
||||
do_mon_dead(){
|
||||
do_drop(drop_item:any[]){
|
||||
console.log("[MissionComp] do_drop",drop_item)
|
||||
let parent=this.node.getChildByName("reward").getChildByName("items")
|
||||
let items=parent.children
|
||||
if(drop_item.length>0){
|
||||
for(let i=0;i<drop_item.length;i++){
|
||||
let d_item=drop_item[i]
|
||||
// 查找是否已存在该物品
|
||||
const existingItem = this.rewards.find(item => item.item_uuid === d_item.item_uuid);
|
||||
if(existingItem){
|
||||
// 如果已存在该物品,累加数量
|
||||
existingItem.count += d_item.count;
|
||||
}else{
|
||||
// 如果不存在该物品,添加新物品
|
||||
this.rewards.push({item_uuid: d_item.item_uuid, count: d_item.count});
|
||||
}
|
||||
}
|
||||
}
|
||||
for(let i=0;i<items.length;i++){
|
||||
let hitem=items[i].getComponent(ItemComp)
|
||||
for(let j=0;j<drop_item.length;j++){
|
||||
let d_item=drop_item[j]
|
||||
if(d_item.item_uuid==hitem.item_uuid){
|
||||
hitem.addItemCount(d_item.count)
|
||||
drop_item.splice(j,1)
|
||||
smc.addItem(d_item.item_uuid,d_item.count)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if(drop_item.length>0){
|
||||
console.log("[MissionComp] do_drop 剩余物品",drop_item)
|
||||
for(let i=0;i<drop_item.length;i++){
|
||||
let d_item=drop_item[i]
|
||||
let path="game/gui/item"
|
||||
const prefab = oops.res.get(path, Prefab);
|
||||
if (!prefab) {
|
||||
console.error("[MissionComp=>do_drop] 预制体加载失败:", path);
|
||||
return;
|
||||
}
|
||||
const node = instantiate(prefab) as unknown as Node;
|
||||
node.parent=parent
|
||||
node.getComponent(ItemComp)!.update_data(d_item.item_uuid,d_item.count)
|
||||
smc.addItem(d_item.item_uuid,d_item.count)
|
||||
}
|
||||
}
|
||||
}
|
||||
do_mon_dead(event:any,data:any){
|
||||
console.log("[MissionComp] do_mon_dead",event,data)
|
||||
smc.vmdata.mission_data.mon_num--
|
||||
console.log("[MissionComp] do_mon_dead",smc.vmdata.mission_data.mon_num)
|
||||
if(data.drops){
|
||||
if(data.drops.length>0){
|
||||
this.do_drop(data.drops)
|
||||
}
|
||||
}
|
||||
if(smc.vmdata.mission_data.mon_num<=0) {
|
||||
smc.vmdata.mission_data.level++
|
||||
if(smc.vmdata.mission_data.level < smc.vmdata.mission_data.max_mission){
|
||||
@@ -57,15 +109,16 @@ export class MissionComp extends CCComp {
|
||||
}
|
||||
smc.addGameProperty("mission",1)
|
||||
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:true})
|
||||
oops.gui.open(UIID.Victory,{victory:true})
|
||||
oops.gui.open(UIID.Victory,{victory:true,rewards:this.rewards})
|
||||
}
|
||||
}
|
||||
do_hero_dead(){
|
||||
|
||||
do_hero_dead(event:any,data:any){
|
||||
console.log("[MissionComp] do_hero_dead",event,data)
|
||||
smc.vmdata.mission_data.hero_num--
|
||||
console.log("[MissionComp] do_hero_dead",smc.vmdata.mission_data.hero_num)
|
||||
if(smc.vmdata.mission_data.hero_num<=0) {
|
||||
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false})
|
||||
oops.gui.open(UIID.Victory,{victory:false})
|
||||
oops.gui.open(UIID.Victory,{victory:false,rewards:this.rewards})
|
||||
}
|
||||
}
|
||||
do_ad(){
|
||||
@@ -109,7 +162,7 @@ export class MissionComp extends CCComp {
|
||||
|
||||
to_end_fight(){
|
||||
oops.message.dispatchEvent(GameEvent.FightEnd,{victory:false})
|
||||
oops.gui.open(UIID.Victory,{victory:false})
|
||||
oops.gui.open(UIID.Victory,{victory:false,rewards:this.rewards})
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +188,8 @@ export class MissionComp extends CCComp {
|
||||
smc.vmdata.mission_data.in_fight=false
|
||||
smc.vmdata.mission_data.fight_time=0
|
||||
smc.vmdata.mission_data.level=0
|
||||
this.rewards=[] // 改为数组,用于存储掉落物品列表
|
||||
this.node.getChildByName("reward").getChildByName("items").removeAllChildren()
|
||||
console.log("[MissionComp]局内数据初始化",smc.vmdata.mission_data)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,13 @@ export class MissionHomeComp extends CCComp {
|
||||
uodate_data(){
|
||||
smc.syncData()
|
||||
}
|
||||
isWxClient(){
|
||||
return typeof wx !== 'undefined' && typeof (wx as any).getSystemInfoSync === 'function';
|
||||
}
|
||||
btn_func(e:string,data:any){
|
||||
smc.syncDataFromLocal() //调试用,正式环境去掉
|
||||
if(!this.isWxClient()){
|
||||
smc.syncDataFromLocal() //调试用,正式环境去掉
|
||||
}
|
||||
// console.log("[MissionHomeComp]:btn_func",e,data)
|
||||
let page_heros=this.node.getChildByName("heros_page")
|
||||
let page_shop=this.node.getChildByName("shop_page")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { _decorator, instantiate, Label ,Prefab,resources,Sprite,SpriteAtlas,v3} from "cc";
|
||||
import { _decorator, instantiate, Label ,Prefab,Node} 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { GameEvent } from "../common/config/GameEvent";
|
||||
import { ItemComp } from "./ItemComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -14,13 +15,18 @@ export class VictoryComp extends CCComp {
|
||||
|
||||
reward_lv:number=1
|
||||
reward_num:number=2
|
||||
rewards:any[]=[]
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
protected onLoad(): void {
|
||||
|
||||
}
|
||||
|
||||
onAdded(args: any) {
|
||||
console.log("[VictoryComp] onAdded",args)
|
||||
console.log("[VictoryComp] onAdded",args,smc.items)
|
||||
if(args.rewards){
|
||||
this.add_reward(args.rewards)
|
||||
this.rewards=args.rewards
|
||||
}
|
||||
this.node.getChildByName("title").getChildByName("victory").active=args.victory
|
||||
this.node.getChildByName("title").getChildByName("defeat").active=!args.victory
|
||||
this.node.getChildByName("btns").getChildByName("next").active=false
|
||||
@@ -29,12 +35,39 @@ export class VictoryComp extends CCComp {
|
||||
},0.2)
|
||||
}
|
||||
|
||||
|
||||
add_reward(rewards:any[]){
|
||||
let parent=this.node.getChildByName("box").getChildByName("items")
|
||||
let items=parent.children
|
||||
for(let i=0;i<rewards.length;i++){
|
||||
let d_item=rewards[i]
|
||||
let path="game/gui/item"
|
||||
const prefab = oops.res.get(path, Prefab);
|
||||
if (!prefab) {
|
||||
console.error("[MissionComp=>do_drop] 预制体加载失败:", path);
|
||||
return;
|
||||
}
|
||||
const node = instantiate(prefab) as unknown as Node;
|
||||
node.parent=parent
|
||||
node.getComponent(ItemComp)!.update_data(d_item.item_uuid,d_item.count,{no_show:true})
|
||||
}
|
||||
}
|
||||
victory_end(){
|
||||
oops.message.dispatchEvent(GameEvent.MissionEnd)
|
||||
oops.gui.removeByNode(this.node)
|
||||
}
|
||||
|
||||
//看广告双倍
|
||||
watch_ad(){
|
||||
return true
|
||||
}
|
||||
double_reward(){
|
||||
if(this.watch_ad()){
|
||||
this.rewards.forEach(d_item=>{
|
||||
smc.addItem(d_item.item_uuid,d_item.count)
|
||||
})
|
||||
this.node.getChildByName("btns").getChildByName("double").active=false
|
||||
}
|
||||
console.log("[VictoryComp]double_reward",smc.items,this.rewards)
|
||||
}
|
||||
restart(){
|
||||
oops.message.dispatchEvent(GameEvent.MissionStart)
|
||||
oops.gui.removeByNode(this.node)
|
||||
|
||||
Reference in New Issue
Block a user