Implementation of saving inventory items (had to resturcture texture loading)
This commit is contained in:
@@ -5,7 +5,7 @@ using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerStats>>
|
||||
public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerData>>
|
||||
{
|
||||
public void Attack();
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerStats>>
|
||||
|
||||
public void ModifyBonusLuck(double amount);
|
||||
|
||||
public IInventory Inventory { get; }
|
||||
public Inventory Inventory { get; }
|
||||
|
||||
public PlayerStatController Stats { get; }
|
||||
|
||||
@@ -61,7 +61,7 @@ public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerStats>>
|
||||
|
||||
public IAutoProp<Accessory> EquippedAccessory { get; }
|
||||
|
||||
public void Equip(IEquipableItem equipable);
|
||||
public void Equip(EquipableItem equipable);
|
||||
|
||||
public void Unequip(IEquipableItem equipable);
|
||||
public void Unequip(EquipableItem equipable);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
#endregion
|
||||
|
||||
#region Save
|
||||
public ISaveChunk<PlayerStats> PlayerChunk { get; set; } = default!;
|
||||
public ISaveChunk<PlayerData> PlayerChunk { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
public double CurrentHP => Stats.CurrentHP.Value;
|
||||
@@ -30,7 +30,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
public Basis CurrentBasis => Transform.Basis;
|
||||
public PlayerStatController Stats { get; set; } = default!;
|
||||
|
||||
public IInventory Inventory { get; private set; } = default!;
|
||||
public Inventory Inventory { get; private set; } = default!;
|
||||
|
||||
public IAutoProp<Weapon> EquippedWeapon => _equippedWeapon;
|
||||
private AutoProp<Weapon> _equippedWeapon { get; set; } = new AutoProp<Weapon>(new Weapon());
|
||||
@@ -53,7 +53,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
[Dependency]
|
||||
public ISaveChunk<GameData> GameChunk => this.DependOn<ISaveChunk<GameData>>();
|
||||
|
||||
ISaveChunk<PlayerStats> IProvide<ISaveChunk<PlayerStats>>.Value() => PlayerChunk;
|
||||
ISaveChunk<PlayerData> IProvide<ISaveChunk<PlayerData>>.Value() => PlayerChunk;
|
||||
#endregion
|
||||
|
||||
#region Event Signals
|
||||
@@ -82,6 +82,8 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
|
||||
[Node] private IHitbox Hitbox { get; set; } = default!;
|
||||
|
||||
[Node] private Area3D CollisionDetector { get; set; } = default!;
|
||||
|
||||
[Node] private Timer HealthTimer { get; set; } = default!;
|
||||
#endregion
|
||||
|
||||
@@ -144,9 +146,9 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
PlayerLogic.Set(Stats);
|
||||
|
||||
var defaultWeapon = new Weapon();
|
||||
defaultWeapon.SetItemStats(_defaultWeapon);
|
||||
defaultWeapon.ItemStats = _defaultWeapon;
|
||||
var defaultArmor = new Armor();
|
||||
defaultArmor.SetItemStats(_defaultArmor);
|
||||
defaultArmor.ItemStats = _defaultArmor;
|
||||
Inventory.TryAdd(defaultWeapon);
|
||||
Inventory.TryAdd(defaultArmor);
|
||||
|
||||
@@ -164,27 +166,32 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
PlayerChunk = new SaveChunk<PlayerStats>(
|
||||
onSave: (chunk) => new PlayerStats
|
||||
PlayerChunk = new SaveChunk<PlayerData>(
|
||||
onSave: (chunk) => new PlayerData()
|
||||
{
|
||||
CurrentHP = Stats.CurrentHP.Value,
|
||||
MaximumHP = Stats.MaximumHP.Value,
|
||||
CurrentVT = Stats.CurrentVT.Value,
|
||||
MaximumVT = Stats.MaximumVT.Value,
|
||||
CurrentAttack = Stats.CurrentAttack.Value,
|
||||
BonusAttack = Stats.BonusAttack.Value,
|
||||
MaxAttack = Stats.MaxAttack.Value,
|
||||
CurrentDefense = Stats.CurrentDefense.Value,
|
||||
BonusDefense = Stats.BonusDefense.Value,
|
||||
MaxDefense = Stats.MaxDefense.Value,
|
||||
CurrentExp = Stats.CurrentExp.Value,
|
||||
CurrentLevel = Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Stats.ExpToNextLevel.Value,
|
||||
Luck = Stats.Luck.Value
|
||||
PlayerStats = new PlayerStats()
|
||||
{
|
||||
CurrentHP = Stats.CurrentHP.Value,
|
||||
MaximumHP = Stats.MaximumHP.Value,
|
||||
CurrentVT = Stats.CurrentVT.Value,
|
||||
MaximumVT = Stats.MaximumVT.Value,
|
||||
CurrentAttack = Stats.CurrentAttack.Value,
|
||||
BonusAttack = Stats.BonusAttack.Value,
|
||||
MaxAttack = Stats.MaxAttack.Value,
|
||||
CurrentDefense = Stats.CurrentDefense.Value,
|
||||
BonusDefense = Stats.BonusDefense.Value,
|
||||
MaxDefense = Stats.MaxDefense.Value,
|
||||
CurrentExp = Stats.CurrentExp.Value,
|
||||
CurrentLevel = Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Stats.ExpToNextLevel.Value,
|
||||
Luck = Stats.Luck.Value
|
||||
},
|
||||
Inventory = Inventory
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
Stats.Init(data);
|
||||
Stats.Init(data.PlayerStats);
|
||||
Inventory = data.Inventory;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -208,6 +215,17 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
this.Provide();
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
CollisionDetector.BodyEntered += CollisionDetector_BodyEntered;
|
||||
}
|
||||
|
||||
private void CollisionDetector_BodyEntered(Node3D body)
|
||||
{
|
||||
if (body is InventoryItem inventoryItem)
|
||||
{
|
||||
var isAdded = Inventory.TryAdd(inventoryItem);
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
@@ -368,6 +386,12 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
|
||||
if (@event.IsActionPressed(GameInputs.Attack))
|
||||
Attack();
|
||||
|
||||
if (@event.IsActionPressed(GameInputs.Save))
|
||||
Game.Save();
|
||||
|
||||
if (@event.IsActionPressed(GameInputs.Load))
|
||||
Game.Load();
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
@@ -376,7 +400,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform));
|
||||
}
|
||||
|
||||
public void Equip(IEquipableItem equipable)
|
||||
public void Equip(EquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
@@ -400,7 +424,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
}
|
||||
|
||||
public void Unequip(IEquipableItem equipable)
|
||||
public void Unequip(EquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
@@ -427,7 +451,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
|
||||
if (equipable.ItemTags.Contains(ItemTag.BreaksOnChange))
|
||||
if (equipable.ItemTag == ItemTag.BreaksOnChange)
|
||||
Inventory.Remove(equipable);
|
||||
}
|
||||
|
||||
@@ -492,7 +516,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
|
||||
if (Stats.CurrentVT.Value > 0)
|
||||
{
|
||||
if (EquippedAccessory.Value.AccessoryTags.Contains(AccessoryTag.HalfVTConsumption))
|
||||
if (EquippedAccessory.Value.AccessoryTag == AccessoryTag.HalfVTConsumption)
|
||||
{
|
||||
reduceOnTick = !reduceOnTick;
|
||||
}
|
||||
@@ -550,7 +574,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
private void HitEnemy(IEnemy enemy)
|
||||
{
|
||||
var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value;
|
||||
var ignoreElementalResistance = EquippedWeapon.Value.WeaponTags.Contains(WeaponTag.IgnoreAffinity);
|
||||
var ignoreElementalResistance = EquippedWeapon.Value.WeaponTag == WeaponTag.IgnoreAffinity;
|
||||
var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value);
|
||||
var element = EquippedWeapon.Value.WeaponElement;
|
||||
|
||||
@@ -561,7 +585,7 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
false,
|
||||
ignoreElementalResistance);
|
||||
|
||||
if (EquippedWeapon.Value.WeaponTags.Contains(WeaponTag.Knockback))
|
||||
if (EquippedWeapon.Value.WeaponTag == WeaponTag.Knockback)
|
||||
enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
[ext_resource type="Script" uid="uid://yxmiqy7i0t7r" path="res://src/player/Player.cs" id="1_xcol5"]
|
||||
[ext_resource type="Script" uid="uid://6edayafleq8y" path="res://src/hitbox/Hitbox.cs" id="2_lb3qc"]
|
||||
[ext_resource type="Script" uid="uid://s6ku2kyc4rbk" path="res://src/player/PlayerStatResource.cs" id="2_xq68d"]
|
||||
[ext_resource type="Resource" uid="uid://b7xr0l4a8g1gk" path="res://src/items/weapons/resources/SealingRod.tres" id="3_ebyyx"]
|
||||
[ext_resource type="Resource" uid="uid://bpdbuf0k0exb5" path="res://src/items/weapons/resources/Swan Sword Odette.tres" id="3_es4xk"]
|
||||
[ext_resource type="Resource" uid="uid://ce2vfa2t3io67" path="res://src/items/armor/resources/AtonersAdornments.tres" id="4_bj1ma"]
|
||||
[ext_resource type="Texture2D" uid="uid://c6r3dhnkuw22w" path="res://src/vfx/hit_effects/FIRE_STRIKE_1.0.png" id="5_wr6lo"]
|
||||
[ext_resource type="Texture2D" uid="uid://m6xsyhnt67sh" path="res://src/player/dont_look_in_here/tendomaya_body0_tex00.png" id="6_es4xk"]
|
||||
@@ -32,13 +32,13 @@ BonusDefense = 0
|
||||
MaxDefense = 12
|
||||
Luck = 0.05
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_wedu3"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dw45s"]
|
||||
radius = 1.0
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_wedu3"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_hs4wf"]
|
||||
size = Vector3(1.94531, 2.43945, 2.35425)
|
||||
size = Vector3(1.94531, 3.38623, 2.35425)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_hcjph"]
|
||||
length = 0.001
|
||||
@@ -470,9 +470,13 @@ collision_layer = 806
|
||||
collision_mask = 775
|
||||
script = ExtResource("1_xcol5")
|
||||
PlayerStatResource = SubResource("Resource_btp2w")
|
||||
_defaultWeapon = ExtResource("3_ebyyx")
|
||||
_defaultWeapon = ExtResource("3_es4xk")
|
||||
_defaultArmor = ExtResource("4_bj1ma")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.06447, 0)
|
||||
shape = SubResource("CapsuleShape3D_dw45s")
|
||||
|
||||
[node name="Hitbox" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.12691, -1)
|
||||
@@ -484,18 +488,14 @@ script = ExtResource("2_lb3qc")
|
||||
shape = SubResource("BoxShape3D_wedu3")
|
||||
disabled = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.06447, 0)
|
||||
shape = SubResource("CapsuleShape3D_dw45s")
|
||||
|
||||
[node name="CollisionDetector" type="Area3D" parent="CollisionShape3D"]
|
||||
[node name="CollisionDetector" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.937567, 0)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.126903, 0)
|
||||
collision_layer = 452
|
||||
collision_mask = 452
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CollisionShape3D/CollisionDetector"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0479561, 0.982638, -0.675098)
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="CollisionDetector"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0479561, 0.509249, -0.675098)
|
||||
shape = SubResource("BoxShape3D_hs4wf")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
|
||||
14
src/player/PlayerData.cs
Normal file
14
src/player/PlayerData.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta, Id("player_data")]
|
||||
public partial record PlayerData
|
||||
{
|
||||
[Save("player_stats")]
|
||||
public required PlayerStats PlayerStats { get; init; }
|
||||
|
||||
[Save("player_inventory")]
|
||||
public required Inventory Inventory { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user