Damage calculation including elemental buff/resistance

This commit is contained in:
2024-09-04 01:24:37 -07:00
parent 9a24ebf058
commit d7a49ba974
23 changed files with 311 additions and 70 deletions

View File

@@ -11,6 +11,8 @@ namespace GameJamDungeon
{
public interface IPlayer : ICharacterBody3D
{
PlayerStatInfo PlayerStatInfo { get; }
PlayerLogic PlayerLogic { get; }
PlayerData PlayerData { get; }
@@ -46,6 +48,9 @@ namespace GameJamDungeon
[Export(PropertyHint.Range, "0, 100, 0.1")]
public float Acceleration { get; set; } = 4f;
[Export]
public PlayerStatInfo PlayerStatInfo { get; set; }
public PlayerLogic.Settings Settings { get; set; } = default!;
public PlayerLogic PlayerLogic { get; set; } = default!;
@@ -62,6 +67,10 @@ namespace GameJamDungeon
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
private AutoProp<double> _currentHP { get; set; } = default!;
private IAutoProp<int> _currentVT { get; set; } = default!;
public void Initialize()
{
AnimationPlayer.AnimationFinished += OnAnimationFinished;
@@ -69,9 +78,7 @@ namespace GameJamDungeon
public void Setup()
{
Settings = new PlayerLogic.Settings(
RotationSpeed,
MoveSpeed);
Settings = new PlayerLogic.Settings(RotationSpeed, MoveSpeed);
PlayerLogic = new PlayerLogic();
PlayerLogic.Set(this as IPlayer);
@@ -82,6 +89,8 @@ namespace GameJamDungeon
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
EquippedWeapon = new AutoProp<WeaponInfo>(WeaponInfo.Default);
_currentHP = new AutoProp<double>(PlayerStatInfo.MaximumHP);
_currentVT = new AutoProp<int>(PlayerStatInfo.MaximumVT);
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
}
@@ -108,6 +117,7 @@ namespace GameJamDungeon
PlayerLogic.Start();
EquippedWeapon.Sync += OnEquippedWeaponChanged;
_currentHP.Sync += OnHPChanged;
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
}
@@ -166,6 +176,12 @@ namespace GameJamDungeon
private void OnEquippedWeaponChanged(WeaponInfo info) => Hitbox.Damage = info.Damage;
private void OnHPChanged(double newHP)
{
if (newHP <= 0.0)
PlayerLogic.Input(new PlayerLogic.Input.Killed());
}
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
}
}

View File

@@ -1,8 +1,9 @@
[gd_scene load_steps=16 format=3 uid="uid://cfecvvav8kkp6"]
[gd_scene load_steps=17 format=3 uid="uid://cfecvvav8kkp6"]
[ext_resource type="Script" path="res://src/player/Player.cs" id="1_xcol5"]
[ext_resource type="Texture2D" uid="uid://bokx3h8kfdo5i" path="res://src/player/slash_0000_Classic_30.png" id="2_la11l"]
[ext_resource type="Script" path="res://src/hitbox/Hitbox.cs" id="2_lb3qc"]
[ext_resource type="Resource" uid="uid://cofd1ylluj24" path="res://src/player/PlayerStats.tres" id="2_nuh2a"]
[ext_resource type="Texture2D" uid="uid://byosr5gk51237" path="res://src/player/slash_0001_Classic_29.png" id="3_ux3f1"]
[ext_resource type="Texture2D" uid="uid://nh071o6ii03j" path="res://src/player/slash_0002_Classic_28.png" id="4_gqnq0"]
[ext_resource type="Texture2D" uid="uid://bodfblud4kea3" path="res://src/player/slash_0003_Classic_27.png" id="5_eebal"]
@@ -117,6 +118,7 @@ axis_lock_angular_z = true
motion_mode = 1
script = ExtResource("1_xcol5")
RotationSpeed = 0.025
PlayerStatInfo = ExtResource("2_nuh2a")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.937567, 0)

View File

@@ -18,5 +18,14 @@ namespace GameJamDungeon
[Save("PlayerInventory")]
public required IEnumerable<InventoryItemInfo> Inventory { get; set; }
[Save("PlayerStats")]
public required PlayerStatInfo PlayerStats { get; set; }
[Save("CurrentHP")]
public required int CurrentHP { get; set; }
[Save("CurrentVT")]
public required int CurrentVT { get; set; }
}
}

View File

@@ -0,0 +1,38 @@
using Godot;
namespace GameJamDungeon
{
[GlobalClass]
public partial class PlayerStatInfo : Resource, ICharacterStats
{
[Export]
public double MaximumHP { get; set; }
[Export]
public int MaximumVT { get; set; }
[Export]
public int BaseAttack { get; set; }
[Export]
public int BaseDefense { get; set; }
[Export]
public double ElementAResistance { get; set; }
[Export]
public double ElementBResistance { get; set; }
[Export]
public double ElementCResistance { get; set; }
[Export]
public double BaseElementADamageBonus { get; set; }
[Export]
public double BaseElementBDamageBonus { get; set; }
[Export]
public double BaseElementCDamageBonus { get; set; }
}
}

View File

@@ -0,0 +1,16 @@
[gd_resource type="Resource" script_class="PlayerStatInfo" load_steps=2 format=3 uid="uid://cofd1ylluj24"]
[ext_resource type="Script" path="res://src/player/PlayerStatInfo.cs" id="1_a84hi"]
[resource]
script = ExtResource("1_a84hi")
MaximumHP = 120.0
MaximumVT = 90
BaseAttack = 10
BaseDefense = 0
ElementAResistance = 0.0
ElementBResistance = 0.0
ElementCResistance = 15.0
BaseElementADamageBonus = 30.0
BaseElementBDamageBonus = 15.0
BaseElementCDamageBonus = 20.0

View File

@@ -15,6 +15,8 @@ namespace GameJamDungeon
public readonly record struct Attack;
public readonly record struct AttackAnimationFinished;
public readonly record struct Killed;
}
}
}

View File

@@ -8,7 +8,7 @@ namespace GameJamDungeon
public partial record State
{
[Meta, Id("player_logic_alive")]
public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Moved>
public abstract partial record Alive : State, IGet<Input.PhysicsTick>, IGet<Input.Moved>, IGet<Input.Killed>
{
public virtual Transition On(in Input.PhysicsTick input)
{
@@ -36,9 +36,14 @@ namespace GameJamDungeon
{
var gameRepo = Get<IGameRepo>();
gameRepo.SetPlayerGlobalPosition(input.GlobalPosition);
GD.Print($"Current position: {input.GlobalPosition}");
return ToSelf();
}
public Transition On(in Input.Killed input)
{
GD.Print("Player died");
return To<Disabled>();
}
}
}
}