Major Player refactor
This commit is contained in:
@@ -3,7 +3,6 @@ namespace GameJamDungeon;
|
||||
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon.src.item_rescue;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
@@ -16,6 +15,8 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
IGame IProvide<IGame>.Value() => this;
|
||||
|
||||
IPlayer IProvide<IPlayer>.Value() => Player;
|
||||
|
||||
IGameEventDepot IProvide<IGameEventDepot>.Value() => GameEventDepot;
|
||||
|
||||
public IInstantiator Instantiator { get; set; } = default!;
|
||||
@@ -61,6 +62,7 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Set(GameRepo);
|
||||
GameLogic.Set(AppRepo);
|
||||
GameLogic.Set(GameEventDepot);
|
||||
GameLogic.Set(Player);
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
RescuedItems = new RescuedItemDatabase();
|
||||
}
|
||||
@@ -117,29 +119,27 @@ public partial class Game : Node3D, IGame
|
||||
InGameUI.UseTeleportPrompt.TeleportToNextFloor += UseTeleportPrompt_TeleportToNextFloor;
|
||||
InGameUI.UseTeleportPrompt.CloseTeleportPrompt += UseTeleportPrompt_CloseTeleportPrompt;
|
||||
|
||||
GameRepo.PlayerData.Inventory.InventoryAtCapacity += PlayerInventory_InventoryAtCapacity;
|
||||
GameRepo.PlayerData.Inventory.PickedUpItem += Inventory_PickedUpItem;
|
||||
GameRepo.PlayerData.Inventory.RaiseStatRequest += Inventory_RaiseStatRequest;
|
||||
Player.Inventory.InventoryAtCapacity += PlayerInventory_InventoryAtCapacity;
|
||||
Player.Inventory.PickedUpItem += Inventory_PickedUpItem;
|
||||
Player.Inventory.RaiseStatRequest += Inventory_RaiseStatRequest;
|
||||
FloorClearMenu.GoToNextFloor += FloorClearMenu_GoToNextFloor;
|
||||
FloorClearMenu.SaveAndExit += FloorClearMenu_SaveAndExit;
|
||||
FloorClearMenu.TransitionCompleted += FloorClearMenu_TransitionCompleted;
|
||||
|
||||
Player.InventoryButtonPressed += Player_InventoryButtonPressed;
|
||||
Player.MinimapButtonHeld += Player_MinimapButtonHeld;
|
||||
Player.PauseButtonPressed += Player_PauseButtonPressed;
|
||||
|
||||
GameRepo.PlayerData.CurrentHP.Sync += CurrentHP_Sync;
|
||||
|
||||
GameEventDepot.EnemyDefeated += OnEnemyDefeated;
|
||||
GameEventDepot.RestorativePickedUp += GameEventDepot_RestorativePickedUp;
|
||||
|
||||
DoubleEXPTimer.Timeout += DoubleEXPTimer_Timeout;
|
||||
}
|
||||
|
||||
private void CurrentHP_Sync(int currentHP)
|
||||
public void ToggleInventory()
|
||||
{
|
||||
if (currentHP <= 0)
|
||||
GameLogic.Input(new GameLogic.Input.GameOver());
|
||||
GameLogic.Input(new GameLogic.Input.OpenInventory());
|
||||
}
|
||||
|
||||
public void ToggleMinimap()
|
||||
{
|
||||
GameLogic.Input(new GameLogic.Input.MiniMapButtonPressed());
|
||||
}
|
||||
|
||||
private void Inventory_PickedUpItem(string pickedUpItemName)
|
||||
@@ -160,14 +160,14 @@ public partial class Game : Node3D, IGame
|
||||
{
|
||||
var thrownScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
||||
var thrown = thrownScene.Instantiate<ThrownItem>();
|
||||
thrown.ThrownItemStats = item.Info;
|
||||
thrown.ItemThatIsThrown = item;
|
||||
AddChild(thrown);
|
||||
thrown.Throw();
|
||||
}
|
||||
|
||||
private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource)
|
||||
{
|
||||
GameRepo.PlayerData.SetCurrentExp(GameRepo.PlayerData.CurrentExp.Value + (resource.ExpFromDefeat * GameRepo.EXPRate));
|
||||
Player.GainExp(resource.ExpFromDefeat * GameRepo.EXPRate);
|
||||
DropRestorative(vector);
|
||||
}
|
||||
|
||||
@@ -205,21 +205,11 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Input(new GameLogic.Input.MiniMapButtonReleased());
|
||||
}
|
||||
|
||||
private void Player_MinimapButtonHeld()
|
||||
{
|
||||
GameLogic.Input(new GameLogic.Input.MiniMapButtonPressed());
|
||||
}
|
||||
|
||||
private void Player_InventoryButtonPressed()
|
||||
{
|
||||
GameLogic.Input(new GameLogic.Input.OpenInventory());
|
||||
}
|
||||
|
||||
private void FloorClearMenu_TransitionCompleted()
|
||||
{
|
||||
GameRepo.Resume();
|
||||
if (GameRepo.PlayerData.Inventory.EquippedWeapon.Value.WeaponStats.WeaponTags.Contains(WeaponTag.BreaksOnChange))
|
||||
GameRepo.PlayerData.Inventory.Unequip(GameRepo.PlayerData.Inventory.EquippedWeapon.Value);
|
||||
if (Player.Inventory.EquippedWeapon.Value.WeaponTags.Contains(WeaponTag.BreaksOnChange))
|
||||
Player.Inventory.Unequip(Player.Inventory.EquippedWeapon.Value);
|
||||
}
|
||||
|
||||
private void FloorClearMenu_GoToNextFloor()
|
||||
@@ -235,7 +225,7 @@ public partial class Game : Node3D, IGame
|
||||
}
|
||||
|
||||
private void GameEventDepot_RestorativePickedUp(Restorative obj)
|
||||
=> GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.CurrentVT.Value + obj.VTRestoreAmount);
|
||||
=> Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + obj.VTRestoreAmount);
|
||||
|
||||
private void Inventory_RaiseStatRequest(InventoryItemStats itemStats)
|
||||
{
|
||||
@@ -251,34 +241,34 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
public void RaiseHP(int amountToRaise)
|
||||
{
|
||||
if (GameRepo.PlayerData.CurrentHP.Value == GameRepo.PlayerData.MaximumHP.Value)
|
||||
if (Player.Stats.CurrentHP.Value == Player.Stats.MaximumHP.Value)
|
||||
{
|
||||
GameRepo.PlayerData.SetMaximumHP(GameRepo.PlayerData.MaximumHP.Value + amountToRaise);
|
||||
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.MaximumHP.Value);
|
||||
Player.Stats.SetMaximumHP(Player.Stats.MaximumHP.Value + amountToRaise);
|
||||
Player.Stats.SetCurrentHP(Player.Stats.MaximumHP.Value);
|
||||
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise}MAXHP Up.");
|
||||
}
|
||||
}
|
||||
|
||||
public void HealHP(int amountToRestore)
|
||||
{
|
||||
GameRepo.PlayerData.SetCurrentHP(GameRepo.PlayerData.CurrentHP.Value + amountToRestore);
|
||||
Player.Stats.SetCurrentHP(Player.Stats.CurrentHP.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
EmitSignal(SignalName.StatRaisedAlert, $"{raiseString}HP Restored.");
|
||||
}
|
||||
|
||||
public void RaiseVT(int amountToRaise)
|
||||
{
|
||||
if (GameRepo.PlayerData.CurrentVT.Value == GameRepo.PlayerData.MaximumVT.Value)
|
||||
if (Player.Stats.CurrentVT.Value == Player.Stats.MaximumVT.Value)
|
||||
{
|
||||
GameRepo.PlayerData.SetMaximumVT(GameRepo.PlayerData.MaximumVT.Value + amountToRaise);
|
||||
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.MaximumVT.Value);
|
||||
Player.Stats.SetMaximumVT(Player.Stats.MaximumVT.Value + amountToRaise);
|
||||
Player.Stats.SetCurrentVT(Player.Stats.MaximumVT.Value);
|
||||
EmitSignal(SignalName.StatRaisedAlert, $"{amountToRaise}MAXVT Up.");
|
||||
}
|
||||
}
|
||||
|
||||
public void HealVT(int amountToRestore)
|
||||
{
|
||||
GameRepo.PlayerData.SetCurrentVT(GameRepo.PlayerData.CurrentVT.Value + amountToRestore);
|
||||
Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
EmitSignal(SignalName.StatRaisedAlert, $"{raiseString}VT Restored.");
|
||||
}
|
||||
@@ -309,7 +299,7 @@ public partial class Game : Node3D, IGame
|
||||
{
|
||||
var transform = Map.GetPlayerSpawnPosition();
|
||||
GameRepo.SetPlayerGlobalTransform(transform);
|
||||
GameRepo.SetPlayerGlobalPosition(new Vector3(transform.Origin.X, -2, transform.Origin.Z));
|
||||
Player.TeleportPlayer(new Vector3(transform.Origin.X, -1.75f, transform.Origin.Z));
|
||||
GameLogic.Input(new GameLogic.Input.HideFloorClearMenu());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user