Projectile handling

This commit is contained in:
dingo
2026-01-19 10:46:37 -05:00
parent f5a5d54ae4
commit 11628617ae
8 changed files with 3347 additions and 9 deletions
+16 -4
View File
@@ -1132,7 +1132,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
RecoveryChance = ammo.ArrowRecoveryChance,
CanHitMobs = true,
CanHitPlayers = false, // TODO: PvP support
SpriteKey = ammo.SpritePath ?? "projectile_arrow"
SpriteKey = ammo.SpritePath ?? "projectile_arrow",
IsLinear = ammo.IsLinearProjectile,
FrontFrame = ammo.ProjectileFrontFrame,
BackFrame = ammo.ProjectileBackFrame
};
dungeon.Simulation.Projectiles.TryAdd(projectile.Id, projectile);
@@ -1153,7 +1156,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
y = projectile.Y,
vx = projectile.VelocityX,
vy = projectile.VelocityY,
sprite = projectile.SpriteKey
sprite = projectile.SpriteKey,
isLinear = projectile.IsLinear,
frontFrame = projectile.FrontFrame,
backFrame = projectile.BackFrame
}, CancellationToken.None);
}
}
@@ -1208,7 +1214,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
RecoveryChance = weapon.ArrowRecoveryChance,
CanHitMobs = true,
CanHitPlayers = false,
SpriteKey = weapon.SpritePath ?? "projectile_knife"
SpriteKey = weapon.SpritePath ?? "projectile_knife",
IsLinear = weapon.IsLinearProjectile,
FrontFrame = weapon.ProjectileFrontFrame,
BackFrame = weapon.ProjectileBackFrame
};
dungeon.Simulation.Projectiles.TryAdd(projectile.Id, projectile);
@@ -1227,7 +1236,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
y = projectile.Y,
vx = projectile.VelocityX,
vy = projectile.VelocityY,
sprite = projectile.SpriteKey
sprite = projectile.SpriteKey,
isLinear = projectile.IsLinear,
frontFrame = projectile.FrontFrame,
backFrame = projectile.BackFrame
}, CancellationToken.None);
}
}
+15
View File
@@ -37,6 +37,21 @@ public class ProjectileInstance
public string SpriteKey { get; set; } = "projectile_default";
/// <summary>
/// Whether projectile uses linear rendering (front/back frames) or spins
/// </summary>
public bool IsLinear { get; set; } = false;
/// <summary>
/// Front frame index for linear projectiles (arrow tip)
/// </summary>
public int FrontFrame { get; set; } = 0;
/// <summary>
/// Back frame index for linear projectiles (arrow tail)
/// </summary>
public int BackFrame { get; set; } = 0;
// Player projectile properties
/// <summary>
/// Item definition ID of the ammunition used (for recovery)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class AddLinearProjectileProperties : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsLinearProjectile",
table: "dungeon_item_definitions",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<int>(
name: "ProjectileBackFrame",
table: "dungeon_item_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "ProjectileFrontFrame",
table: "dungeon_item_definitions",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsLinearProjectile",
table: "dungeon_item_definitions");
migrationBuilder.DropColumn(
name: "ProjectileBackFrame",
table: "dungeon_item_definitions");
migrationBuilder.DropColumn(
name: "ProjectileFrontFrame",
table: "dungeon_item_definitions");
}
}
}
+9
View File
@@ -884,6 +884,9 @@ namespace SystemRevivalServer.Migrations
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsLinearProjectile")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsTeleportScroll")
.HasColumnType("tinyint(1)");
@@ -967,6 +970,12 @@ namespace SystemRevivalServer.Migrations
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<int>("ProjectileBackFrame")
.HasColumnType("int");
b.Property<int>("ProjectileFrontFrame")
.HasColumnType("int");
b.Property<int>("ProjectileRange")
.HasColumnType("int");
+27
View File
@@ -224,6 +224,32 @@
<span class="text-gray-300">Is Throwable</span>
</label>
</div>
<div class="flex items-center pt-6">
<label class="flex items-center gap-2 cursor-pointer">
<input type="checkbox" id="linearProjectileCheck" name="Item.IsLinearProjectile" value="true" checked="@Model.Item.IsLinearProjectile" class="w-4 h-4 rounded border-gray-600 bg-gray-800 text-indigo-600" onchange="toggleLinearFrames()" />
<span class="text-gray-300">Linear Projectile</span>
</label>
</div>
</div>
<!-- Linear Projectile Frame Selection -->
<div id="linearFramesSection" style="display: @(Model.Item.IsLinearProjectile ? "block" : "none")">
<div class="bg-indigo-900/20 border border-indigo-700 rounded-lg p-4">
<h3 class="text-sm font-medium text-indigo-200 mb-3">Linear Projectile Frames</h3>
<p class="text-xs text-indigo-300 mb-4">Select the front (tip) and back (tail) frame indices from the sprite sheet. The projectile will be oriented toward its direction of travel.</p>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="label">Front Frame Index</label>
<input type="number" name="Item.ProjectileFrontFrame" value="@Model.Item.ProjectileFrontFrame" class="input" min="0" />
<p class="text-xs text-gray-500 mt-1">Arrow tip pointing forward</p>
</div>
<div>
<label class="label">Back Frame Index</label>
<input type="number" name="Item.ProjectileBackFrame" value="@Model.Item.ProjectileBackFrame" class="input" min="0" />
<p class="text-xs text-gray-500 mt-1">Arrow tail/feathers</p>
</div>
</div>
</div>
</div>
<!-- Ammunition Type -->
@@ -360,6 +386,7 @@
}
function toggleMaxStack() { const cb = document.getElementById('stackableCheck'); const input = document.getElementById('maxStackInput'); input.disabled = !cb.checked; if (!cb.checked) input.value = 1; }
function toggleAmmoFields() { const cb = document.getElementById('requiresAmmoCheck'); const section = document.getElementById('ammoTypeSection'); section.style.display = cb.checked ? 'block' : 'none'; }
function toggleLinearFrames() { const cb = document.getElementById('linearProjectileCheck'); const section = document.getElementById('linearFramesSection'); section.style.display = cb.checked ? 'block' : 'none'; }
function updateSections() {
const type = document.getElementById('itemType').value;
const isEquipment = ['Weapon', 'Armor', 'Accessory'].includes(type);
+24 -5
View File
@@ -586,11 +586,12 @@
<div class="space-y-4">
<div>
<label class="label">Animation</label>
<select name="animationId" class="input" required>
<input type="text" id="animationSearch" class="input mb-2" placeholder="Type to search animations..." oninput="filterAnimations()" autocomplete="off" />
<select name="animationId" id="animationSelect" class="input" required size="10" style="height: auto;">
<option value="">Select an animation...</option>
@foreach (var anim in Model.AllAnimations)
{
<option value="@anim.Id">[@(anim.SpriteSheet?.Name ?? "?")] @anim.Key - @anim.FrameSequence (@anim.Fps fps)</option>
<option value="@anim.Id" data-search-text="[@(anim.SpriteSheet?.Name ?? "?")] @anim.Key - @anim.FrameSequence (@anim.Fps fps)">[@(anim.SpriteSheet?.Name ?? "?")] @anim.Key - @anim.FrameSequence (@anim.Fps fps)</option>
}
</select>
</div>
@@ -746,14 +747,32 @@
document.getElementById('addAnimationModal').classList.add('hidden');
document.getElementById('addAnimationModal').classList.remove('flex');
}
document.addEventListener('keydown', e => {
document.addEventListener('keydown', e => {
if (e.key === 'Escape') {
closeAddLootModal();
closeAddLootModal();
closeAddAbilityModal();
closeAddAnimationModal();
}
});
// Animation search filter
function filterAnimations() {
const searchInput = document.getElementById('animationSearch');
const select = document.getElementById('animationSelect');
const searchTerm = searchInput.value.toLowerCase();
for (let i = 0; i < select.options.length; i++) {
const option = select.options[i];
const searchText = option.getAttribute('data-search-text') || option.text;
if (searchTerm === '' || searchText.toLowerCase().includes(searchTerm)) {
option.style.display = '';
} else {
option.style.display = 'none';
}
}
}
// Resistance type options for dynamic rows
const resistanceOptions = `@Html.Raw(string.Join("", Model.ResistanceTypes.Select(rt => $"<option value=\"{rt.Key}\">{rt.DisplayName}</option>")))`;
+19
View File
@@ -167,6 +167,25 @@ public class DungeonItemDefinition
/// </summary>
public bool IsThrowable { get; set; } = false;
/// <summary>
/// Whether projectile flies linearly (true) or spins (false)
/// Linear projectiles use ProjectileFrontFrame and ProjectileBackFrame
/// Spinning projectiles rotate as they fly
/// </summary>
public bool IsLinearProjectile { get; set; } = false;
/// <summary>
/// Frame index for front of linear projectile (arrow tip pointing forward)
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileFrontFrame { get; set; } = 0;
/// <summary>
/// Frame index for back of linear projectile (arrow tail/feathers)
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileBackFrame { get; set; } = 0;
// Visuals
/// <summary>
/// Path to the item's sprite image on CDN (e.g., "textures/items/sword_iron.png")