|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, EventTouch, Node, Quat, math, Camera, sys, Vec3, Label, geometry, ProgressBar, tween, easing, Tween, UIOpacity, game, PhysicsSystem, PhysicsRayResult } from 'cc';
|
|
|
+import { _decorator, EventTouch, Node, Quat, math, Camera, sys, Vec3, Label, geometry, ProgressBar, tween, easing, Tween, UIOpacity} from 'cc';
|
|
|
import { Game } from '../game/Game';
|
|
|
import { BaseExp } from '../core/base/BaseExp';
|
|
|
import { autoBind } from '../extend/AutoBind';
|
|
@@ -12,6 +12,7 @@ import { BulletMagazine } from '../game/BulletMagazine';
|
|
|
import { settingData } from '../data/SettingData';
|
|
|
import i18n from '../core/i18n/runtime-scripts/LanguageData';
|
|
|
import PlatformSystem from '../platform/PlatformSystem';
|
|
|
+import { GameEnums } from '../data/GameEnums';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
const { clamp, toRadian } = math;
|
|
|
|
|
@@ -208,7 +209,8 @@ export class GunfightShootUI extends BaseExp {
|
|
|
}
|
|
|
this.crossHair.active = true;//准心
|
|
|
//步枪没有开镜贴图
|
|
|
- this.scopeOverlay.active = !this.isRifleGun();
|
|
|
+ const isRifle: boolean = this.weaponCategoryGun() == GameEnums.weaponCategory.rifle;
|
|
|
+ this.scopeOverlay.active = !isRifle;
|
|
|
this.gun_name_label.string = gData.name_lang;
|
|
|
const isSnipeGun: boolean = gData.type == 1;
|
|
|
//换弹夹进度条
|
|
@@ -343,19 +345,25 @@ export class GunfightShootUI extends BaseExp {
|
|
|
* 恢复原始视野
|
|
|
*/
|
|
|
private onWheelRelease() {
|
|
|
+ if(Game.I.player.isReloadMagazine)return;
|
|
|
if(!this.zoomValid){
|
|
|
this.isScopeOpen = false;
|
|
|
return
|
|
|
}
|
|
|
- //是步枪直接连续开火
|
|
|
- if(!this.isRifleGun()){
|
|
|
- Game.I.player.shoot();
|
|
|
- this.scheduleOnce(()=>{
|
|
|
- //检查是否在秒内完成放大 已经在update里开镜完成时调用 Game.I.player.shoot();
|
|
|
+ const type:number = this.weaponCategoryGun();
|
|
|
+ switch(type){
|
|
|
+ case GameEnums.weaponCategory.sniper://狙击枪
|
|
|
+ Game.I.player.shoot();
|
|
|
+ this.scheduleOnce(()=>{
|
|
|
+ this.isScopeOpen = false;
|
|
|
+ },0.6)
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.dmr://连狙
|
|
|
+ Game.I.player.shoot();
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.rifle://步枪
|
|
|
this.isScopeOpen = false;
|
|
|
- },0.6)
|
|
|
- }else{
|
|
|
- this.isScopeOpen = false;
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -363,16 +371,24 @@ export class GunfightShootUI extends BaseExp {
|
|
|
* 开始开镜
|
|
|
*/
|
|
|
private openScope() {
|
|
|
- //从枪械数据获取参数
|
|
|
const gData = Game.I.player.pData;
|
|
|
if(!gData)return;
|
|
|
- const isRifle: boolean = this.isRifleGun();
|
|
|
- //是步枪直接连续开火
|
|
|
- if(isRifle){
|
|
|
- Game.I.player.shoot();
|
|
|
+ if(Game.I.player.isReloadMagazine)return;
|
|
|
+ const isRifle: boolean = this.weaponCategoryGun() == GameEnums.weaponCategory.rifle;
|
|
|
+ const type:number = this.weaponCategoryGun();
|
|
|
+ switch(type){
|
|
|
+ case GameEnums.weaponCategory.sniper://狙击枪
|
|
|
+ //这儿已经在onWheelRelease处理过了
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.dmr://连狙
|
|
|
+ //这儿已经在onWheelRelease处理过了
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.rifle://步枪 是步枪直接连续开火
|
|
|
+ Game.I.player.shoot();
|
|
|
+ break
|
|
|
}
|
|
|
this.isZoomingIn = true;
|
|
|
- //将 zoomingSpeed 转换为持续时间(450对应1.2秒)
|
|
|
+ //将zoomingSpeed 转换为持续时间(450对应1.2秒)
|
|
|
this.zoomDuration = 72 / gData.zoomingSpeed;
|
|
|
//使用枪械类型决定视口倍数 步枪使用 rifleZoom 狙击枪使用 scopeZoom
|
|
|
const zoomMultiplier = isRifle ?
|
|
@@ -397,21 +413,20 @@ export class GunfightShootUI extends BaseExp {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 是否是步枪
|
|
|
+ * 判断是否属于某一种枪
|
|
|
*/
|
|
|
- public isRifleGun(){
|
|
|
+ public weaponCategoryGun():number{
|
|
|
const gData:any = Game.I.player.pData;
|
|
|
- if(!gData)return false;
|
|
|
- return gData.id == '100016' || gData.id == '100015';
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 是否连发狙枪
|
|
|
- */
|
|
|
- public isRapidSnipeGun(){
|
|
|
- const gData:any = Game.I.player.pData;
|
|
|
- if(!gData)return false;
|
|
|
- return gData.id == '100014' || gData.id == '100015';
|
|
|
+ if(!gData)return GameEnums.weaponCategory.sniper;
|
|
|
+ if(gData.id == GameEnums.palyerWeaponType.akm
|
|
|
+ ||gData.id == GameEnums.palyerWeaponType.m416){
|
|
|
+ return GameEnums.weaponCategory.rifle;
|
|
|
+ }else if(gData.id == GameEnums.palyerWeaponType.vss
|
|
|
+ ||gData.id == GameEnums.palyerWeaponType.sks){
|
|
|
+ return GameEnums.weaponCategory.dmr;
|
|
|
+ }else {
|
|
|
+ return GameEnums.weaponCategory.sniper;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -494,15 +509,21 @@ export class GunfightShootUI extends BaseExp {
|
|
|
if (btnName === 'pause_btn') { // 暂停页面
|
|
|
uiMgr.show(Constants.popUIs.pauseUI);
|
|
|
}else if (btnName === 'shot_btn') {//射击
|
|
|
- if(this.isRifleGun){
|
|
|
- //模拟按下射击
|
|
|
- this._isScopeOpen = true;
|
|
|
- Game.I.player.shoot();
|
|
|
- this.scheduleOnce(()=>{
|
|
|
- this._isScopeOpen = false;
|
|
|
- },1.5)
|
|
|
- }else{
|
|
|
- Game.I.player.shoot();
|
|
|
+ let type:number = this.weaponCategoryGun();
|
|
|
+ switch(type){
|
|
|
+ case GameEnums.weaponCategory.sniper://狙击枪
|
|
|
+ Game.I.player.shoot();
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.rifle://步枪
|
|
|
+ this._isScopeOpen = true;
|
|
|
+ Game.I.player.shoot();
|
|
|
+ this.scheduleOnce(()=>{
|
|
|
+ this._isScopeOpen = false;
|
|
|
+ },1.5)
|
|
|
+ break
|
|
|
+ case GameEnums.weaponCategory.dmr://连狙
|
|
|
+ Game.I.player.shoot();
|
|
|
+ break
|
|
|
}
|
|
|
}else if (btnName === 'cut_gun_btn') {//切枪
|
|
|
if(userIns.data.guns.length <= 1)return;
|
|
@@ -539,20 +560,19 @@ export class GunfightShootUI extends BaseExp {
|
|
|
* @param deltaTime - 上一帧到当前帧的时间间隔
|
|
|
*/
|
|
|
update(deltaTime: number) {
|
|
|
- if (this.isZoomingIn) {
|
|
|
+ if(this.isZoomingIn) {
|
|
|
const currentFov = Game.I.camera.fov;
|
|
|
if (currentFov > this.targetFov) {
|
|
|
const newFov = currentFov - this.zoomSpeed * deltaTime;
|
|
|
Game.I.camera.fov = Math.max(newFov, this.targetFov);
|
|
|
- } else {
|
|
|
- //检查是否在2秒内完成放大
|
|
|
+ }else {//检查是否在2秒内完成放大
|
|
|
const elapsedTime = (sys.now() - this.zoomStartTime) / 1000;
|
|
|
if (elapsedTime <= 1.5) {
|
|
|
this.zoomValid = true;
|
|
|
}
|
|
|
this.isZoomingIn = false;
|
|
|
}
|
|
|
- } else if (this.isZoomingOut) {
|
|
|
+ }else if(this.isZoomingOut) {
|
|
|
const currentFov = Game.I.camera.fov;
|
|
|
if (currentFov < this.originalFov) {
|
|
|
const newFov = currentFov + this.zoomSpeed * deltaTime;
|