Add more spell effects

This commit is contained in:
2026-02-26 02:09:38 -08:00
parent a686ce2fbc
commit fadb1652d4
20 changed files with 163 additions and 49 deletions

View File

@@ -180,7 +180,11 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
{
_morphSFX.Play();
SetPhysicsProcess(false);
Die();
_player.ExperiencePointsComponent.Gain(ExpGiven);
EnemyModelView.PlayDeathAnimation();
var tweener = CreateTween();
tweener.TweenInterval(1.0f);
tweener.TweenCallback(Callable.From(QueueFree));
}
public IDungeonRoom GetCurrentRoom(ImmutableList<IDungeonRoom> roomList)

View File

@@ -15,13 +15,14 @@ height = 5.0
radius = 1.0
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_0h5s2"]
radius = 0.34933
height = 2.66932
[sub_resource type="CylinderShape3D" id="CylinderShape3D_eek1b"]
radius = 1.0
[sub_resource type="SphereShape3D" id="SphereShape3D_wrps7"]
radius = 1.0
radius = 0.552847
[node name="Michael" type="CharacterBody3D" groups=["enemy"]]
process_mode = 1

View File

@@ -10,7 +10,7 @@
[ext_resource type="AudioStream" uid="uid://bf7adfdd857hw" path="res://src/audio/sfx/enemy_morph.ogg" id="8_jvw36"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_cwfph"]
radius = 1.6
radius = 0.90501
height = 3.2
[sub_resource type="CylinderShape3D" id="CylinderShape3D_jbgmx"]

View File

@@ -91,7 +91,7 @@ public partial class Game : Node3D, IGame
GameState = _container.GetInstance<IGameState>();
QuestData = new QuestData();
RescuedItems = new RescuedItemDatabase();
RescuedItems = new RescuedItemDatabase(20);
ItemDatabase = ItemDatabase.Instance;
GameChunk = new SaveChunk<GameData>(
@@ -99,10 +99,7 @@ public partial class Game : Node3D, IGame
{
var gameData = new GameData()
{
RescuedItems = new RescuedItemDatabase()
{
Items = RescuedItems.Items
},
RescuedItems = new RescuedItemDatabase(RescuedItems.GetItems(), 20),
QuestData = new QuestData()
{
DeathCount = QuestData.DeathCount,
@@ -462,6 +459,9 @@ public partial class Game : Node3D, IGame
case ItemTag.ContainsBox:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<BoxItem>());
break;
case ItemTag.RandomSpell:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<EffectItem>());
break;
case ItemTag.ContainsRestorative:
_player.Inventory.TryAdd(_effectService.GetRandomItemOfType<ConsumableItem>());
break;
@@ -502,7 +502,6 @@ public partial class Game : Node3D, IGame
ThrowItem(item);
_player.Inventory.Items.Clear();
GameRepo.CloseInventory();
break;
}
}
@@ -581,7 +580,7 @@ public partial class Game : Node3D, IGame
_effectService.LowerCurrentArmorDefense();
break;
case UsableItemTag.RandomEffect:
_effectService.RandomEffect(effectItem);
_effectService.RandomEffect();
break;
case UsableItemTag.DoubleExp:
_effectService.DoubleExp();
@@ -641,7 +640,23 @@ public partial class Game : Node3D, IGame
_player.HealthComponent.SetCurrentHealth(1);
SfxDatabase.Instance.Play(SoundEffect.DecreaseStat);
break;
case UsableItemTag.DoubleStackedItems:
var stackableItems = _player.Inventory.Items.OfType<IStackable>().ToList();
stackableItems.ForEach(x => x.Count.OnNext(x.Count.Value * 2));
break;
case UsableItemTag.IdentifyRandomItem:
var unidentifiedItems = _player.Inventory.Items.Where(x => x.ItemTag == ItemTag.MysteryItem).ToList();
if (!unidentifiedItems.Any())
return;
var rng = new RandomNumberGenerator();
rng.Randomize();
var index = rng.RandiRange(0, unidentifiedItems.Count - 1);
_player.IdentifyItem(unidentifiedItems[index]);
break;
}
_player.EquipmentComponent.UpdateEquipment(_player.EquipmentComponent.EquippedWeapon.Value);
_player.EquipmentComponent.UpdateEquipment(_player.EquipmentComponent.EquippedArmor.Value);
_player.EquipmentComponent.UpdateEquipment(_player.EquipmentComponent.EquippedAccessory.Value);
}
private void RemoveItemOrSubtractFromItemCount(IBaseInventoryItem item)

