123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { ConfigConst, EConfigConst } from "../cfg/ConfigDef";
- import { ConfigMgr } from "../cfg/configMgr";
- import { MonsterItem } from "../cfg/monsterItem";
- import { Utils } from "../common/utils";
- import { ZooId } from "../zoo/zooId";
- import { BulletPlay } from "./bulletPlay";
- const { ccclass, property, executeInEditMode, playOnFocus } = cc._decorator;
- @ccclass
- export class MonsterModel extends cc.Component {
- hp: number = 1000;
- atk: number = 100;
- zooId: number;
- protected onLoad(): void {
- this.zooId = this.addComponent(ZooId).id;
- cc.log('[MonsterModel]', this.zooId);
- }
- beAttacked(harmNum: number) {
- this.hp -= harmNum;
- }
- isOver() {
- return this.hp <= 0;
- }
- init(id: string, level: number) {
- let monsterData = ConfigMgr.inst.getCfgClassById<MonsterItem>(EConfigConst.monster, id, MonsterItem);
- let atk = Utils.strToJson(monsterData.data.atk);
- let hp = Utils.strToJson(monsterData.data.hp);
- this.hp = hp[0] + (level - 1) * hp[1];
- this.atk = atk[0] + (level - 1) * atk[1];
- cc.log('[MonsterModel] [init]', `[id:${id}]-[level:${level}]`, `[hp:${this.hp} atk:${this.atk}]`);
- }
- setBullet(data: []) {
- if (!data) return;
- cc.log('[MonsterModel] [setBullet]', data);
- let len = Math.floor(data.length / 2);
- for (let index = 0; index < len; index++) {
- let cpt = this.addComponent(BulletPlay);
- cpt.monsterZooid = this.zooId;
- cpt.init(data[1 + index * 2], data[2 + index * 2]);
- cpt.start();
- }
- // let cpt = this.addComponent(BulletPlay);
- // cpt.monsterZooid = this.zooId;
- // cpt.init('1001', 0);
- }
- }
|