136 lines
4.8 KiB
TypeScript
136 lines
4.8 KiB
TypeScript
import { instantiate } from 'cc';
|
|
import { Prefab } from 'cc';
|
|
import { _decorator, Component, Node } from 'cc';
|
|
import { LayoutManager } from '../LayoutManager';
|
|
import { BulletBase } from './BulletBase';
|
|
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
|
|
import { UmLog } from '../../../../cc-common/cc-util/UmLog';
|
|
import { ShootingDataInfo } from '../../global/GameInterface';
|
|
import { GameGlobalData } from '../../global/GameGlobalData';
|
|
import { UITransform } from 'cc';
|
|
import { ESKILL_SPECIAL_TYPE as ESPECIAL_SKILL_TYPE, GameDefine } from '../../config/GameDefine';
|
|
import { Vec3 } from 'cc';
|
|
import { GameAssets } from '../../global/GameAssets';
|
|
import { ActiveSkillBase } from '../hero/ActiveSkillBase';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('ShootingBase')
|
|
export class ShootingBase extends Component {
|
|
@property(Prefab) bulletPrefab: Prefab = null!;
|
|
lastShootingTime = 0;
|
|
speedScale = 1;
|
|
|
|
public setSpeed(speedScale: number) {
|
|
this.speedScale = speedScale;
|
|
}
|
|
|
|
public shooting(start, target, shootingDataInfo, specialSkillId = -1, parent: Node = null) {
|
|
if (!GameGlobalData.Instance.isStatePlay()) return;
|
|
|
|
// UmLog.log("shooting => ", JSON.stringify(shootingDataInfo));
|
|
var shootingTarget = target as Node;
|
|
var startPoint = start.worldPosition;
|
|
var targetPoint = shootingTarget?.active ? target.worldPosition : target;
|
|
|
|
this.speedScale = shootingDataInfo.AtkSpeed;
|
|
var cooldown_time = shootingDataInfo.AtkCoolDown;
|
|
|
|
//conver cooldown time to mili seconds
|
|
if (cooldown_time < 100)
|
|
cooldown_time *= 1000;
|
|
|
|
var timeNow = UmUtil.getTime();
|
|
if (timeNow < (this.lastShootingTime + cooldown_time))
|
|
return;
|
|
|
|
// UmLog.log("shooting => ", timeNow);
|
|
this.lastShootingTime = timeNow;
|
|
|
|
if (!parent)
|
|
parent = LayoutManager.instance.gameplaySpaceLayout;
|
|
|
|
if (specialSkillId > 0) {
|
|
this.specialSkillShooting(startPoint, targetPoint, shootingDataInfo, parent, specialSkillId);
|
|
}
|
|
else {
|
|
this.normalShooting(startPoint, targetPoint, shootingDataInfo, parent);
|
|
}
|
|
}
|
|
|
|
|
|
normalShooting(startPoint, targetPoint, shootingDataInfo, parent) {
|
|
this.addBullet(startPoint, targetPoint, shootingDataInfo, parent);
|
|
}
|
|
|
|
|
|
specialSkillShooting(startPoint, targetPoint, shootingDataInfo, parent, specialSkillId) {
|
|
UmLog.log("specialSkillShooting => ", specialSkillId);
|
|
switch (specialSkillId) {
|
|
case Number(ESPECIAL_SKILL_TYPE.SKILL_1):
|
|
{
|
|
shootingDataInfo.Damage *= 5;
|
|
this.addBullet(startPoint, targetPoint, shootingDataInfo, parent, specialSkillId);
|
|
}
|
|
break;
|
|
|
|
case Number(ESPECIAL_SKILL_TYPE.SKILL_2):
|
|
this.speacialSkillType2Shooting(startPoint, targetPoint, shootingDataInfo, parent);
|
|
break;
|
|
|
|
default:
|
|
this.addBullet(startPoint, targetPoint, shootingDataInfo, parent);
|
|
break;
|
|
}
|
|
}
|
|
|
|
speacialSkillType2Shooting(startPoint, targetPoint, shootingDataInfo, parent)
|
|
{
|
|
var space = 60;
|
|
var listSpaces = new Array();
|
|
listSpaces.push(0);
|
|
listSpaces.push(space * 1);
|
|
listSpaces.push(space * 2);
|
|
listSpaces.push(space * 3);
|
|
listSpaces.push(space * -1);
|
|
listSpaces.push(space * -2);
|
|
listSpaces.push(space * -3);
|
|
|
|
|
|
for (var i = 0; i < listSpaces.length; i++)
|
|
{
|
|
this.addBullet(UmUtil.plusTwoVector3(startPoint, new Vec3(listSpaces[i], 0)), UmUtil.plusTwoVector3(targetPoint, new Vec3(listSpaces[i], 0)), shootingDataInfo, parent);
|
|
}
|
|
|
|
}
|
|
|
|
addBullet(startPoint, targetPoint, shootingDataInfo, parent, specialSkillId = -1) {
|
|
var bullet = instantiate(this.bulletPrefab)?.getComponent(BulletBase);
|
|
parent.addChild(bullet.node);
|
|
bullet.node.worldPosition = startPoint;
|
|
bullet.node.setNodeActive(true);
|
|
bullet.setDamage(shootingDataInfo.Damage);
|
|
bullet.setSpecialSkill(specialSkillId);
|
|
bullet.shooting(targetPoint, shootingDataInfo);
|
|
}
|
|
|
|
enableActiveSkill(tag: number, parent: Node)
|
|
{
|
|
var prefab = GameAssets.instance.getActiveSkill(tag);
|
|
if (!prefab) return;
|
|
|
|
var skillData = GameGlobalData.Instance.listActiveSkillData[tag];
|
|
var skillUse = GameGlobalData.Instance.listActiveSkillUses[tag];
|
|
|
|
var data = { useTime: skillUse?.useTime, range: skillData?.Range, dmg: skillData?.DMG };
|
|
|
|
var skill = instantiate(prefab).getComponent(ActiveSkillBase)!;
|
|
if (!skill) return;
|
|
skill.node.parent = parent? parent : LayoutManager.instance.gameplaySpaceLayout;
|
|
skill?.enableActiveSkill(data, parent);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|