| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- import GameConfig from "../../configData/GameConfig";
- import monsterManger from "../monster/monsterManger";
- import TowerHuan from "./TowerHuan";
- import taside from "./taside";
- import monsterNode from "../monster/monsterNode";
- import soldie from "../monster/soldie";
- import towerManger from "./towerManger";
- import DataObj from "../../configData/DataObj";
- import gameUI from "../UIFace/gameUI";
- import gameData from "../../configData/gameData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class barracks extends cc.Component {
- private GoPos: cc.Vec3[] = null;//1路线坐标集合
- private minPos: cc.Vec2 = null;
- private _taHuan: TowerHuan = null;
- public _taside: taside = null;
- private taHuanVec: cc.Vec2 = null;
- private soldieThree: soldie[] = [];
- public towerType = 0;
- public myDataObj: DataObj = null;
- private isStartWait = true;
- private startPosArr: cc.Vec2[] = [];
- /**左技能ID */
- public SkillIDL = 0;
- /**右技能ID */
- public SkillIDR = 0;
- /**3技能ID */
- public SkillIDT = 0;
- /**攻击范围内的怪物 */
- private attackmonster: monsterNode[] = [];
- onLoad() {
- this.GoPos = gameUI.instance.getGoPos();
- this.myDataObj = new DataObj();
- }
- /**根据ID读取数据 */
- public initID(ID: number) {
- this.myDataObj.writeTower_Config(ID);
- if (towerManger.instance.talantData[7].length > 0) {
- this.myDataObj.TowerData.attack_range *= (1 + towerManger.instance.talantData[7][0]);
- }
- this._taside.setRedHuanScale(this.myDataObj.TowerData.attack_range);
- }
- /**设置或升级技能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;
- }
- }
- if (skillType == 3) {
- if (this.SkillIDT == 0) {
- this.SkillIDT = this.myDataObj.TowerData.next_skill[2];
- }
- else {
- this.myDataObj.writeSkill_Config(this.SkillIDT);
- this.SkillIDT = this.myDataObj.SkillData.next_skill;
- }
- }
- // this.skillSpeattack();
- }
- /**获取兵当前坐标 */
- public getSoldePosArr(): cc.Vec2[] {
- this.startPosArr = [];
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- this.startPosArr.push(element.node.getPosition());
- }
- return this.startPosArr.concat();
- }
- /**设置兵当前坐标 */
- public setSoldePosArr(arr: cc.Vec2[]) {
- this.startPosArr = arr;
- }
- /**加载兵
- * @param num 3塔兵 2技能兵
- */
- private loadSolde(num: number) {
- let self = this;
- let arr: cc.Vec2[] = [self.minPos.add(cc.v2(-20, 0)), self.minPos.add(cc.v2(20, 20)), self.minPos.add(cc.v2(20, -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);
- monsterManger.instance.node.addChild(newNode, 3);
- let startpos = self.taHuanVec.add(cc.v2(0, -57));
- if (self.minPos.y > self.taHuanVec.y) {
- startpos = self.taHuanVec.add(cc.v2(0, 37));
- }
- let theSolde = newNode.getComponent(soldie);
- theSolde.initLevelData(self,self.myDataObj.TowerData.monster_id[0]);
- theSolde.initTalant();
- theSolde.setIsSkill(false);
- theSolde.setinitPos(startpos, arr[i]);
- if (self.startPosArr.length > 0) {
- newNode.setPosition(self.startPosArr[i]);
- if (self.startPosArr[i] == cc.v2(0, 0)) {
- theSolde.initWalkToPoint(true);
- }
- }
- else {
- theSolde.initWalkToPoint(true);
- }
- self.soldieThree.push(theSolde);
- theSolde.setSche();
- }
- self.scheduleOnce(function () {
- self.isStartWait = false;
- }, 0);
- });
- }
- /**插旗 */
- public chaqiWalk(laca: cc.Vec2) {
- let self = this;
- this.minPos = laca;
- let arr: cc.Vec2[] = [self.minPos.add(cc.v2(-20, 0)), self.minPos.add(cc.v2(20, 20)), self.minPos.add(cc.v2(20, -20))];
- this.Disassociate();
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.setinitPos(null, arr[i]);
- // element.setisCanAttck(false);
- element.initWalkToPoint(false);
- }
- // this.scheduleOnce(function(){
- // for (let i = 0; i < this.soldieThree.length; i++) {
- // const element = this.soldieThree[i];
- // element.setisCanAttck(true);
- // }
- // },1);
- }
- /**无怪物时兵归位 */
- private attackOver() {
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.initWalkToPoint(false);
- }
- }
- /**暂停动画 */
- public isPaused(ispause: boolean) {
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.ispaused(ispause);
- }
- }
- /** 环*/
- public setTaHuan(taHuan: TowerHuan) {
- this._taHuan = taHuan;
- this.taHuanVec = taHuan.node.getPosition();
- this.minPos = this.getMinPoint();
- if (this.myDataObj.TowerData.tower_level == 1) {
- cc.tween(this.node)
- .delay(Number(gameData.instance().game_Const[1][2]) - 0.04)
- .call(() => {
- this.loadSolde(this.myDataObj.TowerData.monster_id[1]);
- })
- .start();
- }
- else
- {
- this.loadSolde(this.myDataObj.TowerData.monster_id[1]);
- }
-
- this._taHuan.setRedHuanScale(this.myDataObj.TowerData.attack_range);
- }
- /**设置泥土 */
- public setNitu(mytaside: taside) {
- this._taside = mytaside;
- }
- onDestroy() {
- this.attackmonster = [];
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.node.destroy();
- }
- this.Disassociate();
- this._taHuan.node.destroy();
- }
- /**接触怪和兵关联 */
- private Disassociate() {
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- if (element.getMymonster() != null) {
- if (element.getMymonster().node != null) {
- element.getMymonster().DelateAllBarracks();
- element.getMymonster().animalwalk();
- element.getMymonster().stopAni(false);
- }
- }
- }
- }
- /**刷新 */
- public getIsInSqrt(pos: cc.Vec2) {
- let xiangl = this.taHuanVec.sub(pos);
- let attack_range = this.myDataObj.TowerData.attack_range;
- let a = attack_range;
- let b = attack_range * 5 / 6;
- let jieguo = xiangl.x * xiangl.x / (a * a) + xiangl.y * xiangl.y / (b * b);
- 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) {
- let index = this.attackmonster.indexOf(monter);
- if (index < 0) {
- if (monter.myDataObj.monsterData.company_type == 2) {
- if (this.myDataObj.TowerData.air_attack_switch == 'ON') {
- this.attackmonster.push(monter);
- this.moreMonsterAttack();
- }
- }
- else
- {
- this.attackmonster.push(monter);
- this.moreMonsterAttack();
- }
- }
- }
- }
- public DelateAllAttackmonster() {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (element.node == null) {
- this.attackmonster.splice(i, 1);
- i--;
- continue;
- }
- let isIn = this.getIsInSqrt(element.node.getPosition());
- if (!isIn || element.AniStatus == 'ZhengDie') {
- this.attackmonster.splice(i, 1);
- i--;
- }
- }
- }
- /**调整兵围攻数量 */
- private moreMonsterAttack() {
- if (this.attackmonster.length <= 1) {
- return;
- }
- if (this.attackmonster.length == 2) {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- element.DelateBarracksRetain(2);
- }
- }
- if (this.attackmonster.length >= 3) {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- element.DelateBarracksRetain(1);
- }
- }
- }
- /**开始攻击 */
- public attckStart() {
- if (this.attackmonster.length == 0) {
- this.attackOver();
- return;
- }
- let self = this;
- this.scheduleOnce(function () {
- self.DelateAllAttackmonster();
- self.attckStart();
- }, 0.3);
- }
- /**路线距离兵营最近点坐标 */
- private getMinPoint(): cc.Vec2 {
- let mylength = this.taHuanVec.sub(cc.v2(this.GoPos[0].x, this.GoPos[0].y)).mag();
- let mindex = 0;
- for (let index = 1; index < this.GoPos.length; index++) {
- const element = this.GoPos[index];
- let juli = this.taHuanVec.sub(cc.v2(element.x, element.y)).mag();
- if (juli < mylength) {
- mindex = index;
- mylength = juli;
- }
- }
- return cc.v2(this.GoPos[mindex].x, this.GoPos[mindex].y);
- }
- /**特殊技能 */
- private skillSpeattack() {
- /**冷却时间 */
- let delayTime = this.myDataObj.SkillData.parameter_4;
- if (this.SkillIDL >= 37 && this.SkillIDL <= 39) {
- this.schedule(this.skill37_39, delayTime);
- }
- if (this.SkillIDR >= 40 && this.SkillIDR <= 43) {
- this.skill40_42();
- }
- if (this.SkillIDT >= 52 && this.SkillIDT <= 54) {
- this.schedule(this.skill52_54, delayTime);
- }
- }
- /**id 37-39技能 治疗术 */
- private skill37_39() {
- if (this.attackmonster.length == 0) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDL);
- /**伤害数值 */
- let huixue = this.myDataObj.getRanm(1, this.myDataObj.SkillData.parameter_2);
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.hpDown(-huixue);
- }
- }
- /**id 40-42技能 神圣护甲 */
- private skill40_42() {
- if (this.attackmonster.length == 0) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDR);
- /**物理免伤 */
- let reduce = Number(this.myDataObj.SkillData.parameter_3);
- for (let i = 0; i < this.soldieThree.length; i++) {
- const element = this.soldieThree[i];
- element.myDataObj.monsterData.physics_reduction += reduce * 100;
- }
- }
- /**id 43-45技能 神圣之力 */
- public skill43_45(attackSoldie: soldie) {
- if (this.attackmonster.length == 0) {
- return;
- }
- if (this.SkillIDT < 43 || this.SkillIDT > 45) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDT);
- /**伤害数值 */
- 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;
- if (Math.random() < totalcount) {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (attackSoldie.getMymonster() == element) {
- continue;
- }
- let monToDexLeth = attackSoldie.node.getPosition().sub(element.node.getPosition()).mag();
- if (monToDexLeth < pointNum) {
- element.hpDown(shanghai);
- }
- }
- }
- }
- /**id 46-48技能 双持战斧 */
- public skill46_48(attackSoldie: soldie) {
- if (this.attackmonster.length == 0) {
- return;
- }
- if (this.SkillIDL < 46 || this.SkillIDL > 48) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDL);
- /** */
- let monId = this.myDataObj.getRanm(1, this.myDataObj.SkillData.parameter_2);
- /**伤害 */
- let shanghai = Number(this.myDataObj.SkillData.parameter_3);
-
- attackSoldie.getMymonster().hpDown(shanghai);
-
- }
- /**id 49-51技能 回旋斩 */
- public skill49_51(attackSoldie: soldie) {
- if (this.attackmonster.length == 0) {
- return;
- }
- if (this.SkillIDR < 49 || this.SkillIDR > 51) {
- return;
- }
- this.myDataObj.writeSkill_Config(this.SkillIDR);
- /**伤害数值 */
- 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;
- if (Math.random() < totalcount) {
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
- if (attackSoldie.getMymonster() == element) {
- continue;
- }
- let monToDexLeth = attackSoldie.node.getPosition().sub(element.node.getPosition()).mag();
- if (monToDexLeth < pointNum) {
- element.hpDown(shanghai);
- }
- }
- }
- }
- /**id 52-54技能 投掷领悟 */
- public skill52_54() {
- if (this.attackmonster.length == 0) {
- return;
- }
- if (this.SkillIDT < 52 || this.SkillIDT > 54) {
- return;
- }
- /**伤害数值 */
- let shanghai = this.myDataObj.getRanm(1, this.myDataObj.SkillData.parameter_2);
- /**射程 */
- let totalcount = Number(this.myDataObj.SkillData.parameter_3);
-
- for (let k = 0; k < this.soldieThree.length; k++) {
- const element1 = this.soldieThree[k];
- for (let i = 0; i < this.attackmonster.length; i++) {
- const element = this.attackmonster[i];
-
- let monToDexLeth = element1.node.getPosition().sub(element.node.getPosition()).mag();
- if (monToDexLeth < totalcount) {
- element.hpDown(shanghai);
- break;
- }
- }
- }
- }
- }
|