Dropping and picking up

This commit is contained in:
Marco 2025-03-28 19:47:10 +01:00
commit bcd007fa1e
14 changed files with 294 additions and 62 deletions

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=75 format=3 uid="uid://c4pr2707hbeph"]
[gd_scene load_steps=83 format=3 uid="uid://c4pr2707hbeph"]
[ext_resource type="Script" uid="uid://d2ubk5gucny6s" path="res://Scripts/Components/FSM/PlayerFSMProxy.cs" id="1_g3wua"]
[ext_resource type="Script" uid="uid://bw2hakslndaxm" path="res://Scripts/Components/FSM/PlayerStateMachine.cs" id="1_mpmil"]
@ -34,6 +34,13 @@
[ext_resource type="Texture2D" uid="uid://ddwhrlrgj6i00" path="res://Sprites/Actors/Cirno.png" id="30_li0ug"]
[ext_resource type="Script" uid="uid://camgjo4302qmq" path="res://Scripts/Components/Actors/ConveyorBeltMover.cs" id="32_4f2wn"]
[ext_resource type="Script" uid="uid://dbxbvjonbtib2" path="res://Scripts/Components/FSM/Player/PlayerStorageModule.cs" id="33_fnw0c"]
[ext_resource type="Script" uid="uid://bcpn47j3lr1tg" path="res://Scripts/Components/FSM/Player/DeathItemDropper.cs" id="35_qlmfy"]
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="36_v2m0j"]
[ext_resource type="Resource" uid="uid://cvlwye1u5gv8u" path="res://Resources/Items/Green_Points_Pickup.tres" id="37_awrib"]
[ext_resource type="Resource" uid="uid://cltxhkrqp055v" path="res://Resources/Items/Money_Pickup.tres" id="38_nfrn8"]
[ext_resource type="Resource" uid="uid://dy53gia1tmkah" path="res://Resources/Items/Points_Pickup.tres" id="39_nfq4p"]
[ext_resource type="Resource" uid="uid://clr1gln7nxa1o" path="res://Resources/Items/Power_Pickup.tres" id="40_m1iep"]
[ext_resource type="Script" uid="uid://c8f4tbcjcfsu1" path="res://Scripts/Components/FSM/Player/AutoPickupModule.cs" id="41_v2m0j"]
[sub_resource type="CircleShape2D" id="CircleShape2D_b3hxm"]
radius = 5.0
@ -308,6 +315,9 @@ _data = {
[sub_resource type="CircleShape2D" id="CircleShape2D_fnw0c"]
radius = 2.05679
[sub_resource type="CircleShape2D" id="CircleShape2D_qlmfy"]
radius = 3.16228
[node name="FSMPlayer" type="CharacterBody2D" node_paths=PackedStringArray("PlayerFSM", "InteractionController")]
process_mode = 1
collision_layer = 2
@ -339,7 +349,7 @@ _damageReceiver = NodePath("../../DamageReceiver")
_activationProvider = NodePath("../../InteractionProvider")
_interactionController = NodePath("../../InteractionController")
_storageModule = NodePath("../../Storage")
_moduleNodes = [NodePath("../../InteractionController"), NodePath("../../ItemUser"), NodePath("../../ConveyorBeltMover")]
_moduleNodes = [NodePath("../../InteractionController"), NodePath("../../ItemUser"), NodePath("../../ConveyorBeltMover"), NodePath("../../AutoPickupModule")]
[node name="Cutscene" type="Node2D" parent="StateMachine" node_paths=PackedStringArray("_animationProvider")]
script = ExtResource("4_22ff8")
@ -462,6 +472,7 @@ shape = SubResource("CircleShape2D_7n10g")
[node name="Error" type="AudioStreamPlayer2D" parent="InteractionProvider"]
stream = ExtResource("24_5tmtw")
bus = &"Effects"
[node name="InteractionController" type="Area2D" parent="." node_paths=PackedStringArray("Health", "Shield")]
visible = false
@ -510,8 +521,25 @@ script = ExtResource("32_4f2wn")
position = Vector2(0, 6.48)
shape = SubResource("CircleShape2D_fnw0c")
[node name="Storage" type="Node2D" parent="."]
[node name="Storage" type="Node2D" parent="." node_paths=PackedStringArray("Root")]
script = ExtResource("33_fnw0c")
Root = NodePath("..")
[node name="DeathItemDropper" type="Node2D" parent="." node_paths=PackedStringArray("Storage", "HealthProvider")]
script = ExtResource("35_qlmfy")
Storage = NodePath("../Storage")
HealthProvider = NodePath("../DamageReceiver/HealthProvider")
ItemsToDrop = Array[ExtResource("36_v2m0j")]([ExtResource("37_awrib"), ExtResource("38_nfrn8"), ExtResource("39_nfq4p"), ExtResource("40_m1iep")])
DropSpeed = 80.0
[node name="AutoPickupModule" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 4
script = ExtResource("41_v2m0j")
[node name="CollisionShape2D" type="CollisionShape2D" parent="AutoPickupModule"]
visible = false
shape = SubResource("CircleShape2D_qlmfy")
[connection signal="area_entered" from="DamageReceiver" to="DamageReceiver" method="_on_damage_hitbox_area_entered"]
[connection signal="area_entered" from="InteractionProvider" to="InteractionProvider" method="_on_interaction_controller_area_entered"]

View file

@ -1,7 +1,9 @@
using Godot;
using System;
using System.Linq;
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Components.FSM;
using Cirno.Scripts.Interactables;
public partial class InteractionController : PlayerArea2DModule
{

View file

@ -2,7 +2,7 @@
[ext_resource type="Texture2D" uid="uid://cybpmpb0d8yva" path="res://Sprites/Projectile.png" id="1_7tn7y"]
[ext_resource type="Script" uid="uid://c4molirtle8a0" path="res://Scripts/Components/AutodeleteParticle.cs" id="2_2y1ka"]
[ext_resource type="AudioStream" uid="uid://euu22u5vf3gc" path="res://SFX/pldead00.wav" id="3_q7v7h"]
[ext_resource type="AudioStream" uid="uid://dsenlumnpx5ei" path="res://SFX/laser01.wav" id="3_m0s7m"]
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_nmvck"]
particle_flag_disable_z = true
@ -15,14 +15,15 @@ scale_max = 4.0
[node name="DeathParticles" type="GPUParticles2D"]
emitting = false
amount = 16
process_material = SubResource("ParticleProcessMaterial_nmvck")
texture = ExtResource("1_7tn7y")
one_shot = true
process_material = SubResource("ParticleProcessMaterial_nmvck")
script = ExtResource("2_2y1ka")
LifeTime = 3.0
AutoStart = true
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_q7v7h")
stream = ExtResource("3_m0s7m")
volume_db = -15.078
autoplay = true
bus = &"Effects"

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=142 format=4 uid="uid://bv451a8wgty4u"]
[gd_scene load_steps=144 format=4 uid="uid://bv451a8wgty4u"]
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_ksslq"]
@ -82,8 +82,10 @@
[ext_resource type="PackedScene" uid="uid://bdvj4cxnyr3w4" path="res://Scenes/Actors/Thermathron.tscn" id="73_ier4h"]
[ext_resource type="PackedScene" uid="uid://c21m7w5ahpsd0" path="res://Scenes/Activable/Shroud.tscn" id="74_oaf68"]
[ext_resource type="PackedScene" uid="uid://d0j1bmgbefyp2" path="res://Scenes/Actors/Lightbridge.tscn" id="75_jn1m0"]
[ext_resource type="Resource" uid="uid://cvlwye1u5gv8u" path="res://Resources/Items/Green_Points_Pickup.tres" id="76_dskij"]
[ext_resource type="Script" uid="uid://crpkvxepkcrir" path="res://Scripts/Components/Actors/ForceFieldCollisionDisabler.cs" id="76_h0jm4"]
[ext_resource type="PackedScene" uid="uid://drdgcu2r3yrp7" path="res://Scenes/Interactable/control_pad_green_keycard.tscn" id="76_usuub"]
[ext_resource type="Resource" uid="uid://cltxhkrqp055v" path="res://Resources/Items/Money_Pickup.tres" id="77_wma5c"]
[ext_resource type="PackedScene" uid="uid://b3tyacxxw88lx" path="res://Scenes/Utils/StreamPlayerWithName.tscn" id="77_yot54"]
[ext_resource type="AudioStream" uid="uid://blohh20jktoyo" path="res://SFX/270641__phantastonia__alarm2.wav" id="79_jn1m0"]
[ext_resource type="PackedScene" uid="uid://dky13otbks8cm" path="res://Scenes/Actors/Thermatron_FSM.tscn" id="80_f37sa"]
@ -127,6 +129,34 @@ size = Vector2(184, 53.25)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jn1m0"]
size = Vector2(23, 22)
[sub_resource type="Resource" id="Resource_xhinl"]
script = ExtResource("98_gvbi8")
BulletResource = ExtResource("95_f37sa")
bulletCount = 1
rotationSpeed = 0.0
_rotationOffset = 0.0
duration = 1.0
spread = 0.0
burstInterval = 0.5
ShotsPerBurst = 100
BurstRate = 0.0
_targetPlayer = false
OverrideOwner = true
Owner = 0
OverrideDamageType = false
DamageType = 0
OverrideControllable = false
Controllable = false
OverrideCreationModifier = false
TimeModifiers = []
WaitForCompletion = true
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
[sub_resource type="Resource" id="Resource_f37sa"]
script = ExtResource("99_j6vrf")
Patterns = Array[Object]([SubResource("Resource_xhinl")])
metadata/_custom_type_script = "uid://bngko08ho85p6"
[sub_resource type="Resource" id="Resource_usuub"]
script = ExtResource("49_0si7g")
Target = NodePath("..")
@ -250,34 +280,6 @@ _data = {
}
point_count = 2
[sub_resource type="Resource" id="Resource_xhinl"]
script = ExtResource("98_gvbi8")
BulletResource = ExtResource("95_f37sa")
bulletCount = 1
rotationSpeed = 0.0
_rotationOffset = 0.0
duration = 1.0
spread = 0.0
burstInterval = 0.5
ShotsPerBurst = 100
BurstRate = 0.0
_targetPlayer = false
OverrideOwner = true
Owner = 0
OverrideDamageType = false
DamageType = 0
OverrideControllable = false
Controllable = false
OverrideCreationModifier = false
TimeModifiers = []
WaitForCompletion = true
metadata/_custom_type_script = "uid://c0ndqalsc4jve"
[sub_resource type="Resource" id="Resource_f37sa"]
script = ExtResource("99_j6vrf")
Patterns = Array[Object]([SubResource("Resource_xhinl")])
metadata/_custom_type_script = "uid://bngko08ho85p6"
[sub_resource type="Resource" id="Resource_l476f"]
script = ExtResource("45_emjoj")
ActivationType = 5
@ -427,11 +429,11 @@ Target = NodePath("../BulletEmitter2")
position = Vector2(-565, -399)
[node name="Marisa" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("50_mp5ma")]
position = Vector2(-615, -565)
position = Vector2(-605, -680)
CameraOffset = Vector2(-50, 0)
[node name="ControlPad" parent="Parallax2D/Factory Tilemaps/Debug Room" node_paths=PackedStringArray("Target") instance=ExtResource("12_hfkf1")]
position = Vector2(-615, -495)
position = Vector2(-605, -610)
Target = NodePath("../Marisa")
[node name="Label2" type="Label" parent="Parallax2D/Factory Tilemaps/Debug Room"]
@ -588,6 +590,19 @@ position = Vector2(-1792, -99)
[node name="BigTank3" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("45_5qg27")]
position = Vector2(-1832, -99)
[node name="Chest2" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("25_4b2ed")]
position = Vector2(-679, -408)
LootTable = Array[ExtResource("6_8tdlb")]([ExtResource("76_dskij"), ExtResource("77_wma5c"), ExtResource("6_khabp"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("94_gd7x4"), ExtResource("6_khabp"), ExtResource("6_khabp"), ExtResource("6_khabp"), ExtResource("6_khabp"), ExtResource("6_khabp"), ExtResource("77_wma5c"), ExtResource("77_wma5c"), ExtResource("77_wma5c"), ExtResource("77_wma5c"), ExtResource("76_dskij")])
[node name="Valve" parent="Parallax2D/Factory Tilemaps/Debug Room" node_paths=PackedStringArray("Target") instance=ExtResource("48_8usll")]
position = Vector2(-666, -545)
Target = NodePath("../InvisibleBulletEmitter")
[node name="InvisibleBulletEmitter" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("96_ygp23")]
position = Vector2(-645, -564)
rotation = -1.5708
Script = SubResource("Resource_f37sa")
[node name="Part2" type="Node2D" parent="Parallax2D/Factory Tilemaps"]
[node name="Mainframe" parent="Parallax2D/Factory Tilemaps/Part2" instance=ExtResource("13_acrmt")]
@ -1020,9 +1035,6 @@ scale = Vector2(318.5, 284.25)
position = Vector2(-1010, -50)
scale = Vector2(56, 174)
[node name="Chest2" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("25_4b2ed")]
position = Vector2(-679, -408)
[node name="Ammo5" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("34_17pjh")]
position = Vector2(-936, 68)

View file

@ -34,8 +34,6 @@ public partial class EnemyDropsProvider : Node2D
private void DropItem(LootItem item)
{
if (!string.IsNullOrWhiteSpace(item.DropScenePath))
{
GD.Print($"Dropped item: {item.ItemName}");

View file

@ -7,11 +7,13 @@ using Godot.Collections;
namespace Cirno.Scripts.Components.FSM.Enemy;
public partial class EnemyStorageModule : Node2D
public partial class EnemyStorageModule : Node2D, IFSMStorage
{
[Export]
public EnemyFSMProxy Root { get; private set; }
public Node2D RootAsNode => Root;
public EnemyResource EnemyData => Root.EnemyResource;
public Vector2 MovementDirection { get; set; }

View file

@ -0,0 +1,11 @@
using System.Collections.Generic;
using Cirno.Scripts.Resources.Loot;
using Godot;
namespace Cirno.Scripts.Components.FSM;
public interface IFSMStorage
{
public IEnumerable<LootDrop> LootDrops { get; }
public Node2D RootAsNode { get; }
}

View file

@ -0,0 +1,66 @@
using System.Linq;
using Cirno.Scripts.Interactables;
using Godot;
namespace Cirno.Scripts.Components.FSM.Player;
public partial class AutoPickupModule : PlayerArea2DModule
{
private bool _enabled = false;
public bool Enabled
{
get => _enabled;
set
{
if (_enabled == value) return;
_enabled = value;
// if (_enabled)
// {
// EmitSignal(SignalName.InteractionStarted);
// }
}
}
public override void Init(IStateMachine<PlayerState, CharacterBody2D> machine)
{
base.Init(machine);
}
public override void EnterState(PlayerState state)
{
Enabled = true;
this.AreaEntered += _on_area_entered;
}
public override void ExitState(PlayerState state)
{
Enabled = false;
this.AreaEntered -= _on_area_entered;
}
public override void Process(double delta)
{
}
public override void PhysicsProcess(double delta)
{
}
private void _on_area_entered(Area2D area)
{
if (!Enabled) return;
if (area is ItemPickup { AutoPickup: true } itemPickup)
{
//Check if items are not maxed to avoid a looping autopickup situation
var canAdd = itemPickup.LootTable.Aggregate(false, (current, item) => current || InventoryManager.Instance.CanAddItem(item.ItemKey));
if (canAdd)
{
itemPickup.Collect();
}
}
}
}

View file

@ -0,0 +1 @@
uid://c8f4tbcjcfsu1

View file

@ -0,0 +1,75 @@
using Cirno.Scripts.Components.Actors;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Components.FSM.Player;
public partial class DeathItemDropper : Node2D
{
[Export] public PlayerStorageModule Storage { get; private set; }
[Export] public ActorResourceProvider HealthProvider { get; private set; }
[Export] public Array<LootItem> ItemsToDrop { get; private set; } = [];
[Export(PropertyHint.None, "suffix:%")] public float PercentageToDrop { get; private set; } = 50f;
[Export(PropertyHint.None, "suffix:%")] public float PercentageToDelete { get; private set; } = 50f;
private readonly StringName _dropPhysicsWrapperScene = "uid://d3hds3dbosfcm";
[Export] public float DropRadius { get; private set; } = 8f;
[Export] public float DropSpeed { get; set; } = 40f;
private PackedScene _loadedDropScene;
public override void _Ready()
{
HealthProvider.ResourceDepleted += HealthProviderOnResourceDepleted;
_loadedDropScene = GD.Load<PackedScene>(_dropPhysicsWrapperScene);
}
public override void _ExitTree()
{
HealthProvider.ResourceDepleted -= HealthProviderOnResourceDepleted;
}
private void HealthProviderOnResourceDepleted()
{
foreach (var item in ItemsToDrop)
{
if (InventoryManager.Instance.TryGetItem(item.ItemKey, out var itm))
{
var amountToDrop = Mathf.RoundToInt(itm.Count * PercentageToDrop / 100f);
var removedAmount = InventoryManager.Instance.RemoveItem(item.ItemKey, amountToDrop);
var toDelete = Mathf.RoundToInt(removedAmount * PercentageToDelete / 100f);
DropItem(item, removedAmount - toDelete);
}
}
}
private void DropItem(LootItem item, int amountToDrop)
{
if (!string.IsNullOrWhiteSpace(item.DropScenePath))
{
for (int i = 0; i < amountToDrop; i++)
{
GD.Print($"Dropped item: {item.ItemName}");
var dropInstance = Storage.Root.CreateSibling<ItemDrop>(_loadedDropScene);
dropInstance.ItemToDrop = item;
dropInstance.StartingSpeed = DropSpeed;
}
}
else
{
GD.Print($"Skipping Item with missing path: {item.ItemName}");
}
}
}

View file

@ -0,0 +1 @@
uid://bcpn47j3lr1tg

View file

@ -4,5 +4,9 @@ namespace Cirno.Scripts.Components.FSM.Player;
public partial class PlayerStorageModule : Node2D
{
[Export]
public PlayerFSMProxy Root { get; private set; }
public Node2D RootAsNode => Root;
public Vector2 FacingDirection { get; set; }
}

View file

@ -16,6 +16,8 @@ public partial class ItemDrop : RigidBody2D
Node dropInstance = dropScene.Instantiate();
AddChild(dropInstance);
dropInstance.Owner = this;
float angle = _rng.RandfRange(0, Mathf.Tau); // 0 to 2π
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)).Normalized();

View file

@ -2,6 +2,8 @@
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
using GTweens.Builders;
using GTweensGodot.Extensions;
namespace Cirno.Scripts.Interactables;
@ -11,6 +13,10 @@ public partial class ItemPickup : Interactable
private bool _autoPickup = false;
public bool AutoPickup => _autoPickup;
public ItemDrop Parent { get; set; } = null;
public override void _Ready()
{
_autoPickup = LootTable.Any(x => x.AutoPickup);
@ -27,12 +33,12 @@ public partial class ItemPickup : Interactable
GD.Print("Attempting to Pickup Item");
if (!MeetsRequirements()) return false;
AddItemsToInventory();
Collect();
return true;
}
private void AddItemsToInventory()
public void AddItemsToInventory()
{
var failedItems = new Array<LootItem>();
foreach (var item in LootTable)
@ -54,21 +60,44 @@ public partial class ItemPickup : Interactable
}
// Delet This
QueueFree();
}
public void Collect()
{
AddItemsToInventory();
// if (Owner is ItemDrop dropWrapper)
// {
// // move the wrapper
// var tween = GTweenSequenceBuilder.New()
// .Append(dropWrapper.TweenGlobalPosition(GameManager.Instance.PlayerPosition.Value, 0.5f))
// .AppendCallback(() =>
// {
// AddItemsToInventory();
// Owner.QueueFree();
// })
// .Build();
// }
// else
// {
// // move this
//
// }
}
private void _on_area_entered(Area2D area)
{
if (!_autoPickup) return;
if (area is InteractionController interactionController)
{
//Check if items are not maxed to avoid a looping autopickup situation
var canAdd = LootTable.Aggregate(false, (current, item) => current || InventoryManager.Instance.CanAddItem(item.ItemKey));
if (canAdd)
{
AddItemsToInventory();
}
}
// if (!_autoPickup) return;
// if (area is InteractionController interactionController)
// {
// //Check if items are not maxed to avoid a looping autopickup situation
// var canAdd = LootTable.Aggregate(false, (current, item) => current || InventoryManager.Instance.CanAddItem(item.ItemKey));
//
// if (canAdd)
// {
// AddItemsToInventory();
// }
// }
}
}