import FObject, { GroupType } from "../object/FObject"; import FF from "../FF"; import DialogSay from "../box/DialogSay"; import FSprite from "../object/FSprite"; import CMath from "../../../util/CMath"; /** * 草丛中对话和刷新怪物 */ const {ccclass, property} = cc._decorator; @ccclass export default class FGass extends cc.Component { @property({ type:cc.Prefab, displayName: '对话框' }) mDialog: cc.Prefab = null; @property({ type:[cc.String], displayName: '对话内容' }) mContents: Array = []; @property({ type:[cc.Prefab], displayName: '对话完成刷怪' }) mMonster: Array = []; onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){ if(otherCollider.node.group == 'A'){ let sobject = otherCollider.node.getComponent(FObject); if(sobject){ this.node.removeComponent(cc.PhysicsBoxCollider); let ff = sobject.ff; ff.stopRuning(); this.showDialog(ff); } } } public showDialog(ff:FF){ let node = cc.instantiate(this.mDialog); ff.main.viewManage.popView(node); let dialog:DialogSay = node.getComponent(DialogSay); dialog.setContents(this.mContents); dialog.setEndCallback(()=>{ ff.startRuning(); this.flushMonster(ff); }); } public flushMonster(ff:FF){ for (let i = 0; i < this.mMonster.length; i++) { // let node: cc.Node = cc.instantiate(this.mMonster[i]); // let sp: FSprite = node.getComponent(FSprite); // sp.node.group = GroupType.B; // sp.fData = ff.main.sManage.getMonsterData(1001); // node.setPosition(this.getRandInit()); // ff.mMap.addSprite(sp); } } public getRandInit(): cc.Vec2 { let pos = cc.v2(); pos.x = CMath.getRandom(this.node.x - this.node.width / 2, this.node.x + this.node.width / 2); pos.y = CMath.getRandom(this.node.y - this.node.height / 2, this.node.y + this.node.height / 2); return pos; } }