Fix some boxes and global positioning

This commit is contained in:
2026-02-26 22:56:57 -08:00
parent 0c4a424a4d
commit 721a45c6bb
12 changed files with 83 additions and 14 deletions

View File

@@ -20,8 +20,17 @@ public partial class BoxItemTagEnumContext : JsonSerializerContext;
[JsonSerializable(typeof(ElementType))] [JsonSerializable(typeof(ElementType))]
public partial class ElementTypeEnumContext : JsonSerializerContext; public partial class ElementTypeEnumContext : JsonSerializerContext;
[JsonSerializable(typeof(JewelTags))]
public partial class JewelTagsEnumContext : JsonSerializerContext;
[JsonSerializable(typeof(IBaseInventoryItem))] [JsonSerializable(typeof(IBaseInventoryItem))]
public partial class BaseInventoryItemContext : JsonSerializerContext public partial class BaseInventoryItemContext : JsonSerializerContext
{ {
} }
[JsonSerializable(typeof(RescuedItemDatabase))]
public partial class RescuedItemDatabaseContext : JsonSerializerContext
{
}

View File

@@ -229,11 +229,12 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
protected void LookAtTarget(Vector3 targetPosition) protected void LookAtTarget(Vector3 targetPosition)
{ {
if (GlobalPosition.IsEqualApprox(targetPosition)) var target = new Vector3(GlobalPosition.X, targetPosition.Y, GlobalPosition.Z);
if (target.IsEqualApprox(targetPosition))
return; return;
var lookDirection = GlobalPosition - targetPosition; var lookDirection = target - targetPosition;
var look = new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z); var look = new Vector3(lookDirection.X, GlobalPosition.Y, lookDirection.Z);
if (GlobalPosition.DistanceTo(look) > 0.01) if (target.DistanceTo(look) > 0.01)
LookAt(look, Vector3.Up); LookAt(look, Vector3.Up);
} }

View File

@@ -39,7 +39,7 @@ public partial class FleeBehavior : Node3D, IBehavior
var rooms = _game.CurrentFloor.Rooms; var rooms = _game.CurrentFloor.Rooms;
var validRooms = new Godot.Collections.Array<MonsterRoom>(rooms.OfType<MonsterRoom>()); var validRooms = new Godot.Collections.Array<MonsterRoom>(rooms.OfType<MonsterRoom>());
var randomRoom = validRooms.PickRandom(); var randomRoom = validRooms.PickRandom();
_navigationAgent.TargetPosition = randomRoom.PlayerSpawn.GlobalPosition; _navigationAgent.TargetPosition = new Vector3(randomRoom.PlayerSpawn.GlobalPosition.X, GlobalPosition.Y, randomRoom.PlayerSpawn.GlobalPosition.Z);
SetPhysicsProcess(true); SetPhysicsProcess(true);
} }

View File

@@ -37,11 +37,11 @@ public partial class FollowBehavior : Node3D, IBehavior
SetPhysicsProcess(false); SetPhysicsProcess(false);
} }
private void OnTimeout() => _navigationAgent.TargetPosition = _player.GlobalPosition; private void OnTimeout() => _navigationAgent.TargetPosition = new Vector3(_player.GlobalPosition.X, GlobalPosition.Y, _player.GlobalPosition.Z);
public void StartFollow(NavigationAgent3D navigationAgent) public void StartFollow(NavigationAgent3D navigationAgent)
{ {
_navigationAgent.TargetPosition = _player.GlobalPosition; _navigationAgent.TargetPosition = new Vector3(_player.GlobalPosition.X, GlobalPosition.Y, _player.GlobalPosition.Z);
_thinkTimer.Start(); _thinkTimer.Start();
SetPhysicsProcess(true); SetPhysicsProcess(true);
} }
@@ -56,7 +56,8 @@ public partial class FollowBehavior : Node3D, IBehavior
{ {
var nextVelocity = _navigationAgent.GetNextPathPosition(); var nextVelocity = _navigationAgent.GetNextPathPosition();
var parent = GetParent() as Node3D; var parent = GetParent() as Node3D;
var velocity = parent.GlobalPosition.DirectionTo(nextVelocity) * (float)_followSpeed * (float)delta; var position = new Vector3(parent.GlobalPosition.X, GlobalPosition.Y, parent.GlobalPosition.Z);
var velocity = position.DirectionTo(nextVelocity) * (float)_followSpeed * (float)delta;
EmitSignal(SignalName.OnVelocityComputed, velocity); EmitSignal(SignalName.OnVelocityComputed, velocity);
} }