View File

@@ -41,7 +41,7 @@ public partial class RescuedItems : Node3D
public void SpawnRescuedItems()
{
foreach (var item in Game.RescuedItems.Items)
foreach (var item in Game.RescuedItems.GetItems().ToList())
{
var droppedScene = GD.Load<PackedScene>("res://src/items/dropped/DroppedItem.tscn");
var dropped = droppedScene.Instantiate<DroppedItem>();
@@ -51,7 +51,7 @@ public partial class RescuedItems : Node3D
SpawnLocations.Remove(SpawnLocations.First());
}
Game.RescuedItems.Items.Clear();
Game.RescuedItems.Clear();
}
public override void _ExitTree() => base._ExitTree();

View File

@@ -95,6 +95,7 @@ public class EffectService
currentRoom.EnemiesInRoom.ForEach(e => e.HealthComponent.SetCurrentHealth(e.HealthComponent.MaximumHP.Value));
_player.HealthComponent.SetCurrentHealth(_player.HealthComponent.MaximumHP.Value);
SfxDatabase.Instance.Play(SoundEffect.HealHP);
}
public void AbsorbHPFromAllEnemiesInRoom()
@@ -108,7 +109,7 @@ public class EffectService
var hpToAbsorb = 0.0;
foreach (var enemy in currentEnemies)
{
var absorbAmount = enemy.HealthComponent.MaximumHP.Value * 0.05;
var absorbAmount = enemy.HealthComponent.CurrentHP.Value * 0.25;
enemy.HealthComponent.Damage((int)absorbAmount);
hpToAbsorb += absorbAmount;
enemy.OnAbsorb();
@@ -134,22 +135,24 @@ public class EffectService
public void SwapHPandVT()
{
var oldHp = _player.HealthComponent.CurrentHP.Value;
var oldVt = _player.VTComponent.CurrentVT.Value;
var oldHp = Mathf.Max(1, _player.HealthComponent.CurrentHP.Value);
var oldVt = Mathf.Max(1, _player.VTComponent.CurrentVT.Value);
_player.HealthComponent.SetCurrentHealth(oldVt);
_player.VTComponent.SetVT(oldHp);
SfxDatabase.Instance.Play(SoundEffect.SwapHPAndVT);
}
public void RandomEffect(EffectItem item)
public void RandomEffect()
{
var itemEffects = Enum.GetValues<UsableItemTag>().ToList();
itemEffects.Remove(UsableItemTag.RandomEffect);
itemEffects.Remove(UsableItemTag.None);
var randomEffect = new Godot.Collections.Array<UsableItemTag>(itemEffects).PickRandom();
item.SetEffectTag(randomEffect);
_game.UseItem(item);
var spells = _player.Inventory.Items.OfType<EffectItem>().Where(x => x.UsableItemTag != UsableItemTag.RandomEffect).ToList();
if (spells.Count > 0)
{
var rng = new RandomNumberGenerator();
rng.Randomize();
var index = rng.RandiRange(0, spells.Count - 1);
_game.UseItem(spells[index]);
}
}
public void DoubleExp()
@@ -308,7 +311,7 @@ public class EffectService
var roomsGodotCollection = new Godot.Collections.Array<MonsterRoom>(validRooms);
var randomRoom = roomsGodotCollection.PickRandom();
var spawnPoint = randomRoom.PlayerSpawn;
player.TeleportPlayer((spawnPoint.Rotation, new Vector3(spawnPoint.Position.X, 0, spawnPoint.Position.Z)));
player.TeleportPlayer((spawnPoint.Rotation, new Vector3(spawnPoint.GlobalPosition.X, _player.GlobalPosition.Y, spawnPoint.GlobalPosition.Z)));
SfxDatabase.Instance.Play(SoundEffect.TeleportToRandomRoom);
}
@@ -318,7 +321,8 @@ public class EffectService
if (exitRoom.PlayerDiscoveredRoom)
{
SfxDatabase.Instance.Play(SoundEffect.TeleportToExit);
_player.TeleportPlayer((exitRoom.PlayerSpawn.Rotation, exitRoom.PlayerSpawn.Position));
var exitPoint = exitRoom.PlayerSpawn.GlobalPosition;
_player.TeleportPlayer((exitRoom.PlayerSpawn.Rotation, new Vector3(exitPoint.X, _player.GlobalPosition.Y, exitPoint.Z)));
}
}
@@ -336,9 +340,14 @@ public class EffectService
public T GetRandomItemOfType<T>(params T[] itemsToExclude)
where T : IBaseInventoryItem => ItemDatabase.Instance.PickItem(itemsToExclude);
public void RandomSpell()
public void RandomSpell(EffectItem item)
{
throw new NotImplementedException("Spells not implemented yet.");
var itemEffects = Enum.GetValues<UsableItemTag>().ToList();
itemEffects.Remove(UsableItemTag.RandomEffect);
itemEffects.Remove(UsableItemTag.None);
var randomEffect = new Godot.Collections.Array<UsableItemTag>(itemEffects).PickRandom();
item.SetEffectTag(randomEffect);
_game.UseItem(item);
}
public void DropTo1HPAndGainRareItem<T>()

