123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import FqLogin from "../../../../login/FqLogin";
- import { HttpStateType, ReveData } from "../../../../util/CHttp";
- import FFCalAttr from "../../../data/FFCalAttr";
- import AIPet from "../../object/AI/AIPet";
- import { GroupType } from "../../object/FObject";
- import FSprite, { SpriteActionType } from "../../object/FSprite";
- import PSprite from "../../object/PSprite";
- import BaseEvent from ".././base/BaseEvent";
- /**
- * 解救射手
- */
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class FCageShooter extends BaseEvent {
- @property({
- displayName: '解救的伙伴id',
- })
- mPetId: number = 1;
- @property({
- displayName: '牢笼动画',
- tooltip: '显示牢笼的动画',
- type: sp.Skeleton
- })
- spine: sp.Skeleton = null;//牢笼
- @property({
- displayName: '牢笼中的伙伴',
- type: cc.Node
- })
- mPet: cc.Node = null;//伙伴
- @property({
- displayName: '伙伴预制体',
- type: cc.Prefab
- })
- mPetPrefab: cc.Prefab = null;
- @property({
- displayName: '靠近的提示',
- type: cc.Sprite
- })
- mIcon: cc.Sprite = null;//靠近后的提示
- @property({
- type: [cc.SpriteFrame],
- displayName: '不同状态的图标'
- })
- mIconFrame: Array<cc.SpriteFrame> = [];
- @property({
- displayName: '提示图标',
- type: cc.SpriteFrame
- })
- mTipsIcon: cc.SpriteFrame = null;
- @property({
- type: [cc.Node],
- displayName: '需要打开的门'
- })
- mDoor: Array<cc.Node> = [];
- @property([cc.String])
- text: Array<string> = [];
- private isOver = false;
- onLoad() {
- super.onLoad()
- if (this.mIcon) {
- this.mIcon.node.active = false;
- }
- let petAttr = this.ff.main.player.getPet(this.mPetId)
- if (petAttr) {
- this.isOver = true
- if (this.spine.findAnimation("open3")) {
- this.spine.setAnimation(0, 'open3', false);
- } else {
- this.spine.setAnimation(0, 'open', false);
- }
- this.mPet.destroy()
- for (let i = 0; i < this.mDoor.length; i++) {
- const element = this.mDoor[i];
- element.destroy()
- }
- }
- }
- onBegin(tag: number) {
- if (this.isOver) {
- return;
- }
- if (tag == 1) {
- this.iconTips(true);
- this.showOpt(this.mTipsIcon, () => {
- this.iconTips(false);
- this.closeOpt()
- this.openCage()
- })
- }
- }
- onEnd(tag: number) {
- if (tag == 1) {
- this.iconTips(false);
- this.closeOpt()
- }
- }
- /**
- *
- * @param show 是否显示提示
- */
- private iconTips(show) {
- if (this.mIcon) {
- if (show) {
- this.mIcon.node.active = true;
- let head = this.ff.mFFheader;
- let count = head.getTmpCount(2001);
- if (count > 0) {
- this.mIcon.spriteFrame = this.mIconFrame[0]
- } else {
- this.mIcon.spriteFrame = this.mIconFrame[1]
- }
- } else {
- this.mIcon.node.active = false;
- }
- }
- }
- //打开牢笼
- private openCage() {
- let head = this.ff.mFFheader;
- let count = head.getTmpCount(2001);
- if (count > 0) {
- this.isOver = true;
- this.spine.setCompleteListener(() => {
- this.spine.setCompleteListener(null);
- this.movePet()
- });
- if (this.spine.findAnimation("open3")) {
- this.spine.setAnimation(0, 'open3', false);
- } else {
- this.spine.setAnimation(0, 'open', false);
- }
- FqLogin.commitEvent(this.node.name, '', '');
- } else {
- this.ff.main.showTips('需要一把牢笼钥匙');
- }
- }
- private movePet() {
- let anim = this.mPet.getComponent(cc.Animation);
- let spine = this.mPet.getComponent(sp.Skeleton);
- spine.setAnimation(0, SpriteActionType.run, true);
- anim.on('finished', this.onFinished, this);
- anim.play('cage_pet_move');
- }
- private onFinished(num, string) {
- let anim = this.mPet.getComponent(cc.Animation);
- let spine = this.mPet.getComponent(sp.Skeleton);
- anim.off('finished', this.onFinished, this);
- spine.setAnimation(0, SpriteActionType.stand, true);
- //开始对话
- this.dialog(0)
- }
- private dialog(index: number) {
- if (index >= this.text.length) {
- this.getPet()
- return;
- }
- let texts = this.text[index].split('|')
- let mid = parseInt(texts.shift());
- if (mid == -1) {//主角
- let my = this.ff.mainSprite.node;
- this.showDialog(my, texts, () => {
- index++;
- this.dialog(index);
- });
- } else {
- let my = this.mPet;
- let pos = cc.v2()
- pos.x = this.node.x + my.x
- pos.y = this.node.y + my.y
- pos.y += my.height
- this.showDialogPos(pos, texts, () => {
- index++;
- this.dialog(index);
- });
- }
- }
- /**
- * 解救伙伴
- */
- private getPet() {
- this.isOver = true
- let head = this.ff.mFFheader;
- head.removeTmpGood(2001, 1);
- let msg = {
- petId: this.mPetId
- }
- let main = this.ff.main
- main.gameHttp.sendJson('stage/v1/getPet', msg, (state, reve: ReveData) => {
- main.stopLoad();
- if (state == HttpStateType.SUCCESS) {
- if (reve.retCode == 0) {
- let player = main.player;
- let petAttr = reve.data.petObject
- player.pet[this.mPetId] = petAttr;
- petAttr.id = this.mPetId;
- let node = cc.instantiate(this.mPetPrefab);
- node.group = GroupType.A;
- node.x = this.node.x + this.mPet.x
- node.y = this.node.y + this.mPet.y
- let sp = node.addComponent(PSprite);
- let attrData = FFCalAttr.getAttr(this.ff.main, petAttr)
- sp.setAttrData(attrData)
- this.ff.addRole(sp);
- sp.hp = sp.attrData.hp
- sp.addComponent(AIPet);
- this.mPet.removeFromParent();
- for (let i = 0; i < this.mDoor.length; i++) {
- const element = this.mDoor[i];
- element.destroy()
- }
- } else {
- main.showTips(reve.message);
- }
- } else {
- main.showTips('网络异常');
- }
- });
- }
- }
|