View File

@@ -72,7 +72,8 @@ public partial class PatrolBehavior : Node3D, IBehavior
{ {
var nextVelocity = _navigationAgent.GetNextPathPosition(); var nextVelocity = _navigationAgent.GetNextPathPosition();
var parent = GetParent() as Node3D; var parent = GetParent() as Node3D;
var velocity = parent.GlobalPosition.DirectionTo(nextVelocity) * (float)_patrolSpeed * (float)delta; var position = new Vector3(parent.GlobalPosition.X, GlobalPosition.Y, parent.GlobalPosition.Z);
var velocity = position.DirectionTo(nextVelocity) * (float)_patrolSpeed * (float)delta;
EmitSignal(SignalName.OnVelocityComputed, velocity); EmitSignal(SignalName.OnVelocityComputed, velocity);
} }

View File

@@ -42,7 +42,8 @@ public partial class FilthEater : Enemy2D, IHavePatrolBehavior, IHaveEngagePlaye
public override void PerformAction() public override void PerformAction()
{ {
if (GlobalPosition.DistanceTo(_player.GlobalPosition) > 3) var enemyPosition = new Vector3(GlobalPosition.X, _player.GlobalPosition.Y, GlobalPosition.Z);
if (enemyPosition.DistanceTo(_player.GlobalPosition) > 3)
EnemyModelView.PlaySecondaryAttackAnimation(); EnemyModelView.PlaySecondaryAttackAnimation();
else else
EnemyModelView.PlayPrimaryAttackAnimation(); EnemyModelView.PlayPrimaryAttackAnimation();

View File

@@ -468,6 +468,16 @@ public partial class Game : Node3D, IGame
case ItemTag.DropTo1HPAndGainRareItem: case ItemTag.DropTo1HPAndGainRareItem:
_effectService.DropTo1HPAndGainRareItem<IBaseInventoryItem>(); _effectService.DropTo1HPAndGainRareItem<IBaseInventoryItem>();
break; break;
case ItemTag.TradeOneRandomItem:
var itemsWithoutBox = _player.Inventory.Items.Where(x => x != boxItem).ToList();
var rng = new RandomNumberGenerator();
rng.Randomize();
var index = rng.RandiRange(0, itemsWithoutBox.Count - 1);
var randomItem = itemsWithoutBox[index];
_player.Inventory.Remove(randomItem);
var newItem = _effectService.GetRandomItemOfType<IBaseInventoryItem>();
_player.Inventory.TryAdd(newItem);
break;
case ItemTag.TradeAllRandomItems: case ItemTag.TradeAllRandomItems:
var newInventory = _effectService.TradeAllRandomItems(boxItem); var newInventory = _effectService.TradeAllRandomItems(boxItem);
_player.Inventory.Items.Clear(); _player.Inventory.Items.Clear();

View File

@@ -93,7 +93,8 @@ public partial class Inventory : Node, IInventory
var effectItems = listToSort.Where(x => x is EffectItem).OrderBy(x => x as EffectItem, new EffectComparer()); var effectItems = listToSort.Where(x => x is EffectItem).OrderBy(x => x as EffectItem, new EffectComparer());
var jewelItems = listToSort.Where(x => x is Jewel).OrderBy(x => x as Jewel, new JewelComparer()); var jewelItems = listToSort.Where(x => x is Jewel).OrderBy(x => x as Jewel, new JewelComparer());
var setItems = listToSort.Where(x => x is Plastique).OrderBy(x => x as Plastique, new SetItemComparer()); var setItems = listToSort.Where(x => x is Plastique).OrderBy(x => x as Plastique, new SetItemComparer());
Items = [.. equippedItems, .. weapons, .. armor, .. accessories, .. ammo, .. consumables, .. throwables, .. effectItems, .. jewelItems, .. setItems]; var boxItems = listToSort.Where(x => x is BoxItem).OrderBy(x => x as BoxItem, new BoxItemComparer());
Items = [.. equippedItems, .. weapons, .. armor, .. accessories, .. ammo, .. consumables, .. throwables, .. effectItems, .. jewelItems, ..boxItems, .. setItems];
var stackableItems = Items.OfType<IStackable>(); var stackableItems = Items.OfType<IStackable>();
var itemsToStack = stackableItems.GroupBy(x => ((IBaseInventoryItem)x).ItemName).Where(x => x.Count() > 1); var itemsToStack = stackableItems.GroupBy(x => ((IBaseInventoryItem)x).ItemName).Where(x => x.Count() > 1);
@@ -163,6 +164,14 @@ public partial class Inventory : Node, IInventory
} }
} }
public class BoxItemComparer : IComparer<BoxItem>
{
public int Compare(BoxItem x, BoxItem y)
{
return x.ItemName.CompareTo(y.ItemName);
}
}
public class ConsumableComparer : IComparer<ConsumableItem> public class ConsumableComparer : IComparer<ConsumableItem>
{ {
public int Compare(ConsumableItem x, ConsumableItem y) public int Compare(ConsumableItem x, ConsumableItem y)

View File

@@ -21,7 +21,6 @@ public partial class Ammo : Node3D, IEquipableItem, IStackable
_sprite.Texture = Stats.Texture; _sprite.Texture = Stats.Texture;
} }
public string ItemName => Stats.Name; public string ItemName => Stats.Name;
public string FlavorText => Stats.FlavorText; public string FlavorText => Stats.FlavorText;
@@ -39,7 +38,7 @@ public partial class Ammo : Node3D, IEquipableItem, IStackable
public Texture2D GetTexture() => Stats.Texture; public Texture2D GetTexture() => Stats.Texture;
[Save("ammo_item_count")] [Save("ammo_item_count")]
public AutoProp<int> Count { get; private set; } public AutoProp<int> Count { get; private set; } = new AutoProp<int>(3);
public void SetCount(int count) => Count.OnNext(count); public void SetCount(int count) => Count.OnNext(count);

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=1591 format=3 uid="uid://cfecvvav8kkp6"] [gd_scene load_steps=1596 format=3 uid="uid://cfecvvav8kkp6"]
[ext_resource type="Script" uid="uid://yxmiqy7i0t7r" path="res://src/player/Player.cs" id="1_xcol5"] [ext_resource type="Script" uid="uid://yxmiqy7i0t7r" path="res://src/player/Player.cs" id="1_xcol5"]
[ext_resource type="PackedScene" uid="uid://dqvlemme0iwa" path="res://src/camera/ShakeCamera.tscn" id="2_jtmj1"] [ext_resource type="PackedScene" uid="uid://dqvlemme0iwa" path="res://src/camera/ShakeCamera.tscn" id="2_jtmj1"]
@@ -542,6 +542,7 @@
[ext_resource type="Texture2D" uid="uid://cl2woq73pn2ab" path="res://src/vfx/Weapon Strikes/hydric_attack/tile027.png" id="527_nilvr"] [ext_resource type="Texture2D" uid="uid://cl2woq73pn2ab" path="res://src/vfx/Weapon Strikes/hydric_attack/tile027.png" id="527_nilvr"]
[ext_resource type="Texture2D" uid="uid://d3e8jnj7q6sdk" path="res://src/vfx/Weapon Strikes/hydric_attack/tile028.png" id="528_ynv1q"] [ext_resource type="Texture2D" uid="uid://d3e8jnj7q6sdk" path="res://src/vfx/Weapon Strikes/hydric_attack/tile028.png" id="528_ynv1q"]
[ext_resource type="Texture2D" uid="uid://def40t23awj4c" path="res://src/vfx/Weapon Strikes/hydric_attack/tile029.png" id="529_3e7br"] [ext_resource type="Texture2D" uid="uid://def40t23awj4c" path="res://src/vfx/Weapon Strikes/hydric_attack/tile029.png" id="529_3e7br"]
[ext_resource type="Script" uid="uid://ctshiyffvt4y5" path="res://src/system/AttackDataResource.cs" id="543_cqsul"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dw45s"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dw45s"]
radius = 1.0 radius = 1.0
@@ -10442,6 +10443,30 @@ animations = [{
"speed": 24.0 "speed": 24.0
}] }]
[sub_resource type="Resource" id="Resource_w5dir"]
script = ExtResource("543_cqsul")
Damage = 25
ElementType = 4
metadata/_custom_type_script = "uid://ctshiyffvt4y5"
[sub_resource type="Resource" id="Resource_7rguc"]
script = ExtResource("543_cqsul")
Damage = 25
ElementType = 1
metadata/_custom_type_script = "uid://ctshiyffvt4y5"
[sub_resource type="Resource" id="Resource_cqsul"]
script = ExtResource("543_cqsul")
Damage = 25
ElementType = 3
metadata/_custom_type_script = "uid://ctshiyffvt4y5"
[sub_resource type="Resource" id="Resource_ajbah"]
script = ExtResource("543_cqsul")
Damage = 99
ElementType = 0
metadata/_custom_type_script = "uid://ctshiyffvt4y5"
[node name="Player" type="CharacterBody3D"] [node name="Player" type="CharacterBody3D"]
collision_layer = 802 collision_layer = 802
collision_mask = 775 collision_mask = 775
@@ -10656,16 +10681,20 @@ stream = ExtResource("6_v7rlw")
[node name="FireReactor" parent="Projectiles" instance=ExtResource("509_14f5p")] [node name="FireReactor" parent="Projectiles" instance=ExtResource("509_14f5p")]
unique_name_in_owner = true unique_name_in_owner = true
AttackData = SubResource("Resource_w5dir")
[node name="AirReactor" parent="Projectiles" instance=ExtResource("510_k6pkx")] [node name="AirReactor" parent="Projectiles" instance=ExtResource("510_k6pkx")]
unique_name_in_owner = true unique_name_in_owner = true
AttackData = SubResource("Resource_7rguc")
[node name="WaterReactor" parent="Projectiles" instance=ExtResource("511_sq73w")] [node name="WaterReactor" parent="Projectiles" instance=ExtResource("511_sq73w")]
unique_name_in_owner = true unique_name_in_owner = true
AttackData = SubResource("Resource_cqsul")
[node name="PersuaderBullet" parent="Projectiles" instance=ExtResource("512_k6pkx")] [node name="PersuaderBullet" parent="Projectiles" instance=ExtResource("512_k6pkx")]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.125) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.125)
AttackData = SubResource("Resource_ajbah")
[node name="BulletSFX" type="AudioStreamPlayer3D" parent="Projectiles/PersuaderBullet/Bullet/ProjectileHitbox" index="1"] [node name="BulletSFX" type="AudioStreamPlayer3D" parent="Projectiles/PersuaderBullet/Bullet/ProjectileHitbox" index="1"]
process_mode = 3 process_mode = 3

