You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
AdLike2048/assets/script/ui/BattleGame/NewMechanism/MechanismBloodBagSchedule.ts

58 lines
2.0 KiB

/**
* 血包加血
*/
import { _decorator, Component } from 'cc';
import { IBloodBagAddHpProperty } from '../../../game/ChapterPlayTypes';
import { MapObstacle, ObstacleType } from '../MapObstacle';
import { SingleBloodBag } from './SingleBloodBag';
const { ccclass, property } = _decorator;
@ccclass('MechanismBloodBagSchedule')
export class MechanismBloodBagSchedule extends Component {
_dt: number = 0
/**血包加血属性 */
bloodBagAddHpInfo: IBloodBagAddHpProperty = null
isStartTime: boolean = false
start() {
}
protected update(dt: number): void {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
if (!this.isStartTime) {
return
}
this._dt += dt * gg.game.CurentBattle.TimeScale;
if (this._dt >= 1) {
this._dt = 0
this.checkBloodBagLaunchTime()
}
}
init(bloodBagAddHpInfo: IBloodBagAddHpProperty) {
this.bloodBagAddHpInfo = bloodBagAddHpInfo
this.isStartTime = true
}
/**检查是否到了释放时间 */
checkBloodBagLaunchTime() {
if (this.bloodBagAddHpInfo && this.bloodBagAddHpInfo.timeArr && this.bloodBagAddHpInfo.timeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.bloodBagAddHpInfo.timeArr[0]) {
this.bloodBagAddHpInfo.timeArr.shift()
this.releaseBloodBag(this.bloodBagAddHpInfo)
}
}
/**释放血包 */
releaseBloodBag(bloodBagAddHpInfo: IBloodBagAddHpProperty) {
//随机释放1-3个血包
let num = Math.floor(Math.random() * 3) + 2
let randomPosArr = gg.game.CurentBattle.Map.getRandomCanPutObstacleMapGrids(num);
for (let i = 0; i < randomPosArr.length; i++) {
let grid = randomPosArr[i];
let comp = grid.getComponent(MapObstacle);
comp.setObstacle(ObstacleType.血包);
comp.node.getComponentInChildren(SingleBloodBag).init(bloodBagAddHpInfo, grid)
grid.isCanPutGrid = false;
}
}
}