Teleport enemy to random room item

This commit is contained in:
2025-03-02 11:55:19 -08:00
parent 2439791d05
commit 05295f535a
20 changed files with 166 additions and 59 deletions

View File

@@ -3,6 +3,7 @@ using Chickensoft.Introspection;
using Godot;
using System;
using System.Collections.Immutable;
using System.Linq;
namespace GameJamDungeon;
@@ -74,6 +75,33 @@ public partial class ThrowableItem : Node3D, IUsableItem
ChangeAffinity();
}
public void TeleportToRandomRoom(IEnemy enemy)
{
var currentFloor = Game.CurrentFloor;
var rooms = currentFloor.Rooms;
var rng = new RandomNumberGenerator();
rng.Randomize();
var randomRoom = rooms[rng.RandiRange(0, rooms.Count - 1)];
var spawnPoints = randomRoom.EnemySpawnPoints.GetChildren().OfType<Marker3D>().ToList();
var randomSpawnPoint = spawnPoints[rng.RandiRange(0, spawnPoints.Count - 1)];
enemy.SetEnemyGlobalPosition(randomSpawnPoint.GlobalPosition);
}
public void TeleportToRandomRoom(IPlayer player)
{
var currentFloor = Game.CurrentFloor;
var rooms = currentFloor.Rooms;
var rng = new RandomNumberGenerator();
rng.Randomize();
var randomRoom = rooms[rng.RandiRange(0, rooms.Count - 1)];
var spawnPoint = randomRoom.PlayerSpawn;
player.TeleportPlayer(spawnPoint.GlobalPosition);
}
private void ChangeAffinity()
{
var maximumElements = Enum.GetNames(typeof(ElementType)).Length;

View File

@@ -3,7 +3,8 @@
public enum ThrowableItemTag
{
LowerTargetTo1HP,
CanChangeAffinity
CanChangeAffinity,
TeleportToRandomLocation
}
public enum UsableItemTag

View File

@@ -0,0 +1,19 @@
[gd_resource type="Resource" script_class="ThrowableItemStats" load_steps=3 format=3 uid="uid://lo37qfyxlhx1"]
[ext_resource type="Texture2D" uid="uid://cagebvc1lp28y" path="res://src/items/throwable/textures/tablet.PNG" id="1_xt2mp"]
[ext_resource type="Script" uid="uid://d3wlunkcuv2w2" path="res://src/items/throwable/ThrowableItemStats.cs" id="2_m680r"]
[resource]
script = ExtResource("2_m680r")
ThrowableItemTags = Array[int]([2])
ElementType = 0
UsableItemTags = Array[int]([])
Name = "Gospel of Dimension"
Description = "Teleports target to a random location."
Texture = ExtResource("1_xt2mp")
SpawnRate = 0.1
ThrowSpeed = 20.0
HealHPAmount = 0
HealVTAmount = 0
ThrowDamage = 20
ItemTags = Array[int]([])

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cagebvc1lp28y"
path="res://.godot/imported/tablet.PNG-95771620877422607611342ad4de8709.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://src/items/throwable/textures/tablet.PNG"
dest_files=["res://.godot/imported/tablet.PNG-95771620877422607611342ad4de8709.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

View File

@@ -1,6 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using System.Linq;
namespace GameJamDungeon;
@@ -39,8 +40,20 @@ public partial class ThrownItem : RigidBody3D
{
if (ItemThatIsThrown is ThrowableItem throwableItem)
{
switch (throwableItem.ThrowableItemTags.Single())
{
case ThrowableItemTag.LowerTargetTo1HP:
enemy.TakeDamage(enemy.CurrentHP - 1, ignoreDefense: true, ignoreElementalResistance: true);
break;
case ThrowableItemTag.TeleportToRandomLocation:
throwableItem.TeleportToRandomRoom(enemy);
break;
}
if (throwableItem.ThrowableItemTags.Contains(ThrowableItemTag.LowerTargetTo1HP))
enemy.TakeDamage(enemy.CurrentHP - 1, ignoreDefense: true, ignoreElementalResistance: true);
else if (throwableItem.ThrowableItemTags.Contains(ThrowableItemTag.TeleportToRandomLocation))
//enemy teleport
return;
else
enemy.TakeDamage(throwableItem.ThrowDamage, throwableItem.ElementType);
}