Compare commits
2 Commits
0434667c22
...
b523591e84
| Author | SHA1 | Date | |
|---|---|---|---|
| b523591e84 | |||
| 4be0092cfb |
@@ -1,6 +1,10 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://n5cj71bxxjkk"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://n5cj71bxxjkk"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqe1i2qmpttwf" path="res://scripts/CSharp/Common/Fight/FightWorld.cs" id="1_tnyce"]
|
||||
[ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="2_lxs0o"]
|
||||
[ext_resource type="Resource" uid="uid://0mnsr4anoaiq" path="res://resources/items/beet.tres" id="3_008v8"]
|
||||
|
||||
[node name="FightWorldAutoload" type="Node2D"]
|
||||
script = ExtResource("1_tnyce")
|
||||
_itemToDropByEnemyGroup = ExtResource("2_lxs0o")
|
||||
itemBeetrootToEatForHealth = ExtResource("3_008v8")
|
||||
|
||||
@@ -146,7 +146,7 @@ theme_override_constants/margin_bottom = 10
|
||||
[node name="Talk Button" type="Button" parent="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 41
|
||||
text = "Talk"
|
||||
text = "Heal"
|
||||
|
||||
[node name="MarginContainer4" type="MarginContainer" parent="ActionSelect/BottomPanel/VBoxContainer/MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
[ext_resource type="Shader" uid="uid://xnky830dtfsn" path="res://shader/repeat_texture.gdshader" id="23_2ouqg"]
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Vesna.tscn" id="24_ffcio"]
|
||||
[ext_resource type="Resource" uid="uid://dlcmqfjvgphqu" path="res://resources/items/rake.tres" id="25_3h260"]
|
||||
[ext_resource type="Resource" uid="uid://cndd64batns31" path="res://resources/items/wateringcan.tres" id="26_1bhpp"]
|
||||
[ext_resource type="Shader" uid="uid://braevmqauoek7" path="res://shader/swaying_plant.gdshader" id="27_txtka"]
|
||||
[ext_resource type="Texture2D" uid="uid://dgavbfci8x178" path="res://art/nature/grass/grass-1.png" id="28_ejigw"]
|
||||
[ext_resource type="Texture2D" uid="uid://h2b5aufaaw7w" path="res://art/nature/grass/grass-2.png" id="29_pjemw"]
|
||||
@@ -41,6 +40,7 @@
|
||||
[ext_resource type="Script" uid="uid://dbu8afaiohpdh" path="res://scripts/CSharp/Common/Fight/FightRoomSceneSetup.cs" id="40_cvg1r"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcld43daavmrn" path="res://prefabs/fight/fight_scene_switcher.tscn" id="40_elhbh"]
|
||||
[ext_resource type="PackedScene" uid="uid://qfdiudt3vpai" path="res://prefabs/fight/roaming_enemy_group.tscn" id="41_cvg1r"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpbbroif2tnil" path="res://prefabs/interactions/generic_item_on_ground_2d.tscn" id="41_x3yi1"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ruj2u"]
|
||||
shader = ExtResource("16_0fard")
|
||||
@@ -64,9 +64,9 @@ colors = PackedColorArray(0.348791, 0.400092, 0.435264, 1, 0.219333, 0.251087, 0
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_d5x6a"]
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_d53cn"]
|
||||
seamless = true
|
||||
color_ramp = SubResource("Gradient_663j1")
|
||||
noise = SubResource("FastNoiseLite_d5x6a")
|
||||
color_ramp = SubResource("Gradient_663j1")
|
||||
seamless = true
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_k0jkw"]
|
||||
shader = ExtResource("23_2ouqg")
|
||||
@@ -84,9 +84,9 @@ fractal_gain = 0.795
|
||||
domain_warp_enabled = true
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_pjpt5"]
|
||||
seamless = true
|
||||
color_ramp = SubResource("Gradient_eryax")
|
||||
noise = SubResource("FastNoiseLite_wgikv")
|
||||
color_ramp = SubResource("Gradient_eryax")
|
||||
seamless = true
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_yvxfs"]
|
||||
shader = ExtResource("27_txtka")
|
||||
@@ -765,7 +765,6 @@ y_sort_enabled = true
|
||||
[node name="Vesna" parent="YSorted" instance=ExtResource("24_ffcio")]
|
||||
position = Vector2(8202, 1950)
|
||||
_hoe = ExtResource("25_3h260")
|
||||
_wateringCan = ExtResource("26_1bhpp")
|
||||
|
||||
[node name="CharacterBody2D" parent="YSorted/Vesna" index="0"]
|
||||
y_sort_enabled = true
|
||||
@@ -776,11 +775,9 @@ y_sort_enabled = true
|
||||
[node name="Animated Sprites" parent="YSorted/Vesna/CharacterBody2D/visuals" index="0"]
|
||||
y_sort_enabled = true
|
||||
animation = &"diagonal item"
|
||||
frame = 0
|
||||
frame_progress = 0.0
|
||||
|
||||
[node name="WateringCanUI" parent="YSorted/Vesna/CharacterBody2D" index="2" node_paths=PackedStringArray("_stages")]
|
||||
_stages = [null, null, null, null, null, null]
|
||||
|
||||
[node name="ForestVisuals" type="Node2D" parent="YSorted"]
|
||||
y_sort_enabled = true
|
||||
position = Vector2(-60, -250)
|
||||
@@ -864,10 +861,10 @@ region_rect = Rect2(1699, 76, 280, 230)
|
||||
[node name="bush4" type="Sprite2D" parent="YSorted/ForestVisuals/Static/greenery/left side"]
|
||||
modulate = Color(0.8428, 0.8771, 0.98, 1)
|
||||
material = SubResource("ShaderMaterial_yvxfs")
|
||||
position = Vector2(16878, 2099)
|
||||
position = Vector2(16884, 1943)
|
||||
scale = Vector2(2, 2)
|
||||
texture = ExtResource("19_edja8")
|
||||
offset = Vector2(0, -172)
|
||||
offset = Vector2(-3, -94)
|
||||
region_enabled = true
|
||||
region_rect = Rect2(0, 604, 248, 228)
|
||||
|
||||
@@ -1232,10 +1229,10 @@ region_rect = Rect2(130, 0, 201, 278)
|
||||
modulate = Color(0.8428, 0.8771, 0.98, 1)
|
||||
y_sort_enabled = true
|
||||
material = SubResource("ShaderMaterial_yvxfs")
|
||||
position = Vector2(3348, 2074)
|
||||
position = Vector2(3346.379, 1926.0276)
|
||||
scale = Vector2(-2.40318, 3.59175)
|
||||
texture = ExtResource("19_edja8")
|
||||
offset = Vector2(0, -172)
|
||||
offset = Vector2(-0.67456055, -130.80212)
|
||||
region_enabled = true
|
||||
region_rect = Rect2(130, 0, 201, 278)
|
||||
|
||||
@@ -2156,6 +2153,7 @@ _sceneRoot = NodePath("..")
|
||||
script = ExtResource("40_cvg1r")
|
||||
_enemyGroupSpawns = [NodePath("../YSorted/EnemyGroupSpawns/Spawn1"), NodePath("../YSorted/EnemyGroupSpawns/Spawn2"), NodePath("../YSorted/EnemyGroupSpawns/Spawn3"), NodePath("../YSorted/EnemyGroupSpawns/Spawn4")]
|
||||
_roamingEnemyGroupPrefab = ExtResource("41_cvg1r")
|
||||
_itemOnGroundPrefab = ExtResource("41_x3yi1")
|
||||
_fightSceneSwitcher = NodePath("../FightSceneSwitcher")
|
||||
|
||||
[editable path="YSorted/Vesna"]
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AllyAttackAction : FighterAction
|
||||
public override void ExecuteAction()
|
||||
{
|
||||
var totalDamage = minigameDetail.damageHits!.Sum(dh => dh);
|
||||
targetSelect.GetTarget().AddHealth(-totalDamage);
|
||||
targetSelect.GetTarget().ChangeHealth(-totalDamage);
|
||||
}
|
||||
|
||||
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
@@ -63,7 +63,7 @@ public class AllyAttackAction : FighterAction
|
||||
|
||||
foreach (var hit in minigameDetail.damageHits!)
|
||||
{
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber(hit);
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber($"-{hit}");
|
||||
}
|
||||
|
||||
await currentFighterVisual.AnimatePosToBase();
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BlobAttackAction(int damage = 3) : FighterAction
|
||||
|
||||
public override void ExecuteAction()
|
||||
{
|
||||
FightWorld.Instance.allyFighters.vesnaFighter.AddHealth(-damage);
|
||||
FightWorld.Instance.allyFighters.vesnaFighter.ChangeHealth(-damage);
|
||||
}
|
||||
|
||||
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
@@ -31,7 +31,7 @@ public class BlobAttackAction(int damage = 3) : FighterAction
|
||||
|
||||
await currentFighterVisual.AnimatePosToTarget(targetFighterVisual);
|
||||
_ = targetFighterVisual.AnimateHit();
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber(damage);
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber($"-{damage}");
|
||||
await currentFighterVisual.AnimatePosToBase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight.Actions;
|
||||
|
||||
public class EatBeetrootAction : FighterAction
|
||||
{
|
||||
public override Variant<float, Func<bool>> GetAnimationEnd() => 1;
|
||||
public override bool NextDetail() => false;
|
||||
|
||||
private const int HealAmount = 20;
|
||||
|
||||
public override bool ShouldAbort()
|
||||
{
|
||||
Debug.Assert(FightWorld.Instance.itemBeetrootToEatForHealth != null,
|
||||
"Item to eat for health has not been set in the FightWorld autoload");
|
||||
return !InventoryManager.Instance.playerInventory!.HasItems(new ItemInstance
|
||||
{ blueprint = FightWorld.Instance.itemBeetrootToEatForHealth });
|
||||
}
|
||||
|
||||
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
{
|
||||
var fighter = HappeningData.fighterTurn.Current;
|
||||
var fighterVisual = allFightersVisual.GetVisualForFighter(fighter);
|
||||
fighterVisual.SpawnDamageIndicatorNumber($"+{HealAmount}");
|
||||
await fighterVisual.AnimateHeal();
|
||||
}
|
||||
|
||||
public override void ExecuteAction()
|
||||
{
|
||||
var fighter = HappeningData.fighterTurn.Current;
|
||||
|
||||
var result = InventoryManager.Instance.playerInventory!.TryRemoveAllItems(
|
||||
new ItemInstance { blueprint = FightWorld.Instance.itemBeetrootToEatForHealth! });
|
||||
|
||||
if (result != InventoryActionResult.Success)
|
||||
throw new Exception("No Beetroot in inventory. This case should have been handled earlier");
|
||||
|
||||
fighter.ChangeHealth(HealAmount);
|
||||
}
|
||||
|
||||
public override AllyActionButton BindToActionButton() => AllyActionButton.Talk; // Temporarily bound to talk button
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b2463q1waqvdu
|
||||
@@ -10,7 +10,8 @@ public class AllyFighters
|
||||
maxHealth = 60,
|
||||
availableActions =
|
||||
[
|
||||
new AllyAttackAction()
|
||||
new AllyAttackAction(),
|
||||
new EatBeetrootAction()
|
||||
]
|
||||
};
|
||||
public FightWorld.Fighter chuhaFighter = new()
|
||||
|
||||
@@ -222,9 +222,9 @@ public partial class FightHappening : Node
|
||||
case FightState.ActionCheckDetails:
|
||||
RequireNotNull(HappeningData.actionStaging);
|
||||
|
||||
if (ActionAbort())
|
||||
if (ShouldActionAbort())
|
||||
ChangeState(FightState.InputActionSelect);
|
||||
else if (ActionNeededDetail())
|
||||
else if (DoesActionNeededDetail())
|
||||
ChangeState(FightState.InputActionDetail);
|
||||
else
|
||||
ChangeState(FightState.ActionExecute);
|
||||
@@ -328,13 +328,13 @@ public partial class FightHappening : Node
|
||||
return HappeningData.actionStaging.GetAnimationEnd();
|
||||
}
|
||||
|
||||
private bool ActionAbort()
|
||||
private bool ShouldActionAbort()
|
||||
{
|
||||
Debug.Assert(HappeningData.actionStaging != null);
|
||||
return HappeningData.actionStaging.MarkedForAbort();
|
||||
return HappeningData.actionStaging.ShouldAbort();
|
||||
}
|
||||
|
||||
private bool ActionNeededDetail()
|
||||
private bool DoesActionNeededDetail()
|
||||
{
|
||||
Debug.Assert(HappeningData.actionStaging != null);
|
||||
return HappeningData.actionStaging.NextDetail();
|
||||
@@ -344,7 +344,7 @@ public partial class FightHappening : Node
|
||||
private void ReviveVesna()
|
||||
{
|
||||
var vesnaFighter = FightWorld.Instance.allyFighters.vesnaFighter;
|
||||
vesnaFighter.health = vesnaFighter.maxHealth;
|
||||
vesnaFighter.Health = vesnaFighter.maxHealth;
|
||||
GD.Print("Vesna has been revived. This is for the current prototype only");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight;
|
||||
|
||||
public partial class FightRoomSceneSetup : Node
|
||||
{
|
||||
[Export(PropertyHint.ArrayType)] private Node2D[] _enemyGroupSpawns;
|
||||
[Export] private PackedScene _roamingEnemyGroupPrefab;
|
||||
[Export] private FightSceneSwitcher _fightSceneSwitcher;
|
||||
[Export(PropertyHint.ArrayType)] private Node2D[] _enemyGroupSpawns = null!;
|
||||
[Export] private PackedScene _roamingEnemyGroupPrefab = null!;
|
||||
[Export] private PackedScene _itemOnGroundPrefab = null!;
|
||||
[Export] private FightSceneSwitcher _fightSceneSwitcher = null!;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
@@ -19,11 +20,30 @@ public partial class FightRoomSceneSetup : Node
|
||||
foreach (var (parent, group) in _enemyGroupSpawns.Zip(room.enemyGroups))
|
||||
{
|
||||
if (group.AreAllDead())
|
||||
continue;
|
||||
|
||||
var roamingEnemyGroup = _roamingEnemyGroupPrefab.Instantiate<RoamingEnemyGroup>();
|
||||
roamingEnemyGroup.Initialize(group, _fightSceneSwitcher);
|
||||
parent.AddChild(roamingEnemyGroup);
|
||||
{
|
||||
SpawnLoot(group, parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
SpawnEnemies(group, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnEnemies(FightWorld.FighterGroup group, Node2D parent)
|
||||
{
|
||||
var roamingEnemyGroup = _roamingEnemyGroupPrefab.Instantiate<RoamingEnemyGroup>();
|
||||
roamingEnemyGroup.Initialize(group, _fightSceneSwitcher);
|
||||
parent.AddChild(roamingEnemyGroup);
|
||||
}
|
||||
|
||||
private void SpawnLoot(FightWorld.FighterGroup group, Node2D parent)
|
||||
{
|
||||
if (group.lootToDrop == null)
|
||||
return;
|
||||
|
||||
var onGroundInstance = _itemOnGroundPrefab.Instantiate<ItemOnGround2D>();
|
||||
onGroundInstance.itemInstance = group.lootToDrop;
|
||||
parent.AddChild(onGroundInstance);
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,16 @@ public static class FightUtils
|
||||
{
|
||||
return self.Where(e => e.IsAlive());
|
||||
}
|
||||
|
||||
public static IEnumerable<FightWorld.Fighter> WhereIsNotInFormation(this IEnumerable<FightWorld.Fighter> self, FighterFormation formation)
|
||||
|
||||
public static IEnumerable<FightWorld.Fighter> WhereIsNotInFormation(this IEnumerable<FightWorld.Fighter> self,
|
||||
FighterFormation formation)
|
||||
{
|
||||
return self.Where(e => !e.IsInFormation(formation));
|
||||
}
|
||||
|
||||
public static bool IsAlive(this FightWorld.Fighter self)
|
||||
{
|
||||
return self.GetHealth() > 0;
|
||||
return self.Health > 0;
|
||||
}
|
||||
|
||||
public static bool IsDead(this FightWorld.Fighter self)
|
||||
@@ -26,16 +27,16 @@ public static class FightUtils
|
||||
return !self.IsAlive();
|
||||
}
|
||||
|
||||
public static int GetHealth(this FightWorld.Fighter self)
|
||||
/// <summary>
|
||||
/// Changes the health of a fighter
|
||||
/// </summary>
|
||||
/// <param name="self">The fighter itself</param>
|
||||
/// <param name="amount">The amount of health to add. Make negative to remove health</param>
|
||||
public static void ChangeHealth(this FightWorld.Fighter self, int amount)
|
||||
{
|
||||
return Math.Max(self.health ?? self.maxHealth, 0);
|
||||
self.Health += amount;
|
||||
}
|
||||
|
||||
public static void AddHealth(this FightWorld.Fighter self, int addHealth)
|
||||
{
|
||||
self.health = self.GetHealth() + addHealth;
|
||||
}
|
||||
|
||||
public static bool IsInFormation(this FightWorld.Fighter self, FighterFormation formation)
|
||||
{
|
||||
return formation.ContainsFighter(self);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Babushka.scripts.CSharp.Common.Fight.Actions;
|
||||
using Babushka.scripts.CSharp.Common.Inventory;
|
||||
using Babushka.scripts.CSharp.Common.Util;
|
||||
using Godot;
|
||||
|
||||
@@ -19,6 +21,7 @@ public partial class FightWorld : Node
|
||||
None,
|
||||
EndOfNight
|
||||
}
|
||||
|
||||
public required Dictionary<int, Room> paths;
|
||||
public required List<FighterGroup> enemyGroups;
|
||||
public Special specialRoom = Special.None;
|
||||
@@ -27,6 +30,7 @@ public partial class FightWorld : Node
|
||||
public class FighterGroup
|
||||
{
|
||||
public required List<Fighter> fighters;
|
||||
public ItemInstance? lootToDrop = null;
|
||||
}
|
||||
|
||||
public class FightHappeningData
|
||||
@@ -56,9 +60,17 @@ public partial class FightWorld : Node
|
||||
public required int maxHealth;
|
||||
public required List<FighterAction> availableActions;
|
||||
public const int MaxActionPoints = 1;
|
||||
public int? health = null; // null => initialize to full health on spawn
|
||||
public int actionPointsLeft;
|
||||
|
||||
private int? _healthBacking = null;
|
||||
|
||||
public int Health
|
||||
{
|
||||
get => _healthBacking ?? maxHealth;
|
||||
set => _healthBacking = Math.Clamp(value, 0, maxHealth);
|
||||
}
|
||||
|
||||
|
||||
public FighterAction AutoSelectAction()
|
||||
{
|
||||
return availableActions.Random() ?? new FighterAction.Skip();
|
||||
@@ -81,6 +93,10 @@ public partial class FightWorld : Node
|
||||
public FightHappeningData? fightHappeningData = null;
|
||||
public AllyFighters allyFighters = new();
|
||||
|
||||
// settings
|
||||
[Export] private ItemResource? _itemToDropByEnemyGroup;
|
||||
[Export] public ItemResource? itemBeetrootToEatForHealth;
|
||||
|
||||
public void ResetFightWorld()
|
||||
{
|
||||
Generate();
|
||||
@@ -89,10 +105,10 @@ public partial class FightWorld : Node
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
world = new Generator().GenerateWorld();
|
||||
world = new Generator(this).GenerateWorld();
|
||||
}
|
||||
|
||||
private class Generator
|
||||
private class Generator(FightWorld fightWorld)
|
||||
{
|
||||
public World GenerateWorld()
|
||||
{
|
||||
@@ -113,7 +129,7 @@ public partial class FightWorld : Node
|
||||
{
|
||||
rooms.Add(GenerateDisconnectedRoom());
|
||||
}
|
||||
|
||||
|
||||
rooms.Add(new Room
|
||||
{
|
||||
paths = [],
|
||||
@@ -162,6 +178,11 @@ public partial class FightWorld : Node
|
||||
fighters = []
|
||||
};
|
||||
|
||||
if (fightWorld._itemToDropByEnemyGroup != null)
|
||||
{
|
||||
enemyGroup.lootToDrop = new ItemInstance { blueprint = fightWorld._itemToDropByEnemyGroup };
|
||||
}
|
||||
|
||||
var enemyCount = GD.RandRange(2, 3);
|
||||
|
||||
for (var i = 0; i < enemyCount; i++)
|
||||
@@ -189,7 +210,6 @@ public partial class FightWorld : Node
|
||||
var enemy = new Fighter
|
||||
{
|
||||
type = type,
|
||||
health = null,
|
||||
maxHealth = GD.RandRange(8, 20),
|
||||
availableActions =
|
||||
[
|
||||
|
||||
@@ -30,8 +30,6 @@ public abstract class FighterAction
|
||||
public abstract bool DetailComplete();
|
||||
}
|
||||
|
||||
private bool _abort = false;
|
||||
|
||||
#region Shortcuts
|
||||
|
||||
protected static FightWorld.FightHappeningData HappeningData =>
|
||||
@@ -65,15 +63,7 @@ public abstract class FighterAction
|
||||
{
|
||||
}
|
||||
|
||||
public void MarkAbort()
|
||||
{
|
||||
_abort = true;
|
||||
}
|
||||
|
||||
public bool MarkedForAbort()
|
||||
{
|
||||
return _abort;
|
||||
}
|
||||
public virtual bool ShouldAbort() => false;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the FighterActionDetail, that is currently handled.
|
||||
|
||||
@@ -7,9 +7,9 @@ public partial class FighterDamageIndicatorFlyingNumber : Node2D
|
||||
{
|
||||
[Export] private Label _label;
|
||||
|
||||
public void Initialize(int number)
|
||||
public void Initialize(string text)
|
||||
{
|
||||
_label.Text = number.ToString();
|
||||
_label.Text = text;
|
||||
|
||||
var tween = CreateTween();
|
||||
var xMovement = GD.RandRange(-150, 150);
|
||||
|
||||
@@ -7,10 +7,10 @@ public partial class FighterDamageIndicatorVisual : Node2D
|
||||
[Export] private PackedScene _flyingNumberPrefab;
|
||||
|
||||
|
||||
public void SpawnFlyingNumber(int number)
|
||||
public void SpawnFlyingNumber(string text)
|
||||
{
|
||||
var flyingNumberInstance = _flyingNumberPrefab.Instantiate<FighterDamageIndicatorFlyingNumber>();
|
||||
AddChild(flyingNumberInstance);
|
||||
flyingNumberInstance.Initialize(number);
|
||||
flyingNumberInstance.Initialize(text);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,12 @@ public partial class FighterVisual : Node2D
|
||||
_boundFighter.IsInFormation(HappeningData.enemyFighterFormation) ? -1 : 1,
|
||||
_boundFighter.IsDead() ? .3f : 1);
|
||||
|
||||
healthBarVisual.UpdateHealth(_boundFighter.GetHealth(), _boundFighter.maxHealth);
|
||||
UpdateHealthBarVisuals();
|
||||
}
|
||||
|
||||
private void UpdateHealthBarVisuals()
|
||||
{
|
||||
healthBarVisual.UpdateHealth(_boundFighter.Health, _boundFighter.maxHealth);
|
||||
}
|
||||
|
||||
public void SetTargetSelectionActive(bool value)
|
||||
@@ -78,24 +83,26 @@ public partial class FighterVisual : Node2D
|
||||
|
||||
public async Task AnimateHit()
|
||||
{
|
||||
UpdateHealthBarVisuals();
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(_squashParent, "scale", new Vector2(1.4f, 0.6f), 0.15);
|
||||
tween.TweenProperty(_squashParent, "scale", new Vector2(1, 1), 0.4)
|
||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
// Keep for reference for new Heal animation
|
||||
//public void HealAnimation()
|
||||
//{
|
||||
// EmitSignalHealed();
|
||||
// var tween = GetTree().CreateTween();
|
||||
// tween.TweenProperty(this, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
||||
// tween.TweenProperty(this, "scale", new Vector2(1, 1), 0.4)
|
||||
// .SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
//}
|
||||
public void SpawnDamageIndicatorNumber(int number)
|
||||
|
||||
public async Task AnimateHeal()
|
||||
{
|
||||
_fighterDamageIndicatorVisual.SpawnFlyingNumber(number);
|
||||
UpdateHealthBarVisuals();
|
||||
var tween = GetTree().CreateTween();
|
||||
tween.TweenProperty(_squashParent, "scale", new Vector2(0.6f, 1.4f), 0.15);
|
||||
tween.TweenProperty(_squashParent, "scale", new Vector2(1, 1), 0.4)
|
||||
.SetTrans(Tween.TransitionType.Cubic).SetEase(Tween.EaseType.Out);
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
public void SpawnDamageIndicatorNumber(string text)
|
||||
{
|
||||
_fighterDamageIndicatorVisual.SpawnFlyingNumber(text);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
|
||||
[Signal]
|
||||
public delegate void InventoryContentsChangedEventHandler();
|
||||
|
||||
|
||||
public static string ID = "inventoryInstance";
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
SlotAmountChanged += UpdateSaveData;
|
||||
SavegameService.OnSaveGameReset += SaveGameReset;
|
||||
}
|
||||
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryContentsChanged -= UpdateSaveData;
|
||||
@@ -101,7 +101,8 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
return InventoryActionResult.DestinationFull;
|
||||
}
|
||||
|
||||
var itemInstance = _slots[slotIndex].itemInstance ?? new ItemInstance { blueprint = newItem.blueprint, amount = 0 };
|
||||
var itemInstance = _slots[slotIndex].itemInstance ??
|
||||
new ItemInstance { blueprint = newItem.blueprint, amount = 0 };
|
||||
var maxStack = itemInstance!.blueprint.maxStack;
|
||||
var freeOnStack = maxStack - itemInstance.amount;
|
||||
var moveAmount = Math.Min(freeOnStack, newItem.amount);
|
||||
@@ -130,12 +131,12 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
itemInstance = _slots[inventorySlot].itemInstance;
|
||||
if (itemInstance == null)
|
||||
return InventoryActionResult.SourceDoesNotExist;
|
||||
|
||||
|
||||
itemInstance.amount -= 1;
|
||||
|
||||
if(itemInstance.amount == 0)
|
||||
|
||||
if (itemInstance.amount == 0)
|
||||
_slots[inventorySlot].itemInstance = null;
|
||||
|
||||
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
@@ -145,6 +146,38 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
return RemoveItem(inventorySlot, out _);
|
||||
}
|
||||
|
||||
public InventoryActionResult TryRemoveAllItems(ItemInstance items)
|
||||
{
|
||||
var hasItemsCount = TotalItemsOfBlueprint(items.blueprint);
|
||||
if (hasItemsCount < items.amount)
|
||||
return InventoryActionResult.SourceDoesNotExist;
|
||||
|
||||
var amountToRemove = items.amount;
|
||||
foreach (var s in _slots)
|
||||
{
|
||||
if (s.IsEmpty() || s.itemInstance!.blueprint != items.blueprint)
|
||||
continue;
|
||||
|
||||
var slotItem = s.itemInstance!;
|
||||
if (slotItem.amount <= amountToRemove)
|
||||
{
|
||||
amountToRemove -= slotItem.amount;
|
||||
s.itemInstance = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
slotItem.amount -= amountToRemove;
|
||||
amountToRemove = 0;
|
||||
}
|
||||
|
||||
if (amountToRemove == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
EmitSignal(SignalName.InventoryContentsChanged);
|
||||
return InventoryActionResult.Success;
|
||||
}
|
||||
|
||||
public InventoryActionResult AddItemToSlot(ItemInstance itemInstance, int destinationSlot)
|
||||
{
|
||||
if (destinationSlot < 0 || destinationSlot >= _slots.Count)
|
||||
@@ -174,8 +207,8 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
{
|
||||
return items.All(HasItems);
|
||||
}
|
||||
|
||||
#region SAVE AND LOAD
|
||||
|
||||
#region SAVE AND LOAD
|
||||
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
@@ -189,17 +222,17 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
string[] value = new string[2];
|
||||
value[0] = _slots[i].itemInstance.blueprint.ResourcePath;
|
||||
value[1] = _slots[i].itemInstance.amount.ToString();
|
||||
payloadData.Add(key,value);
|
||||
payloadData.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SavegameService.AppendDataToSave(ID, payloadData);
|
||||
}
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
var id = ID;
|
||||
|
||||
|
||||
Godot.Collections.Dictionary<string, Variant> save = SavegameService.GetSaveData(id);
|
||||
|
||||
if (save.Count > 0)
|
||||
@@ -210,15 +243,15 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
{
|
||||
string[] savePayload = inventoryItemData.AsStringArray();
|
||||
ItemResource resource = ResourceLoader.Load<ItemResource>(savePayload[0]);
|
||||
int _amount = int.Parse(savePayload[1]);
|
||||
|
||||
int _amount = int.Parse(savePayload[1]);
|
||||
|
||||
ItemInstance instance = new ItemInstance { blueprint = resource, amount = _amount };
|
||||
AddItem(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when a new save is created.
|
||||
/// Needs to do a runtime check because the InventoryInstance is already in existence at the beginning of the first scene.
|
||||
@@ -230,5 +263,6 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
slot.itemInstance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
[GlobalClass]
|
||||
public partial class ItemInstance: Resource
|
||||
{
|
||||
[Export] public ItemResource blueprint;
|
||||
[Export] public required ItemResource blueprint;
|
||||
[Export] public int amount = 1;
|
||||
|
||||
public ItemInstance Clone()
|
||||
|
||||
Reference in New Issue
Block a user