полнценая система прогресаа и конца уровне с началом и концом
This commit is contained in:
@@ -83,30 +83,64 @@ func exitWeapon(nextWeapon : int):
|
||||
|
||||
enterWeapon(nextWeapon)
|
||||
|
||||
func enterWeapon(nextWeapon : int):
|
||||
func enterWeapon(nextWeapon):
|
||||
#this function manage the second part of the weapon switching mechanic
|
||||
#in this part, the next weapon is enabled (equiped and set up)
|
||||
|
||||
# --- СВЕРХ-ЗАЩИТА ОТ БАГОВ СЛОВАРЯ (DICTIONARY) ПРИ СМЕНЕ УРОВНЯ ---
|
||||
# Раз движок уверен, что weaponList — это Dictionary, проверяем наличие ключа через .has()
|
||||
var is_valid_weapon = false
|
||||
|
||||
if weaponList != null and weaponList.has(nextWeapon):
|
||||
is_valid_weapon = true
|
||||
|
||||
# Если оружие еще не готово или ключ '0' отсутствует в словаре на новом уровне:
|
||||
if not is_valid_weapon:
|
||||
print("[ОРУЖИЕ] Предупреждение: Ключ ", nextWeapon, " еще не инициализирован в словарe weaponList. Ждем...")
|
||||
# Даем ассету один кадр очухаться и наполнить свои словари пушками
|
||||
await get_tree().process_frame
|
||||
|
||||
# Повторная проверка
|
||||
if weaponList != null and weaponList.has(nextWeapon):
|
||||
is_valid_weapon = true
|
||||
|
||||
# Если всё еще пусто — аварийно выходим, чтобы спасти игру от вылета
|
||||
if not is_valid_weapon:
|
||||
print("[ОРУЖИЕ] КРИТИЧЕСКИЙ СБОЙ: Оружие полностью утеряно при генерации сцены!")
|
||||
canUseWeapon = true
|
||||
canChangeWeapons = true
|
||||
return
|
||||
|
||||
cW = weaponList[nextWeapon]
|
||||
nextWeapon = 0
|
||||
cWModel = cW.weaponSlot.model
|
||||
cWModel.visible = true
|
||||
|
||||
shootManager.getCurrentWeapon(cW)
|
||||
reloadManager.getCurrentWeapon(cW)
|
||||
animManager.getCurrentWeapon(cW, cWModel)
|
||||
# Проверяем наличие модели оружия перед включением видимости
|
||||
if cW and cW.weaponSlot and "model" in cW.weaponSlot:
|
||||
cWModel = cW.weaponSlot.model
|
||||
if cWModel:
|
||||
cWModel.visible = true
|
||||
|
||||
weaponSoundManagement(cW.equipSound, cW.equipSoundSpeed)
|
||||
# Передаем обновленное оружие в менеджеры, если они существуют
|
||||
if shootManager: shootManager.getCurrentWeapon(cW)
|
||||
if reloadManager: reloadManager.getCurrentWeapon(cW)
|
||||
if animManager: animManager.getCurrentWeapon(cW, cWModel)
|
||||
|
||||
animPlayer.playback_default_blend_time = cW.animBlendTime
|
||||
|
||||
if cW.equipAnimName != "":
|
||||
animManager.playAnimation("EquipAnim%s" % cW.weaponName, cW.equipAnimSpeed, false)
|
||||
await get_tree().create_timer(cW.equipTime).timeout
|
||||
|
||||
if cW.isShooting: cW.isShooting = false
|
||||
if cW.isReloading: cW.isReloading = false
|
||||
if cW:
|
||||
weaponSoundManagement(cW.equipSound, cW.equipSoundSpeed)
|
||||
if animPlayer:
|
||||
animPlayer.playback_default_blend_time = cW.animBlendTime
|
||||
|
||||
if cW.equipAnimName != "" and animManager:
|
||||
animManager.playAnimation("EquipAnim%s" % cW.weaponName, cW.equipAnimSpeed, false)
|
||||
|
||||
await get_tree().create_timer(cW.equipTime).timeout
|
||||
|
||||
if cW.isShooting: cW.isShooting = false
|
||||
if cW.isReloading: cW.isReloading = false
|
||||
|
||||
canUseWeapon = true
|
||||
canChangeWeapons = true
|
||||
|
||||
|
||||
|
||||
func _process(_delta : float):
|
||||
if cW != null and cWModel != null and canUseWeapon:
|
||||
@@ -132,11 +166,31 @@ func weaponInputs():
|
||||
changeWeapon(weaponStack[weaponIndex])
|
||||
|
||||
func displayStats():
|
||||
if hud == null or cW == null:
|
||||
return
|
||||
|
||||
hud.displayWeaponStack(weaponStack.size())
|
||||
hud.displayWeaponName(cW.weaponName)
|
||||
hud.displayTotalAmmoInMag(cW.totalAmmoInMag, cW.nbProjShotsAtSameTime)
|
||||
hud.displayTotalAmmo(ammoManager.ammoDict[cW.ammoType], cW.nbProjShotsAtSameTime)
|
||||
|
||||
# --- БРОНЕБОЙНАЯ ЗАЩИТА ОТ ВЫЛЕТА ИЗ-ЗА ПАТРОНОВ ПРИ СМЕНЕ СЦЕНЫ ---
|
||||
# Используем метод .get() вместо квадратных скобок [...].
|
||||
# Он никогда не уронит игру, даже если словарь ammoDict полностью пустой!
|
||||
var total_ammo : int = 0
|
||||
if ammoManager != null and ammoManager.ammoDict != null:
|
||||
total_ammo = ammoManager.ammoDict.get(cW.ammoType, 0)
|
||||
|
||||
hud.displayTotalAmmo(total_ammo, cW.nbProjShotsAtSameTime)
|
||||
|
||||
|
||||
# --- БРОНЕБОЙНАЯ ЗАЩИТА ОТ ВЫЛЕТА ПРИ ПЕРЕХОДЕ НА НОВЫЙ УРОВЕНЬ ---
|
||||
# Проверяем, существует ли ammoManager и есть ли тип патронов текущего оружия в словаре
|
||||
if ammoManager != null and ammoManager.ammoDict != null and ammoManager.ammoDict.has(cW.ammoType):
|
||||
hud.displayTotalAmmo(ammoManager.ammoDict[cW.ammoType], cW.nbProjShotsAtSameTime)
|
||||
else:
|
||||
# Если словарь еще не загрузился, временно пишем 0, чтобы игра не вылетала
|
||||
hud.displayTotalAmmo(0, cW.nbProjShotsAtSameTime)
|
||||
|
||||
func changeWeapon(nextWeapon : int):
|
||||
if canChangeWeapons and !cW.isShooting and !cW.isReloading:
|
||||
exitWeapon(nextWeapon)
|
||||
|
||||
Reference in New Issue
Block a user