Implementation of saving inventory items (had to resturcture texture loading)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace GameJamDungeon;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public enum ElementType
|
||||
{
|
||||
@@ -9,3 +11,6 @@ public enum ElementType
|
||||
Igneous,
|
||||
Ferrum
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(ElementType))]
|
||||
public partial class ElementTypeEnumContext : JsonSerializerContext;
|
||||
|
||||
+118
-26
@@ -7,11 +7,12 @@ using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Chickensoft.Serialization;
|
||||
using Chickensoft.Serialization.Godot;
|
||||
using GameJamDungeon.src.items;
|
||||
using Godot;
|
||||
using Org.BouncyCastle.Asn1.Pkcs;
|
||||
using System;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using static GameJamDungeon.GameLogic.State;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
@@ -78,6 +79,8 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
public RescuedItemDatabase RescuedItems { get; set; } = default!;
|
||||
|
||||
private EffectService _effectService;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
FileSystem = new FileSystem();
|
||||
@@ -96,6 +99,7 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
var resolver = new SerializableTypeResolver();
|
||||
GodotSerialization.Setup();
|
||||
Serializer.AddConverter(new Texture2DConverter());
|
||||
|
||||
var upgradeDependencies = new Blackboard();
|
||||
|
||||
@@ -104,7 +108,7 @@ public partial class Game : Node3D, IGame
|
||||
Converters = {
|
||||
new SerializableTypeConverter(upgradeDependencies)
|
||||
},
|
||||
TypeInfoResolver = resolver,
|
||||
TypeInfoResolver = JsonTypeInfoResolver.Combine(resolver, WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, ThrowableItemTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default),
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
@@ -113,23 +117,27 @@ public partial class Game : Node3D, IGame
|
||||
{
|
||||
var gameData = new GameData()
|
||||
{
|
||||
PlayerData = new PlayerStats
|
||||
PlayerData = new PlayerData()
|
||||
{
|
||||
CurrentHP = Player.Stats.CurrentHP.Value,
|
||||
MaximumHP = Player.Stats.MaximumHP.Value,
|
||||
CurrentVT = Player.Stats.CurrentVT.Value,
|
||||
MaximumVT = Player.Stats.MaximumVT.Value,
|
||||
CurrentAttack = Player.Stats.CurrentAttack.Value,
|
||||
BonusAttack = Player.Stats.BonusAttack.Value,
|
||||
MaxAttack = Player.Stats.MaxAttack.Value,
|
||||
CurrentDefense = Player.Stats.CurrentDefense.Value,
|
||||
BonusDefense = Player.Stats.BonusDefense.Value,
|
||||
MaxDefense = Player.Stats.MaxDefense.Value,
|
||||
CurrentExp = Player.Stats.CurrentExp.Value,
|
||||
CurrentLevel = Player.Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Player.Stats.ExpToNextLevel.Value,
|
||||
Luck = Player.Stats.Luck.Value
|
||||
},
|
||||
PlayerStats = new PlayerStats()
|
||||
{
|
||||
CurrentHP = Player.Stats.CurrentHP.Value,
|
||||
MaximumHP = Player.Stats.MaximumHP.Value,
|
||||
CurrentVT = Player.Stats.CurrentVT.Value,
|
||||
MaximumVT = Player.Stats.MaximumVT.Value,
|
||||
CurrentAttack = Player.Stats.CurrentAttack.Value,
|
||||
BonusAttack = Player.Stats.BonusAttack.Value,
|
||||
MaxAttack = Player.Stats.MaxAttack.Value,
|
||||
CurrentDefense = Player.Stats.CurrentDefense.Value,
|
||||
BonusDefense = Player.Stats.BonusDefense.Value,
|
||||
MaxDefense = Player.Stats.MaxDefense.Value,
|
||||
CurrentExp = Player.Stats.CurrentExp.Value,
|
||||
CurrentLevel = Player.Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Player.Stats.ExpToNextLevel.Value,
|
||||
Luck = Player.Stats.Luck.Value
|
||||
},
|
||||
Inventory = Player.Inventory
|
||||
}
|
||||
};
|
||||
|
||||
return gameData;
|
||||
@@ -222,12 +230,22 @@ public partial class Game : Node3D, IGame
|
||||
GameEventDepot.RestorativePickedUp += GameEventDepot_RestorativePickedUp;
|
||||
|
||||
DoubleEXPTimer.Timeout += DoubleEXPTimer_Timeout;
|
||||
|
||||
_effectService = new EffectService(this, Player);
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
SaveFile.Save();
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
SaveFile.Load();
|
||||
}
|
||||
|
||||
public void ToggleInventory()
|
||||
{
|
||||
SaveFile.Load();
|
||||
|
||||
if (GameLogic.Value is InventoryOpened)
|
||||
GameLogic.Input(new GameLogic.Input.CloseInventory());
|
||||
else
|
||||
@@ -250,7 +268,81 @@ public partial class Game : Node3D, IGame
|
||||
InGameUI.PlayerInfoUI.DisplayMessage($"{pickedUpItemName} picked up.");
|
||||
}
|
||||
|
||||
public void DropItem(IInventoryItem item)
|
||||
public void UseItem(InventoryItem item)
|
||||
{
|
||||
if (item is ConsumableItem consumableItem)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (item is EffectItem effectItem)
|
||||
{
|
||||
switch (effectItem.UsableItemTag)
|
||||
{
|
||||
case UsableItemTag.DoubleEXP:
|
||||
DoubleEXP(TimeSpan.FromSeconds(30));
|
||||
break;
|
||||
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)
|
||||
{
|
||||
if (throwableItem.HealHPAmount > 0)
|
||||
Player.HealHP(throwableItem.HealHPAmount);
|
||||
if (throwableItem.HealVTAmount > 0)
|
||||
Player.HealVT(throwableItem.HealVTAmount);
|
||||
|
||||
if (throwableItem.ThrowableItemTag == ThrowableItemTag.TeleportToRandomLocation)
|
||||
_effectService.TeleportToRandomRoom(Player);
|
||||
|
||||
if (throwableItem.ThrowableItemTag == ThrowableItemTag.CanChangeAffinity)
|
||||
_effectService.ChangeAffinity(throwableItem);
|
||||
|
||||
if (throwableItem.ThrowableItemTag == ThrowableItemTag.WarpToExitIfFound)
|
||||
_effectService.WarpToExit(Player);
|
||||
}
|
||||
}
|
||||
|
||||
public void DropItem(InventoryItem item)
|
||||
{
|
||||
var droppedScene = GD.Load<PackedScene>("res://src/items/dropped/DroppedItem.tscn");
|
||||
var dropped = droppedScene.Instantiate<DroppedItem>();
|
||||
@@ -259,14 +351,14 @@ public partial class Game : Node3D, IGame
|
||||
dropped.Drop();
|
||||
}
|
||||
|
||||
public void ThrowItem(IInventoryItem item)
|
||||
public void ThrowItem(InventoryItem item)
|
||||
{
|
||||
var thrownScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
|
||||
var thrown = thrownScene.Instantiate<ThrownItem>();
|
||||
thrown.ItemThatIsThrown = item;
|
||||
AddChild(thrown);
|
||||
thrown.Position += new Vector3(0, 1.5f, 0);
|
||||
thrown.Throw();
|
||||
thrown.Throw(_effectService);
|
||||
}
|
||||
|
||||
public void AnnounceMessageOnInventoryScreen(string message)
|
||||
@@ -323,11 +415,11 @@ public partial class Game : Node3D, IGame
|
||||
private void FloorClearMenu_TransitionCompleted()
|
||||
{
|
||||
GameRepo.Resume();
|
||||
if (Player.EquippedWeapon.Value.ItemTags.Contains(ItemTag.BreaksOnChange))
|
||||
if (Player.EquippedWeapon.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||
Player.Unequip(Player.EquippedWeapon.Value);
|
||||
if (Player.EquippedArmor.Value.ItemTags.Contains(ItemTag.BreaksOnChange))
|
||||
if (Player.EquippedArmor.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||
Player.Unequip(Player.EquippedArmor.Value);
|
||||
if (Player.EquippedAccessory.Value.ItemTags.Contains(ItemTag.BreaksOnChange))
|
||||
if (Player.EquippedAccessory.Value.ItemTag == ItemTag.BreaksOnChange)
|
||||
Player.Unequip(Player.EquippedAccessory.Value);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
[ext_resource type="Shader" uid="uid://dmjxo4k2rx1an" path="res://src/app/App.gdshader" id="2_6ifxs"]
|
||||
[ext_resource type="PackedScene" uid="uid://by67pn7fdsg1m" path="res://src/map/Map.tscn" id="3_d8awv"]
|
||||
[ext_resource type="PackedScene" uid="uid://cfecvvav8kkp6" path="res://src/player/Player.tscn" id="3_kk6ly"]
|
||||
[ext_resource type="Resource" uid="uid://bpdbuf0k0exb5" path="res://src/items/weapons/resources/Sword Sword Odette.tres" id="4_6pp6l"]
|
||||
[ext_resource type="Resource" uid="uid://bpdbuf0k0exb5" path="res://src/items/weapons/resources/Swan Sword Odette.tres" id="4_6pp6l"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1muxus5qdbeu" path="res://src/ui/in_game_ui/InGameUI.tscn" id="5_lxtnp"]
|
||||
[ext_resource type="PackedScene" uid="uid://b16ejcwanod72" path="res://src/audio/InGameAudio.tscn" id="6_qc71l"]
|
||||
[ext_resource type="Script" uid="uid://daphxl6vvsbjm" path="res://src/game/DialogueController.cs" id="10_58pbt"]
|
||||
|
||||
@@ -7,5 +7,5 @@ namespace GameJamDungeon;
|
||||
public partial record GameData
|
||||
{
|
||||
[Save("player_data")]
|
||||
public required PlayerStats PlayerData { get; init; }
|
||||
public required PlayerData PlayerData { get; init; }
|
||||
}
|
||||
|
||||
+8
-2
@@ -15,9 +15,11 @@ public interface IGame : IProvide<IGameRepo>, IProvide<IGameEventDepot>, IProvid
|
||||
|
||||
public IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
public void DropItem(IInventoryItem item);
|
||||
public void UseItem(InventoryItem item);
|
||||
|
||||
public void ThrowItem(IInventoryItem item);
|
||||
public void DropItem(InventoryItem item);
|
||||
|
||||
public void ThrowItem(InventoryItem item);
|
||||
|
||||
public void DoubleEXP(TimeSpan lengthOfEffect);
|
||||
|
||||
@@ -34,4 +36,8 @@ public interface IGame : IProvide<IGameRepo>, IProvide<IGameEventDepot>, IProvid
|
||||
public void NextFloorLoaded();
|
||||
|
||||
public void EnemyDefeated(Vector3 defeatedLocation, EnemyStatResource enemyStatResource);
|
||||
|
||||
public void Save();
|
||||
|
||||
public void Load();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user