cirnogodot/Scripts/Activables/LevelTeleporter.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2025-02-21 22:48:12 +01:00
using System;
using System.Collections;
using System.Threading.Tasks;
2025-03-02 11:58:30 +01:00
using Cirno.Scripts.Components.FSM;
2025-04-30 15:09:59 +02:00
using Cirno.Scripts.Enums;
2025-04-02 17:42:55 +02:00
using Cirno.Scripts.Resources;
2025-02-21 22:48:12 +01:00
using Godot;
namespace Cirno.Scripts.Activables;
2025-03-24 16:56:35 +01:00
public partial class LevelTeleporter : Teleporter
2025-02-21 22:48:12 +01:00
{
2025-04-30 15:09:59 +02:00
[Export] public string LevelPath { get; set; }
2025-09-10 16:16:05 +02:00
[Export] public MapResource Map { get; private set; }
2025-03-24 16:56:35 +01:00
2025-05-01 17:07:55 +02:00
[Export] public bool SaveInventory { get; set; }
2025-02-21 22:48:12 +01:00
2025-03-05 10:55:14 +01:00
protected override async Task Teleport(IStateMachine<PlayerState, CharacterBody2D> player)
2025-02-21 22:48:12 +01:00
{
2025-04-02 17:42:55 +02:00
if (string.IsNullOrWhiteSpace(LevelPath) && Map is null) return;
2025-03-02 11:58:30 +01:00
//player.RequestMovementDisable(true);
2025-03-05 10:55:14 +01:00
player.SetState(PlayerState.Cutscene);
2025-02-21 22:48:12 +01:00
2025-03-05 10:55:14 +01:00
await TweenPlayer(player.MainObject);
2025-02-21 22:48:12 +01:00
_particles.Emitting = true;
2025-03-24 16:56:35 +01:00
2025-03-02 11:58:30 +01:00
//await player.Teleport();
2025-03-24 22:22:07 +01:00
player.SetState(PlayerState.Teleporting);
2025-03-02 11:58:30 +01:00
await Task.Delay((int)(0.6f * 1000));
2025-02-22 14:45:46 +01:00
2025-02-21 22:48:12 +01:00
await Task.Delay((int)(TeleportAnimationLength * 1000));
2025-03-24 16:56:35 +01:00
if (SaveInventory)
{
// Save inventory
GlobalState.Instance.SessionSettings.Items = InventoryManager.Instance.Save();
}
2025-05-02 16:20:54 +02:00
else
{
GlobalState.Instance.SessionSettings.EquippedWeaponId = string.Empty;
}
2025-03-24 16:56:35 +01:00
2025-04-02 17:42:55 +02:00
if (!string.IsNullOrWhiteSpace(LevelPath))
{
2025-04-30 15:09:59 +02:00
if (GlobalState.Instance.SessionSettings.GameMode is GameMode.Roguelite)
{
GlobalState.Instance.SessionSettings.LevelNumber += 1;
}
2025-09-10 16:16:05 +02:00
2025-04-02 17:42:55 +02:00
GlobalState.Instance.GotoScene(LevelPath);
}
else
{
GlobalState.Instance.GotoScene(Map);
}
2025-02-21 22:48:12 +01:00
}
}