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

@@ -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()