View File

@@ -22,7 +22,7 @@ public sealed class MaSaveFileManager : IMaSaveFileManager
public MaSaveFileManager() public MaSaveFileManager()
{ {
_saveFileManager = new SaveFileManager(new FileSystem()); _saveFileManager = new SaveFileManager(new FileSystem());
_converters = [WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default, BaseInventoryItemContext.Default]; _converters = [WeaponTagEnumContext.Default, ItemTagEnumContext.Default, ElementTypeEnumContext.Default, AccessoryTagEnumContext.Default, UsableItemTagEnumContext.Default, BoxItemTagEnumContext.Default, JewelTagsEnumContext.Default, BaseInventoryItemContext.Default, RescuedItemDatabaseContext.Default];
} }
public async Task Save<T>(T gameData) public async Task Save<T>(T gameData)

View File

@@ -85,6 +85,15 @@ public partial class InventoryMenu : Control, IInventoryMenu
SfxDatabase.Instance.Play(SoundEffect.MoveUI); SfxDatabase.Instance.Play(SoundEffect.MoveUI);
if (Input.IsActionJustPressed(GameInputs.Interact)) if (Input.IsActionJustPressed(GameInputs.Interact))
SfxDatabase.Instance.Play(SoundEffect.CancelUI); SfxDatabase.Instance.Play(SoundEffect.CancelUI);
if (Input.IsActionJustPressed(GameInputs.InventorySort))
{
var sorted = _player.Inventory.Sort(_player.EquipmentComponent.EquippedWeapon.Value, _player.EquipmentComponent.EquippedArmor.Value, _player.EquipmentComponent.EquippedAccessory.Value, _player.EquipmentComponent.EquippedAmmo.Value);
if (sorted)
{
ResetInventoryState();
SfxDatabase.Instance.Play(SoundEffect.SortInventory);
}
}
} }
private void ActionPanel_AugmentMenuRequested() private void ActionPanel_AugmentMenuRequested()