super-hero/assets/cc-game/scripts/game_play/bullet/ShootingBase.ts

136 lines
4.8 KiB
TypeScript
Raw Normal View History

2024-04-19 03:49:41 -07:00
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;
2024-04-22 01:32:16 -07:00
// UmLog.log("shooting => ", JSON.stringify(shootingDataInfo));
2024-04-19 03:49:41 -07:00
var shootingTarget = target as Node;
var startPoint = start.worldPosition;
var targetPoint = shootingTarget?.active ? target.worldPosition : target;
2024-04-22 01:32:16 -07:00
this.speedScale = shootingDataInfo.AtkSpeed;
var cooldown_time = shootingDataInfo.AtkCoolDown;
//conver cooldown time to mili seconds
if (cooldown_time < 100)
cooldown_time *= 1000;
2024-04-19 03:49:41 -07:00
var timeNow = UmUtil.getTime();
2024-04-22 01:32:16 -07:00
if (timeNow < (this.lastShootingTime + cooldown_time))
2024-04-19 03:49:41 -07:00
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):
{
2024-04-22 01:32:16 -07:00
shootingDataInfo.Damage *= 5;
2024-04-19 03:49:41 -07:00
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);
2024-04-22 01:32:16 -07:00
bullet.setDamage(shootingDataInfo.Damage);
2024-04-19 03:49:41 -07:00
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);
}
}