| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import DataObj from "../../configData/DataObj";
- import GameConfig from "../../configData/GameConfig";
- import monsterNode from "../monster/monsterNode";
- import arrow from "./arrow";
- import towerManger from "./towerManger";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Archer extends cc.Component {
- @property(cc.Sprite)
- private jiantou: cc.Sprite = null;
- private animal: sp.Skeleton = null;
- private minter: monsterNode = null;
- private interVec: cc.Vec2 = null;
- private paodanstartPos: cc.Vec2 = null;
- /**是否开始计时 */
- private timeUp = false;
- /**计时数 */
- private timeCount = 0;
- private _arraw: arrow = null;
- protected onLoad() {
- this.jiantou.node.opacity = 0;
- this.animal = this.node.getComponent(sp.Skeleton);
- this.jiantou.node.setPosition(1, 45);
- this.paodanstartPos = this.jiantou.node.getPosition();
- }
- public initTower(myarraw: arrow) {
- this._arraw = myarraw;
- this.jiantou.node.scale = this._arraw.myDataObj.BulletData.model_scaling;
- if (this._arraw.myDataObj.TowerData.id != 7) {
- this.archerAngleUpdate();
- }
-
- }
- public attack(aminter: monsterNode) {
- this.minter = aminter;
- this.animal.setAnimation(0, "animation", false).timeScale = GameConfig.instance().speed;
- this.interVec = this.minter.getNewPos().sub(cc.v2(0, -45));
- let xianglin = this.minter.getTimeSetDistance(this._arraw.myDataObj.BulletData.speed+0.4);
- this.interVec = this.interVec.add(xianglin);
- this.scheduleOnce(function () {
- this.initFeiData();
- }, 0.4);
- }
- private initFeiData() {
-
- this.jiantou.node.setPosition(this.paodanstartPos);
- let arrawpos = this._arraw.node.getPosition();
- let mypos = arrawpos.add(this.node.getPosition());
- let danpos = mypos.add(this.jiantou.node.getPosition());
- this.paodanUpAction(this.interVec, danpos);
- // console.log("this.interVec:"+this.interVec+" danpos:"+danpos);
- }
- private paodanUpAction(pos: cc.Vec2, danpos: cc.Vec2) {
- // this.jiantou.node.angle = 0;
- let hetght = this._arraw.myDataObj.BulletData.parabola[0];
- if (pos.y > danpos.y) {
- hetght = 50+Math.abs(pos.y - danpos.y)*0.5 + this._arraw.myDataObj.BulletData.parabola[0];
- }
- let endpos = pos.sub(danpos);
- if (this.interVec.x > this._arraw.taHuanVec.x) {
- this.animal.node.scaleX = -1;
- endpos = cc.v2(-endpos.x, endpos.y);
- }
- else {
- this.animal.node.scaleX = 1;
- }
-
- if (this._arraw.myDataObj.TowerData.id == 7) {
- cc.tween(this.jiantou.node)
- .by(this._arraw.myDataObj.BulletData.speed,{position:cc.v3(endpos.sub(cc.v2(0,25)))})
- .start();
- this.jiantou.node.opacity = 255;
- }
- else {
- this.ParabolaTo(this._arraw.myDataObj.BulletData.speed, cc.v2(0, 0), endpos, hetght, this._arraw.myDataObj.BulletData.parabola[1]);
- this.scheduleOnce(function () {
- this.jiantou.node.opacity = 255;
- }, 0.03);
- }
-
- this.scheduleOnce(function () {
- this.paodanhuanyuan();
- }, this._arraw.myDataObj.BulletData.speed);
- this.scheduleOnce(function () {
- this._arraw.oneAccack(this);
- }, this._arraw.myDataObj.TowerData.attack_cd);
- }
- /**即时更新箭头角度 */
- private archerAngleUpdate() {
- let self = this;
- let lastP = this.jiantou.node.getPosition();
- this.schedule(function () {
- let curP = self.jiantou.node.getPosition();
- if (curP.x != lastP.x && curP.y != lastP.y) {
- let dirVec = curP.sub(lastP);//获得从startPos指向endPos的方向向量
- let comVec = new cc.Vec2(0, 1);//计算夹角的参考方向,这里选择x轴正方向
- let radian = cc.v2(dirVec).signAngle(comVec);// --向量夹角弧度(相对于y轴正向)
- let angle = radian * 180 / Math.PI; //-- 弧度值转换为角度 公式:弧度=度*π/180
- self.jiantou.node.angle = -angle;
- }
- lastP = curP;
- }, 0);
- }
- /**抛物线运动 */
- private ParabolaTo(t: number, startPoint: cc.Vec2, endPoint: cc.Vec2, height: number, angle: number) {
- // 把角度转换为弧度
- // let radian = angle ;
- let radian = angle * 3.14159 / 180.0;
- // 第一个控制点为抛物线左半弧的中点
- let q1x = startPoint.x + (endPoint.x - startPoint.x) / 2.0;
- let q1 = cc.v2(q1x, height + startPoint.y + Math.cos(radian) * q1x);
- // 第二个控制点为整个抛物线的中点
- let q2x = startPoint.x + (endPoint.x - startPoint.x) / 2.0;
- let q2 = cc.v2(q2x, height + startPoint.y + Math.cos(radian) * q2x);
- //曲线配置
- var bezier = [q1, q2, endPoint];
- // console.log("endPoint:"+endPoint);
- //使用CCEaseInOut让曲线运动有一个由慢到快的变化,显得更自然
- let bezerby = cc.bezierTo(t, bezier);
- this.jiantou.node.runAction(bezerby);
- // this.jiantou.node.runAction(bezerby.easing(cc.easeInOut(t)));
- }
- private paodanhuanyuan() {
- if (this.minter.AniStatus == 'ZhengDie'&&this._arraw.myDataObj.TowerData.id != 7) {
- this.scheduleOnce(function () {
- this.jiantou.node.opacity = 0;
- this.jiantou.node.setPosition(this.paodanstartPos);
- }, this._arraw.myDataObj.TowerData.attack_cd - this._arraw.myDataObj.BulletData.speed-0.1);
- }
- else {
- this.jiantou.node.opacity = 0;
- this.jiantou.node.setPosition(this.paodanstartPos);
- }
- let attck = this._arraw.myDataObj.getRanm(1, this._arraw.myDataObj.BulletData.attack);
- let reduction = this.minter.myDataObj.monsterData.physics_reduction;
- if (towerManger.instance.talantData[2].length > 0) {
- reduction -= towerManger.instance.talantData[2][0];
- if (reduction < 0) {
- reduction = 0;
- }
- }
- if (towerManger.instance.talantData[4].length > 0) {
- if (Math.random() < towerManger.instance.talantData[4][0]) {
- attck *= towerManger.instance.talantData[4][1];
- }
- }
- let realHurt = attck * (1 - reduction);
- //技能7-9 爆头一击
- // if (this._arraw.SkillIDL >= 7 && this._arraw.SkillIDL <= 9) {
- // this._arraw.myDataObj.writeSkill_Config(this._arraw.SkillIDL);
- // let jilv = Number(this._arraw.myDataObj.SkillData.parameter_2);
- // if (Math.random() < jilv) {
- // realHurt *= 2;
- // }
- // }
- this.minter.hpDown(realHurt);
- // this.skillNorattack(this._arraw.SkillIDL);
- }
- /**普攻技能 */
- private skillNorattack(ID: number) {
- if (ID <= 3 && ID > 0) {
- if (!this.timeUp) {
- this.timeUp = true;
- this.skill1_3();
- }
- else {
- this.timeCount = 0;
- }
- }
- }
- /**id 1-3技能 剧毒箭矢*/
- private skill1_3() {
- this.scheduleOnce(() => {
- this._arraw.myDataObj.writeSkill_Config(this._arraw.SkillIDL);
- let shanghai = Number(this._arraw.myDataObj.SkillData.parameter_2);
- let totalcount = Number(this._arraw.myDataObj.SkillData.parameter_3);
- this.minter.hpDown(shanghai);
- this.timeCount++;
- if (this.timeCount <= totalcount) {
- this.skill1_3();
- }
- else {
- this.timeUp = false;
- }
- }, 1);
- }
- }
|