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,7 +239,101 @@ 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)
|
||||||
|
{
|
||||||
|
case ConsumableItem consumableItem:
|
||||||
|
EnactConsumableItemEffects(consumableItem);
|
||||||
|
break;
|
||||||
|
case EffectItem effectItem:
|
||||||
|
EnactEffectItemEffects(effectItem);
|
||||||
|
break;
|
||||||
|
case ThrowableItem throwableItem:
|
||||||
|
EnactThrowableItemEffects(throwableItem);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ToSignal(GetTree().CreateTimer(0.3f), "timeout");
|
||||||
|
|
||||||
|
RemoveItemOrSubtractFromItemCount(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DropItem(InventoryItem item)
|
||||||
|
{
|
||||||
|
var droppedScene = GD.Load<PackedScene>("res://src/items/dropped/DroppedItem.tscn");
|
||||||
|
var dropped = droppedScene.Instantiate<DroppedItem>();
|
||||||
|
dropped.Item = item;
|
||||||
|
AddChild(dropped);
|
||||||
|
dropped.Drop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ThrowItem(InventoryItem item)
|
||||||
|
{
|
||||||
|
var thrownScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
||||||
|
var thrown = thrownScene.Instantiate<ThrownItem>();
|
||||||
|
thrown.ItemThatIsThrown = (InventoryItem)item;
|
||||||
|
AddChild(thrown);
|
||||||
|
thrown.Position += new Vector3(0, 1.5f, 0);
|
||||||
|
thrown.Throw(_effectService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDungeonFloor CurrentFloor => Map.CurrentFloor;
|
||||||
|
|
||||||
|
public void EnemyDefeated(Vector3 defeatedLocation, EnemyStatResource resource) => Player.GainExp(resource.ExpFromDefeat * GameRepo.ExpRate);
|
||||||
|
|
||||||
|
private void DropRestorative(Vector3 vector)
|
||||||
|
{
|
||||||
|
var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn");
|
||||||
|
var restorative = restorativeScene.Instantiate<Restorative>();
|
||||||
|
AddChild(restorative);
|
||||||
|
restorative.GlobalPosition = vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UseTeleportPrompt_CloseTeleportPrompt() => GameLogic.Input(new GameLogic.Input.HideAskForTeleport());
|
||||||
|
|
||||||
|
private void UseTeleportPrompt_TeleportToNextFloor()
|
||||||
|
{
|
||||||
|
GameLogic.Input(new GameLogic.Input.FloorExitReached());
|
||||||
|
GameEventDepot.OnDungeonAThemeAreaEntered();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PauseMenu_UnpauseButtonPressed() => GameLogic.Input(new GameLogic.Input.UnpauseGame());
|
||||||
|
|
||||||
|
private void Player_PauseButtonPressed() => GameLogic.Input(new GameLogic.Input.PauseGame());
|
||||||
|
|
||||||
|
private void FloorClearMenu_TransitionCompleted()
|
||||||
|
{
|
||||||
|
GameRepo.Resume();
|
||||||
|
if (Player.EquippedWeapon.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||||
|
Player.Unequip(Player.EquippedWeapon.Value);
|
||||||
|
if (Player.EquippedArmor.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||||
|
Player.Unequip(Player.EquippedArmor.Value);
|
||||||
|
if (Player.EquippedAccessory.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||||
|
Player.Unequip(Player.EquippedAccessory.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FloorClearMenu_GoToNextFloor() => GameLogic.Input(new GameLogic.Input.GoToNextFloor());
|
||||||
|
|
||||||
|
private void FloorClearMenu_SaveAndExit() => GameLogic.Input(new GameLogic.Input.SaveGame());
|
||||||
|
|
||||||
|
private void GameEventDepot_RestorativePickedUp(IHealthPack obj) => Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + (int)obj.RestoreAmount);
|
||||||
|
|
||||||
|
private void SetPauseMode(bool isPaused)
|
||||||
|
{
|
||||||
|
if (GetTree() != null)
|
||||||
|
GetTree().Paused = isPaused;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
if (Player.Stats.CurrentHP == Player.Stats.MaximumHP && consumableItem.RaiseHPAmount > 0)
|
if (Player.Stats.CurrentHP == Player.Stats.MaximumHP && consumableItem.RaiseHPAmount > 0)
|
||||||
Player.RaiseHP(consumableItem.RaiseHPAmount);
|
Player.RaiseHP(consumableItem.RaiseHPAmount);
|
||||||
@@ -255,7 +345,8 @@ public partial class Game : Node3D, IGame
|
|||||||
if (consumableItem.HealVTAmount > 0 && Player.Stats.CurrentVT != Player.Stats.MaximumVT)
|
if (consumableItem.HealVTAmount > 0 && Player.Stats.CurrentVT != Player.Stats.MaximumVT)
|
||||||
Player.HealVT(consumableItem.HealVTAmount);
|
Player.HealVT(consumableItem.HealVTAmount);
|
||||||
}
|
}
|
||||||
if (item is EffectItem effectItem)
|
|
||||||
|
private void EnactEffectItemEffects(EffectItem effectItem)
|
||||||
{
|
{
|
||||||
switch (effectItem.UsableItemTag)
|
switch (effectItem.UsableItemTag)
|
||||||
{
|
{
|
||||||
@@ -294,7 +385,8 @@ public partial class Game : Node3D, IGame
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item is ThrowableItem throwableItem)
|
|
||||||
|
private void EnactThrowableItemEffects(ThrowableItem throwableItem)
|
||||||
{
|
{
|
||||||
switch (throwableItem.ThrowableItemTag)
|
switch (throwableItem.ThrowableItemTag)
|
||||||
{
|
{
|
||||||
@@ -320,120 +412,11 @@ public partial class Game : Node3D, IGame
|
|||||||
Player.HealVT(throwableItem.HealVTAmount);
|
Player.HealVT(throwableItem.HealVTAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
await ToSignal(GetTree().CreateTimer(0.3f), "timeout");
|
private void RemoveItemOrSubtractFromItemCount(InventoryItem item)
|
||||||
|
{
|
||||||
if (item is IStackable stackableItem && stackableItem.Count > 1)
|
if (item is IStackable stackableItem && stackableItem.Count > 1)
|
||||||
stackableItem.SetCount(stackableItem.Count - 1);
|
stackableItem.SetCount(stackableItem.Count - 1);
|
||||||
else
|
else
|
||||||
GameRepo.RemoveItemFromInventory(item);
|
GameRepo.RemoveItemFromInventory(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DropItem(InventoryItem item)
|
|
||||||
{
|
|
||||||
var droppedScene = GD.Load<PackedScene>("res://src/items/dropped/DroppedItem.tscn");
|
|
||||||
var dropped = droppedScene.Instantiate<DroppedItem>();
|
|
||||||
dropped.Item = item;
|
|
||||||
AddChild(dropped);
|
|
||||||
dropped.Drop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ThrowItem(InventoryItem item)
|
|
||||||
{
|
|
||||||
var thrownScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
|
||||||
var thrown = thrownScene.Instantiate<ThrownItem>();
|
|
||||||
thrown.ItemThatIsThrown = (InventoryItem)item;
|
|
||||||
AddChild(thrown);
|
|
||||||
thrown.Position += new Vector3(0, 1.5f, 0);
|
|
||||||
thrown.Throw(_effectService);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IDungeonFloor CurrentFloor => Map.CurrentFloor;
|
|
||||||
|
|
||||||
public void EnemyDefeated(Vector3 defeatedLocation, EnemyStatResource resource)
|
|
||||||
{
|
|
||||||
Player.GainExp(resource.ExpFromDefeat * GameRepo.ExpRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DropRestorative(Vector3 vector)
|
|
||||||
{
|
|
||||||
var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn");
|
|
||||||
var restorative = restorativeScene.Instantiate<Restorative>();
|
|
||||||
AddChild(restorative);
|
|
||||||
restorative.GlobalPosition = vector;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UseTeleportPrompt_CloseTeleportPrompt()
|
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.HideAskForTeleport());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UseTeleportPrompt_TeleportToNextFloor()
|
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.FloorExitReached());
|
|
||||||
GameEventDepot.OnDungeonAThemeAreaEntered();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PauseMenu_UnpauseButtonPressed()
|
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.UnpauseGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Player_PauseButtonPressed()
|
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.PauseGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FloorClearMenu_TransitionCompleted()
|
|
||||||
{
|
|
||||||
GameRepo.Resume();
|
|
||||||
if (Player.EquippedWeapon.Value.ItemTag == ItemTag.BreaksOnChange)
|
|
||||||
Player.Unequip(Player.EquippedWeapon.Value);
|
|
||||||
if (Player.EquippedArmor.Value.ItemTag == ItemTag.BreaksOnChange)
|
|
||||||
Player.Unequip(Player.EquippedArmor.Value);
|
|
||||||
if (Player.EquippedAccessory.Value.ItemTag == ItemTag.BreaksOnChange)
|
|
||||||
Player.Unequip(Player.EquippedAccessory.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FloorClearMenu_GoToNextFloor()
|
|
||||||
{
|
|
||||||
GameLogic.Input(new GameLogic.Input.GoToNextFloor());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FloorClearMenu_SaveAndExit()
|
|
||||||
{
|
|
||||||
// Save
|
|
||||||
GameLogic.Input(new GameLogic.Input.SaveGame());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GameEventDepot_RestorativePickedUp(IHealthPack obj)
|
|
||||||
=> Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + (int)obj.RestoreAmount);
|
|
||||||
|
|
||||||
private void SetPauseMode(bool isPaused)
|
|
||||||
{
|
|
||||||
if (GetTree() != null)
|
|
||||||
GetTree().Paused = isPaused;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user