View File

@@ -44,7 +44,9 @@ public class ItemDatabase
rng.Randomize();
if (itemsToExclude.Any())
itemsToSelectFrom.Except(itemsToExclude);
itemsToSelectFrom = itemsToSelectFrom.Except(itemsToExclude);
itemsToSelectFrom = itemsToSelectFrom.Where(x => x.ItemTag != ItemTag.MysteryItem);
var weights = itemsToSelectFrom.Select(x => x.SpawnRate).ToArray();
var selectedItem = itemsToSelectFrom.ToArray()[rng.RandWeighted(weights)];

View File

@@ -48,12 +48,13 @@ public partial class DroppedItem : RigidBody3D, IDroppedItem
public void RescueItem()
{
if (!Game.RescuedItems.TryAdd(Item))
return;
ContactMonitor = false;
Pickup.SetDeferred(Area3D.PropertyName.Monitorable, false);
Pickup.SetDeferred(Area3D.PropertyName.Monitoring, false);
SfxDatabase.Instance.Play(SoundEffect.Transfer);
PlayRescueAnimation();
Game.RescuedItems.Items.Add(Item);
}
private void PlayRescueAnimation()

View File

@@ -8,8 +8,8 @@ script = ExtResource("2_pixk1")
UsableItemTag = 15
ElementalDamageType = 0
Name = "Spell Sign: Entropic Seal"
StatDescription = "Uses a random item in the inventory.
No effect if no usable items exist."
StatDescription = "Uses a random spell in the inventory.
No effect if no usable spells exist."
FlavorText = ""
SpawnRate = 0.5
BonusAttack = 0

View File

