| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- import DataObj from "../../configData/DataObj";
- import GameConfig from "../../configData/GameConfig";
- import monsterNode from "../monster/monsterNode";
- import Archer from "./Archer";
- import taside from "./taside";
- import TowerHuan from "./TowerHuan";
- import towerManger from "./towerManger";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class arrow extends cc.Component {
- private _taHuan: TowerHuan = null;
- public _taside: taside = null;
- public taHuanVec: cc.Vec2 = null;
- public myDataObj: DataObj = null;
- /**攻击范围内的怪物 */
- private attackmonster: monsterNode[] = [];
- private archer: Archer[] = [];
- public towerType = 0;
-
- /**左技能ID */
- public SkillIDL = 0;
- /**右技能ID */
- public SkillIDR = 0;
- private timeCount = 0;
- private isStartWait = true;
- public talantData = {
- };
- protected onLoad() {
- this.myDataObj = new DataObj();
- }
- /**根据ID读取数据 */
- public initID(ID: number) {
- this.myDataObj.writeTower_Config(ID);
- this.myDataObj.writeBullet_Config(this.myDataObj.TowerData.bullet_id);
-
- if (towerManger.instance.talantData[1].length > 0 && towerManger.instance.talantData[3].length > 0) {
- this.myDataObj.TowerData.attack_range *= (1 + towerManger.instance.talantData[3][0] + towerManger.instance.talantData[1][0]);
- }
- else {
- if (towerManger.instance.talantData[1].length > 0) {
- this.myDataObj.TowerData.attack_range *= (1 + towerManger.instance.talantData[1][0]);
- }
- if (towerManger.instance.talantData[3].length > 0) {
- this.myDataObj.TowerData.attack_range *= (1 + towerManger.instance.talantData[3][0]);
- }
- }
- this.loadArcher(this.myDataObj.TowerData.monster_id[1]);
- }
- /**设置或升级技能ID 技能类型 1左边 2右边*/
- public setandUpSkillId(skillType:number)
- {
- if (skillType == 1) {
- if (this.SkillIDL == 0) {
- this.SkillIDL = this.myDataObj.TowerData.next_skill[0];
- }
- else
- {
- this.myDataObj.writeSkill_Config(this.SkillIDL);
- this.SkillIDL = this.myDataObj.SkillData.next_skill;
- }
- }
-
- if (skillType == 2) {
- if (this.SkillIDR == 0) {
- this.SkillIDR = this.myDataObj.TowerData.next_skill[1];
- }
- else
- {
- this.myDataObj.writeSkill_Config(this.SkillIDR);
- this.SkillIDR = this.myDataObj.SkillData.next_skill;
- }
- }
- // this.skillSpeattack();
- }
- private loadArcher(num: number) {
- let self = this;
- let arr = [];
- if (num == 1) {
- arr = [cc.v2(0, 20)];
- }
- if (num == 2) {
- arr = [cc.v2(-21, 20), cc.v2(11, 20)];
- if (this.myDataObj.TowerData.id == 3) {
- arr = [cc.v2(-19, 5), cc.v2(13, 5)];
- }
- if (this.myDataObj.TowerData.id == 4) {
- arr = [cc.v2(-19, -5), cc.v2(13, -5)];
- }
- if (this.myDataObj.TowerData.id == 7) {
- arr = [cc.v2(-19-10, 8), cc.v2(13+10, 8)];
- }
- }
- if (num == 3) {
- arr = [cc.v2(-30, 20), cc.v2(0, 20), cc.v2(30, 20)];
- }
- cc.resources.load("prefabs/" + this.myDataObj.TowerData.name2, cc.Prefab, function (err, prefab: cc.Prefab) {
- for (let i = 0; i < num; i++) {
- var newNode = cc.instantiate(prefab);
- self.node.addChild(newNode);
- newNode.setPosition(arr[i]);
- let theSolde = newNode.getComponent(Archer);
- theSolde.initTower(self);
- self.archer.push(theSolde);
- }
- if (self.myDataObj.TowerData.tower_level == 1) {
- self.isStartWait = false;
- }
- else
- {
- self.scheduleOnce(function(){
- self.isStartWait = false;
- },self.myDataObj.TowerData.attack_cd);
- }
-
- });
- }
- public setTaHuan(taHuan: TowerHuan) {
- this._taHuan = taHuan;
- this.taHuanVec = taHuan.node.getPosition();
- this._taHuan.setRedHuanScale(this.myDataObj.TowerData.attack_range);
- this._taside.setRedHuanScale(this.myDataObj.TowerData.attack_range);
- }
- public setNitu(mytaside: taside) {
- this._taside = mytaside;
- }
- onDestroy() {
- this._taHuan.node.destroy();
- this.attackmonster = [];
- }
- public getIsInSqrt(pos: cc.Vec2): boolean {
- let xiangl = this.taHuanVec.sub(pos);
- let attack_range = this.myDataObj.TowerData.attack_range;
- let a = attack_range;
- let b = attack_range * 5 / 6;
- if (xiangl.x * xiangl.x / (a * a) + xiangl.y * xiangl.y / (b * b) < 1) {
- return true;
- }
- else {
- return false;
- }
- }
- public getAttackmonster(): monsterNode[] {
- return this.attackmonster;
- }
- public addAttackmonster(monter: monsterNode) {
- if (!this.isStartWait) {
- if (monter.myDataObj.monsterData.company_type == 2) {
- if (this.myDataObj.TowerData.air_attack_switch == 'ON') {
- this.attackmonster.push(monter);
- }
- }
- else
- {
- this.attackmonster.push(monter);
- }
- }
- }
- private DelateAllAttackmonster() {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (element.node == null) {
- console.log("arraw!!!!!!!!!!");
- this.attackmonster.splice(i, 1);
- i--;
- continue;
- }
- if (!this.getIsInSqrt(element.node.getPosition()) || element.AniStatus == 'ZhengDie') {
- this.attackmonster.splice(i, 1);
- i--;
- }
- }
- }
- /**开始攻击 */
- public attckStart() {
- if (this.attackmonster.length == 0) {
- return;
- }
- for (let i = 0; i < this.archer.length; i++) {
- const element = this.archer[i];
- this.scheduleOnce(function () {
- element.attack(this.attackmonster[0]);
- }, i * 0.3);
- }
- }
- public oneAccack(myArcher: Archer) {
- this.DelateAllAttackmonster();
- if (this.attackmonster.length == 0) {
- return;
- }
- myArcher.attack(this.attackmonster[0]);
- }
- /**特殊技能 */
- private skillSpeattack() {
- /**冷却时间 */
- let delayTime = this.myDataObj.SkillData.parameter_4;
- if (this.SkillIDR >= 4 && this.SkillIDR <= 6) {
- this.schedule(this.skill4_6, delayTime);
- }
- if (this.SkillIDR >= 10 && this.SkillIDR <= 12) {
- this.schedule(this.skill10_12, delayTime);
- }
- }
- /**id 4-6技能 藤蔓缠绕*/
- private skill4_6() {
- if (this.attackmonster.length == 0) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDR);
- this.timeCount = 0;
- /**伤害数值 */
- let shanghai = Number(this.myDataObj.SkillData.parameter_2);
- /**持续时间 */
- let totalcount = Number(this.myDataObj.SkillData.parameter_3);
- /**目标数量 */
- let pointNum = this.myDataObj.SkillData.parameter_5;
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (i < pointNum) {
- element.SetWalk(true);
- }
- }
- this.schedule(() => {
- this.timeCount++;
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (i < pointNum) {
- element.hpDown(shanghai);
- if (this.timeCount >= totalcount) {
- element.SetWalk(false);
- }
- }
- }
- }, 1, totalcount - 1);
- }
- /**id 10-12技能 弹幕射击*/
- private skill10_12() {
- if (this.attackmonster.length == 0) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDR);
- this.timeCount = 0;
- /**伤害数值 */
- let shanghai = this.myDataObj.getRanm(1, this.myDataObj.SkillData.parameter_2);
- /**射程半径 */
- let totalcount = Number(this.myDataObj.SkillData.parameter_3);
- /**目标数量 */
- let pointNum = this.myDataObj.SkillData.parameter_5;
- let dex = 0;
- let juli = 10000;
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- let monTotaLeth = this.taHuanVec.sub(element.node.getPosition()).mag();
- if (monTotaLeth < juli) {
- juli = monTotaLeth;
- dex = i;
- }
- }
- let dexPos = this.attackmonster[dex].node.getPosition();
- let arrTemp: monsterNode[] = [];
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- let monToDexLeth = dexPos.sub(element.node.getPosition()).mag();
- if (monToDexLeth < totalcount) {
- arrTemp.push(element);
- }
- }
- for (let i = 0; i < arrTemp.length; i++) {
- const element = arrTemp[i];
- if (i < pointNum) {
- element.hpDown(shanghai);
- }
- }
- }
- }
|