Clean up Game.cs
This commit is contained in:
@@ -221,11 +221,7 @@ public partial class Game : Node3D, IGame
|
|||||||
_effectService = new EffectService(this, Player, Map);
|
_effectService = new EffectService(this, Player, Map);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadExistingGame()
|
public void LoadExistingGame() => SaveFile.Load().ContinueWith((_) => CallDeferred(nameof(FinishedLoadingSaveFile)));
|
||||||
{
|
|
||||||
SaveFile.Load()
|
|
||||||
.ContinueWith((_) => CallDeferred(nameof(FinishedLoadingSaveFile)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void TogglePause()
|
public void TogglePause()
|
||||||
{
|
{
|
||||||
@@ -243,89 +239,22 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
public async Task UseItem(InventoryItem item)
|
public async Task UseItem(InventoryItem item)
|
||||||
{
|
{
|
||||||
if (item is ConsumableItem consumableItem)
|
switch (item)
|
||||||
{
|
{
|
||||||
if (Player.Stats.CurrentHP == Player.Stats.MaximumHP && consumableItem.RaiseHPAmount > 0)
|
case ConsumableItem consumableItem:
|
||||||
Player.RaiseHP(consumableItem.RaiseHPAmount);
|
EnactConsumableItemEffects(consumableItem);
|
||||||
if (Player.Stats.CurrentVT == Player.Stats.MaximumVT && consumableItem.RaiseVTAmount > 0)
|
break;
|
||||||
Player.RaiseVT(consumableItem.RaiseVTAmount);
|
case EffectItem effectItem:
|
||||||
|
EnactEffectItemEffects(effectItem);
|
||||||
if (consumableItem.HealHPAmount > 0 && Player.Stats.CurrentHP != Player.Stats.MaximumHP)
|
break;
|
||||||
Player.HealHP(consumableItem.HealHPAmount);
|
case ThrowableItem throwableItem:
|
||||||
if (consumableItem.HealVTAmount > 0 && Player.Stats.CurrentVT != Player.Stats.MaximumVT)
|
EnactThrowableItemEffects(throwableItem);
|
||||||
Player.HealVT(consumableItem.HealVTAmount);
|
break;
|
||||||
}
|
|
||||||
if (item is EffectItem effectItem)
|
|
||||||
{
|
|
||||||
switch (effectItem.UsableItemTag)
|
|
||||||
{
|
|
||||||
case UsableItemTag.TeleportAllEnemiesToRoom:
|
|
||||||
_effectService.TeleportEnemiesToCurrentRoom();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.KillHalfEnemiesInRoom:
|
|
||||||
_effectService.KillHalfEnemiesInRoom();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.TurnAllEnemiesIntoHealingItem:
|
|
||||||
_effectService.TurnAllEnemiesInRoomIntoHealingItem();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.HealsAllInRoomToMaxHP:
|
|
||||||
_effectService.HealAllEnemiesAndPlayerInRoomToFull();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.AbsorbHPFromAllEnemiesInRoom:
|
|
||||||
_effectService.AbsorbHPFromAllEnemiesInRoom();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.DealElementalDamageToAllEnemiesInRoom:
|
|
||||||
_effectService.DealElementalDamageToAllEnemiesInRoom(ElementType.Hydric);
|
|
||||||
break;
|
|
||||||
case UsableItemTag.SwapHPAndVT:
|
|
||||||
_effectService.SwapHPandVT();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.RaiseCurrentWeaponAttack:
|
|
||||||
_effectService.RaiseCurrentWeaponAttack();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.RaiseCurrentDefenseArmor:
|
|
||||||
_effectService.RaiseCurrentArmorDefense();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.RaiseLevel:
|
|
||||||
_effectService.RaiseLevel();
|
|
||||||
break;
|
|
||||||
case UsableItemTag.RandomEffect:
|
|
||||||
_effectService.RandomEffect(effectItem);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item is ThrowableItem throwableItem)
|
|
||||||
{
|
|
||||||
switch (throwableItem.ThrowableItemTag)
|
|
||||||
{
|
|
||||||
case ThrowableItemTag.DoubleExp:
|
|
||||||
GameRepo.StartDoubleEXP(TimeSpan.FromSeconds(30));
|
|
||||||
break;
|
|
||||||
case ThrowableItemTag.TeleportToRandomLocation:
|
|
||||||
_effectService.TeleportToRandomRoom(Player);
|
|
||||||
InGameUI.CloseInventory();
|
|
||||||
break;
|
|
||||||
case ThrowableItemTag.CanChangeAffinity:
|
|
||||||
_effectService.ChangeAffinity(throwableItem);
|
|
||||||
break;
|
|
||||||
case ThrowableItemTag.WarpToExitIfFound:
|
|
||||||
_effectService.WarpToExit(Player);
|
|
||||||
InGameUI.CloseInventory();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (throwableItem.HealHPAmount > 0)
|
|
||||||
Player.HealHP(throwableItem.HealHPAmount);
|
|
||||||
if (throwableItem.HealVTAmount > 0)
|
|
||||||
Player.HealVT(throwableItem.HealVTAmount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await ToSignal(GetTree().CreateTimer(0.3f), "timeout");
|
await ToSignal(GetTree().CreateTimer(0.3f), "timeout");
|
||||||
|
|
||||||
if (item is IStackable stackableItem && stackableItem.Count > 1)
|
RemoveItemOrSubtractFromItemCount(item);
|
||||||
stackableItem.SetCount(stackableItem.Count - 1);
|
|
||||||
else
|
|
||||||
GameRepo.RemoveItemFromInventory(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DropItem(InventoryItem item)
|
public void DropItem(InventoryItem item)
|
||||||
@@ -349,10 +278,7 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
public IDungeonFloor CurrentFloor => Map.CurrentFloor;
|
public IDungeonFloor CurrentFloor => Map.CurrentFloor;
|
||||||
|
|
||||||
public void EnemyDefeated(Vector3 defeatedLocation, EnemyStatResource resource)
|
public void EnemyDefeated(Vector3 defeatedLocation, EnemyStatResource resource) => Player.GainExp(resource.ExpFromDefeat * GameRepo.ExpRate);
|
||||||
{
|
|
||||||
Player.GainExp(resource.ExpFromDefeat * GameRepo.ExpRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DropRestorative(Vector3 vector)
|
private void DropRestorative(Vector3 vector)
|
||||||
{
|
{
|
||||||
@@ -362,10 +288,7 @@ public partial class Game : Node3D, IGame
|
|||||||
restorative.GlobalPosition = vector;
|
restorative.GlobalPosition = vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UseTeleportPrompt_CloseTeleportPrompt()
|
private void UseTeleportPrompt_CloseTeleportPrompt() => GameLogic.Input(new GameLogic.Input.HideAskForTeleport());
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.HideAskForTeleport());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UseTeleportPrompt_TeleportToNextFloor()
|
private void UseTeleportPrompt_TeleportToNextFloor()
|
||||||
{
|
{
|
||||||
@@ -373,15 +296,9 @@ public partial class Game : Node3D, IGame
|
|||||||
GameEventDepot.OnDungeonAThemeAreaEntered();
|
GameEventDepot.OnDungeonAThemeAreaEntered();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PauseMenu_UnpauseButtonPressed()
|
private void PauseMenu_UnpauseButtonPressed() => GameLogic.Input(new GameLogic.Input.UnpauseGame());
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.UnpauseGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Player_PauseButtonPressed()
|
private void Player_PauseButtonPressed() => GameLogic.Input(new GameLogic.Input.PauseGame());
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.PauseGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FloorClearMenu_TransitionCompleted()
|
private void FloorClearMenu_TransitionCompleted()
|
||||||
{
|
{
|
||||||
@@ -394,19 +311,11 @@ public partial class Game : Node3D, IGame
|
|||||||
Player.Unequip(Player.EquippedAccessory.Value);
|
Player.Unequip(Player.EquippedAccessory.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FloorClearMenu_GoToNextFloor()
|
private void FloorClearMenu_GoToNextFloor() => GameLogic.Input(new GameLogic.Input.GoToNextFloor());
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.GoToNextFloor());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FloorClearMenu_SaveAndExit()
|
private void FloorClearMenu_SaveAndExit() => GameLogic.Input(new GameLogic.Input.SaveGame());
|
||||||
{
|
|
||||||
// Save
|
|
||||||
GameLogic.Input(new GameLogic.Input.SaveGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GameEventDepot_RestorativePickedUp(IHealthPack obj)
|
private void GameEventDepot_RestorativePickedUp(IHealthPack obj) => Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + (int)obj.RestoreAmount);
|
||||||
=> Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + (int)obj.RestoreAmount);
|
|
||||||
|
|
||||||
private void SetPauseMode(bool isPaused)
|
private void SetPauseMode(bool isPaused)
|
||||||
{
|
{
|
||||||
@@ -414,26 +323,100 @@ public partial class Game : Node3D, IGame
|
|||||||
GetTree().Paused = isPaused;
|
GetTree().Paused = isPaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoubleEXPTimer_Timeout()
|
private void DoubleEXPTimer_Timeout() => GameRepo.EndDoubleExp();
|
||||||
|
|
||||||
|
public void NextFloorLoaded() => GameLogic.Input(new GameLogic.Input.HideFloorClearMenu());
|
||||||
|
|
||||||
|
private void OnPauseMenuTransitioned() => GameLogic.Input(new GameLogic.Input.PauseMenuTransitioned());
|
||||||
|
|
||||||
|
public void OnStart() => GameLogic.Input(new GameLogic.Input.StartGame());
|
||||||
|
|
||||||
|
private void FinishedLoadingSaveFile() => EmitSignal(SignalName.SaveFileLoaded);
|
||||||
|
|
||||||
|
private void EnactConsumableItemEffects(ConsumableItem consumableItem)
|
||||||
{
|
{
|
||||||
GameRepo.EndDoubleExp();
|
if (Player.Stats.CurrentHP == Player.Stats.MaximumHP && consumableItem.RaiseHPAmount > 0)
|
||||||
|
Player.RaiseHP(consumableItem.RaiseHPAmount);
|
||||||
|
if (Player.Stats.CurrentVT == Player.Stats.MaximumVT && consumableItem.RaiseVTAmount > 0)
|
||||||
|
Player.RaiseVT(consumableItem.RaiseVTAmount);
|
||||||
|
|
||||||
|
if (consumableItem.HealHPAmount > 0 && Player.Stats.CurrentHP != Player.Stats.MaximumHP)
|
||||||
|
Player.HealHP(consumableItem.HealHPAmount);
|
||||||
|
if (consumableItem.HealVTAmount > 0 && Player.Stats.CurrentVT != Player.Stats.MaximumVT)
|
||||||
|
Player.HealVT(consumableItem.HealVTAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NextFloorLoaded()
|
private void EnactEffectItemEffects(EffectItem effectItem)
|
||||||
{
|
{
|
||||||
GameLogic.Input(new GameLogic.Input.HideFloorClearMenu());
|
switch (effectItem.UsableItemTag)
|
||||||
|
{
|
||||||
|
case UsableItemTag.TeleportAllEnemiesToRoom:
|
||||||
|
_effectService.TeleportEnemiesToCurrentRoom();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.KillHalfEnemiesInRoom:
|
||||||
|
_effectService.KillHalfEnemiesInRoom();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.TurnAllEnemiesIntoHealingItem:
|
||||||
|
_effectService.TurnAllEnemiesInRoomIntoHealingItem();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.HealsAllInRoomToMaxHP:
|
||||||
|
_effectService.HealAllEnemiesAndPlayerInRoomToFull();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.AbsorbHPFromAllEnemiesInRoom:
|
||||||
|
_effectService.AbsorbHPFromAllEnemiesInRoom();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.DealElementalDamageToAllEnemiesInRoom:
|
||||||
|
_effectService.DealElementalDamageToAllEnemiesInRoom(ElementType.Hydric);
|
||||||
|
break;
|
||||||
|
case UsableItemTag.SwapHPAndVT:
|
||||||
|
_effectService.SwapHPandVT();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.RaiseCurrentWeaponAttack:
|
||||||
|
_effectService.RaiseCurrentWeaponAttack();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.RaiseCurrentDefenseArmor:
|
||||||
|
_effectService.RaiseCurrentArmorDefense();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.RaiseLevel:
|
||||||
|
_effectService.RaiseLevel();
|
||||||
|
break;
|
||||||
|
case UsableItemTag.RandomEffect:
|
||||||
|
_effectService.RandomEffect(effectItem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPauseMenuTransitioned()
|
private void EnactThrowableItemEffects(ThrowableItem throwableItem)
|
||||||
{
|
{
|
||||||
GameLogic.Input(new GameLogic.Input.PauseMenuTransitioned());
|
switch (throwableItem.ThrowableItemTag)
|
||||||
|
{
|
||||||
|
case ThrowableItemTag.DoubleExp:
|
||||||
|
GameRepo.StartDoubleEXP(TimeSpan.FromSeconds(30));
|
||||||
|
break;
|
||||||
|
case ThrowableItemTag.TeleportToRandomLocation:
|
||||||
|
_effectService.TeleportToRandomRoom(Player);
|
||||||
|
InGameUI.CloseInventory();
|
||||||
|
break;
|
||||||
|
case ThrowableItemTag.CanChangeAffinity:
|
||||||
|
_effectService.ChangeAffinity(throwableItem);
|
||||||
|
break;
|
||||||
|
case ThrowableItemTag.WarpToExitIfFound:
|
||||||
|
_effectService.WarpToExit(Player);
|
||||||
|
InGameUI.CloseInventory();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (throwableItem.HealHPAmount > 0)
|
||||||
|
Player.HealHP(throwableItem.HealHPAmount);
|
||||||
|
if (throwableItem.HealVTAmount > 0)
|
||||||
|
Player.HealVT(throwableItem.HealVTAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnStart() =>
|
private void RemoveItemOrSubtractFromItemCount(InventoryItem item)
|
||||||
GameLogic.Input(new GameLogic.Input.StartGame());
|
|
||||||
|
|
||||||
private void FinishedLoadingSaveFile()
|
|
||||||
{
|
{
|
||||||
EmitSignal(SignalName.SaveFileLoaded);
|
if (item is IStackable stackableItem && stackableItem.Count > 1)
|
||||||
|
stackableItem.SetCount(stackableItem.Count - 1);
|
||||||
|
else
|
||||||
|
GameRepo.RemoveItemFromInventory(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user