@@ -0,0 +1,30 @@
[gd_resource type="Resource" script_class="EffectItemStats" load_steps=3 format=3 uid="uid://cofh755qjlkn0"]
[ext_resource type="Texture2D" uid="uid://prsafwfaxnda" path="res://src/items/effect/textures/Entropic Seal.png" id="1_y1nwh"]
[ext_resource type="Script" uid="uid://b5w4iw4iqmxtn" path="res://src/items/effect/EffectItemStats.cs" id="2_cov8h"]
[resource]
script = ExtResource("2_cov8h")
UsableItemTag = 32
ElementalDamageType = 0
Name = "Spell Sign: Fortune"
StatDescription = "Doubles the amount of stack items."
FlavorText = ""
SpawnRate = 0.5
BonusAttack = 0
BonusDefense = 0
BonusLuck = 5
BonusHP = 0
BonusVT = 0
AeolicResistance = 0
TelluricResistance = 0
HydricResistance = 0
IgneousResistance = 0
FerrumResistance = 0
HolyResistance = 0
CurseResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 22
Texture = ExtResource("1_y1nwh")
metadata/_custom_type_script = "uid://b5w4iw4iqmxtn"

View File

@@ -5,7 +5,7 @@
[resource]
script = ExtResource("2_4qksk")
UsableItemTag = 0
UsableItemTag = 33
ElementalDamageType = 0
Name = "Spell Sign: Recall"
StatDescription = "Identifies a random unknown item in inventory."

View File

@@ -29,6 +29,6 @@ HolyResistance = 0
CurseResistance = 0
ThrowSpeed = 12.0
ThrowDamage = 5
ItemTag = 0
ItemTag = 2
Texture = ExtResource("1_r4wv3")
metadata/_custom_type_script = "uid://d3wlunkcuv2w2"

View File

@@ -68,10 +68,12 @@ public partial class ThrownItem : RigidBody3D, IThrownItem
public void RescueItem()
{
if (!Game.RescuedItems.TryAdd(ItemThatIsThrown))
return;
ContactMonitor = false;
Freeze = true;
PlayRescueAnimation();
Game.RescuedItems.Items.Add(ItemThatIsThrown);
SfxDatabase.Instance.Play(SoundEffect.Transfer);
}
private void PlayRescueAnimation()

View File

@@ -7,7 +7,6 @@ using System;
using System.Linq;
using Zennysoft.Ma.Adapter;
using Zennysoft.Ma.Adapter.Entity;
using static Zennysoft.Ma.Adapter.AppLogic;
namespace Zennysoft.Game.Ma;
@@ -19,6 +18,8 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
IPlayer IProvide<IPlayer>.Value() => this;
[Dependency] public IGame _game => this.DependOn<IGame>();
private PlayerLogic.IBinding PlayerBinding { get; set; } = default!;
#endregion
@@ -391,7 +392,7 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
ApplyNewAugment((dynamic)augmentableItem, jewel as Jewel);
if (augmentableItem is IEquipableItem equipable && EquipmentComponent.IsItemEquipped(equipable))
if (augmentableItem.Augment != null && augmentableItem is IEquipableItem equipable && EquipmentComponent.IsItemEquipped(equipable))
augmentableItem.Augment.AugmentType.Apply();
}
@@ -423,7 +424,12 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
weapon.Augment = new Augment(JewelTags.LowerEXPGain, new LowerEXPRateAugment(this), jewel.ItemName, jewel.StatDescription, jewel.GetTexture());
break;
case JewelTags.ItemRescue:
if (!_game.RescuedItems.TryAdd(weapon))
break;
if (EquipmentComponent.IsItemEquipped(weapon))
Unequip(weapon);
Inventory.Remove(weapon);
SfxDatabase.Instance.Play(SoundEffect.Transfer);
break;
case JewelTags.Glue:
if (!EquipmentComponent.IsItemEquipped(weapon))
@@ -480,7 +486,12 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
armor.Augment = new Augment(JewelTags.LowerEXPGain, new LowerEXPRateAugment(this), jewel.ItemName, jewel.StatDescription, jewel.GetTexture());
break;
case JewelTags.ItemRescue:
if (!_game.RescuedItems.TryAdd(armor))
break;
if (EquipmentComponent.IsItemEquipped(armor))
Unequip(armor);
Inventory.Remove(armor);
SfxDatabase.Instance.Play(SoundEffect.Transfer);
break;
case JewelTags.Glue:
if (!EquipmentComponent.IsItemEquipped(armor))
@@ -537,7 +548,12 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
accessory.Augment = new Augment(JewelTags.LowerEXPGain, new LowerEXPRateAugment(this), jewel.ItemName, jewel.StatDescription, jewel.GetTexture());
break;
case JewelTags.ItemRescue:
if (!_game.RescuedItems.TryAdd(accessory))
break;
if (EquipmentComponent.IsItemEquipped(accessory))
Unequip(accessory);
Inventory.Remove(accessory);
SfxDatabase.Instance.Play(SoundEffect.Transfer);
break;
case JewelTags.Glue:
if (!EquipmentComponent.IsItemEquipped(accessory))

View File

@@ -73,7 +73,10 @@ public partial class AugmentableItemsMenu : Control
foreach (var item in inventory)
{
if (item is IAugmentableItem augmentable && augmentable.Augment == null)
ItemSlots[slotIndex++].SetItemToSlot(item);
{
ItemSlots[slotIndex].SetItemToSlot(item);
ItemSlots[slotIndex++].EnableItem();
}
}
Show();

View File

@@ -14,6 +14,8 @@ public interface IItemSlot : IControl
public void FocusItem();
public void EnableItem();
public event Action<IItemSlot> ItemPressed;
public event Action<IItemSlot> ItemSelected;

View File

@@ -66,7 +66,7 @@ public partial class ItemRescueMenu : Control, IInventoryMenu
if (Input.IsActionJustPressed(GameInputs.Inventory))
GetViewport().SetInputAsHandled();
var validSelectableItems = _game.RescuedItems.Items;
var validSelectableItems = _game.RescuedItems.GetItems().ToList();
if (Input.IsActionJustPressed(GameInputs.MoveUp) && _currentlySelected != null && _currentlySelected.Item.Value != validSelectableItems.First())
SfxDatabase.Instance.Play(SoundEffect.MoveUI);
@@ -110,7 +110,7 @@ public partial class ItemRescueMenu : Control, IInventoryMenu
private void ResetInventoryState()
{
var inventory = _game.RescuedItems.Items;
var inventory = _game.RescuedItems.GetItems().ToList();
ItemSlots.ForEach(x => x.SetEmpty());
ClearDescriptionBox();
@@ -141,7 +141,7 @@ public partial class ItemRescueMenu : Control, IInventoryMenu
private void ActionPanel_ActionPanelClosing()
{
ActionPanel.Hide();
if (_currentlySelected != null && !_game.RescuedItems.Items.Contains(_currentlySelected.Item.Value))
if (_currentlySelected != null && !_game.RescuedItems.GetItems().ToList().Contains(_currentlySelected.Item.Value))
_currentlySelected = null;
ResetInventoryState();
}
@@ -151,7 +151,7 @@ public partial class ItemRescueMenu : Control, IInventoryMenu
if (_currentlySelected != null)
{
_player.Inventory.PickUpItem(_currentlySelected.Item.Value);
_game.RescuedItems.Items.Remove(_currentlySelected.Item.Value);
_game.RescuedItems.Remove(_currentlySelected.Item.Value);
ResetInventoryState();
ActionPanel_ActionPanelClosing();
}
@@ -159,7 +159,7 @@ public partial class ItemRescueMenu : Control, IInventoryMenu
private void DropButton_Pressed()
{
_game.RescuedItems.Items.Remove(_currentlySelected.Item.Value);
_game.RescuedItems.Remove(_currentlySelected.Item.Value);
ResetInventoryState();
ActionPanel_ActionPanelClosing();
}

View File

@@ -65,6 +65,11 @@ public partial class ItemSlot : Control, IItemSlot
Show();
}
public void EnableItem()
{
ItemName.Disabled = false;
}
public void SetEmpty()
{
Hide();