projectile fix

This commit is contained in:
dingo
2026-01-19 11:07:24 -05:00
parent 11628617ae
commit 01a19056bb
7 changed files with 3514 additions and 32 deletions
+16 -8
View File
@@ -1134,8 +1134,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
CanHitPlayers = false, // TODO: PvP support
SpriteKey = ammo.SpritePath ?? "projectile_arrow",
IsLinear = ammo.IsLinearProjectile,
FrontFrame = ammo.ProjectileFrontFrame,
BackFrame = ammo.ProjectileBackFrame
FrontX = ammo.ProjectileFrontX,
FrontY = ammo.ProjectileFrontY,
BackX = ammo.ProjectileBackX,
BackY = ammo.ProjectileBackY
};
dungeon.Simulation.Projectiles.TryAdd(projectile.Id, projectile);
@@ -1158,8 +1160,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
vy = projectile.VelocityY,
sprite = projectile.SpriteKey,
isLinear = projectile.IsLinear,
frontFrame = projectile.FrontFrame,
backFrame = projectile.BackFrame
frontX = projectile.FrontX,
frontY = projectile.FrontY,
backX = projectile.BackX,
backY = projectile.BackY
}, CancellationToken.None);
}
}
@@ -1216,8 +1220,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
CanHitPlayers = false,
SpriteKey = weapon.SpritePath ?? "projectile_knife",
IsLinear = weapon.IsLinearProjectile,
FrontFrame = weapon.ProjectileFrontFrame,
BackFrame = weapon.ProjectileBackFrame
FrontX = weapon.ProjectileFrontX,
FrontY = weapon.ProjectileFrontY,
BackX = weapon.ProjectileBackX,
BackY = weapon.ProjectileBackY
};
dungeon.Simulation.Projectiles.TryAdd(projectile.Id, projectile);
@@ -1238,8 +1244,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
vy = projectile.VelocityY,
sprite = projectile.SpriteKey,
isLinear = projectile.IsLinear,
frontFrame = projectile.FrontFrame,
backFrame = projectile.BackFrame
frontX = projectile.FrontX,
frontY = projectile.FrontY,
backX = projectile.BackX,
backY = projectile.BackY
}, CancellationToken.None);
}
}
+15 -5
View File
@@ -38,19 +38,29 @@ public class ProjectileInstance
public string SpriteKey { get; set; } = "projectile_default";
/// <summary>
/// Whether projectile uses linear rendering (front/back frames) or spins
/// Whether projectile uses linear rendering (front/back coordinates) or spins
/// </summary>
public bool IsLinear { get; set; } = false;
/// <summary>
/// Front frame index for linear projectiles (arrow tip)
/// X coordinate of arrow tip (front) in sprite
/// </summary>
public int FrontFrame { get; set; } = 0;
public int FrontX { get; set; } = 0;
/// <summary>
/// Back frame index for linear projectiles (arrow tail)
/// Y coordinate of arrow tip (front) in sprite
/// </summary>
public int BackFrame { get; set; } = 0;
public int FrontY { get; set; } = 0;
/// <summary>
/// X coordinate of arrow tail (back) in sprite
/// </summary>
public int BackX { get; set; } = 0;
/// <summary>
/// Y coordinate of arrow tail (back) in sprite
/// </summary>
public int BackY { get; set; } = 0;
// Player projectile properties
/// <summary>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,60 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SystemRevivalServer.Migrations
{
/// <inheritdoc />
public partial class ChangeProjectileFramesToCoordinates : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "ProjectileFrontFrame",
table: "dungeon_item_definitions",
newName: "ProjectileFrontY");
migrationBuilder.RenameColumn(
name: "ProjectileBackFrame",
table: "dungeon_item_definitions",
newName: "ProjectileFrontX");
migrationBuilder.AddColumn<int>(
name: "ProjectileBackX",
table: "dungeon_item_definitions",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "ProjectileBackY",
table: "dungeon_item_definitions",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ProjectileBackX",
table: "dungeon_item_definitions");
migrationBuilder.DropColumn(
name: "ProjectileBackY",
table: "dungeon_item_definitions");
migrationBuilder.RenameColumn(
name: "ProjectileFrontY",
table: "dungeon_item_definitions",
newName: "ProjectileFrontFrame");
migrationBuilder.RenameColumn(
name: "ProjectileFrontX",
table: "dungeon_item_definitions",
newName: "ProjectileBackFrame");
}
}
}
+8 -2
View File
@@ -970,10 +970,16 @@ namespace SystemRevivalServer.Migrations
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<int>("ProjectileBackFrame")
b.Property<int>("ProjectileBackX")
.HasColumnType("int");
b.Property<int>("ProjectileFrontFrame")
b.Property<int>("ProjectileBackY")
.HasColumnType("int");
b.Property<int>("ProjectileFrontX")
.HasColumnType("int");
b.Property<int>("ProjectileFrontY")
.HasColumnType("int");
b.Property<int>("ProjectileRange")
+206 -12
View File
@@ -232,21 +232,50 @@
</div>
</div>
<!-- Linear Projectile Frame Selection -->
<!-- Linear Projectile Coordinate 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>
<h3 class="text-sm font-medium text-indigo-200 mb-3">Linear Projectile Coordinates</h3>
<p class="text-xs text-indigo-300 mb-4">Click on the arrow tip (front) and tail (back) positions in the preview below. The projectile will be oriented toward its direction of travel.</p>
<!-- Image preview with click coordinates -->
<div class="mb-4">
<div class="relative inline-block border-2 border-indigo-500 bg-gray-900 rounded" id="projectilePreviewContainer" style="display: none;">
<img id="projectilePreviewImage" src="" class="max-w-full max-h-64 block" style="image-rendering: pixelated;" />
<canvas id="projectileOverlay" class="absolute inset-0 pointer-events-none" style="image-rendering: pixelated;"></canvas>
<div class="absolute top-1 right-1 bg-black/70 text-white text-xs px-2 py-1 rounded" id="projectileCoords">Hover to see coordinates</div>
</div>
<p class="text-xs text-gray-500 mt-2">Image will appear after you select a sprite path above</p>
</div>
<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>
<label class="label">Front (Tip) Coordinates</label>
<div class="flex gap-2">
<div class="flex-1">
<label class="text-xs text-gray-500">X</label>
<input type="number" id="frontXInput" name="Item.ProjectileFrontX" value="@Model.Item.ProjectileFrontX" class="input" min="0" />
</div>
<div class="flex-1">
<label class="text-xs text-gray-500">Y</label>
<input type="number" id="frontYInput" name="Item.ProjectileFrontY" value="@Model.Item.ProjectileFrontY" class="input" min="0" />
</div>
</div>
<button type="button" onclick="setClickMode('front')" class="btn btn-sm btn-secondary mt-1 w-full">Click to Set Front</button>
</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>
<label class="label">Back (Tail) Coordinates</label>
<div class="flex gap-2">
<div class="flex-1">
<label class="text-xs text-gray-500">X</label>
<input type="number" id="backXInput" name="Item.ProjectileBackX" value="@Model.Item.ProjectileBackX" class="input" min="0" />
</div>
<div class="flex-1">
<label class="text-xs text-gray-500">Y</label>
<input type="number" id="backYInput" name="Item.ProjectileBackY" value="@Model.Item.ProjectileBackY" class="input" min="0" />
</div>
</div>
<button type="button" onclick="setClickMode('back')" class="btn btn-sm btn-secondary mt-1 w-full">Click to Set Back</button>
</div>
</div>
</div>
@@ -381,12 +410,177 @@
const path = document.getElementById('spritePath').value;
const img = document.getElementById('spritePreview');
const placeholder = document.getElementById('spritePlaceholder');
if (path && path.trim()) { img.onload = () => { img.classList.remove('hidden'); placeholder.classList.add('hidden'); }; img.onerror = () => { img.classList.add('hidden'); placeholder.classList.remove('hidden'); }; img.src = cdnBase + '/' + path.trim(); }
else { img.classList.add('hidden'); placeholder.classList.remove('hidden'); }
if (path && path.trim()) {
img.onload = () => {
img.classList.remove('hidden');
placeholder.classList.add('hidden');
updateProjectilePreview(path.trim());
};
img.onerror = () => {
img.classList.add('hidden');
placeholder.classList.remove('hidden');
};
img.src = cdnBase + '/' + path.trim();
}
else {
img.classList.add('hidden');
placeholder.classList.remove('hidden');
}
}
// Projectile coordinate picker
let projectileClickMode = null; // 'front' or 'back'
let projectilePreviewImg = null;
let projectileCanvas = null;
let projectileCtx = null;
function updateProjectilePreview(path) {
const container = document.getElementById('projectilePreviewContainer');
const img = document.getElementById('projectilePreviewImage');
const canvas = document.getElementById('projectileOverlay');
const linearCheck = document.getElementById('linearProjectileCheck');
if (!linearCheck || !linearCheck.checked) {
container.style.display = 'none';
return;
}
img.onload = () => {
container.style.display = 'inline-block';
canvas.width = img.width;
canvas.height = img.height;
canvas.style.width = img.width + 'px';
canvas.style.height = img.height + 'px';
projectilePreviewImg = img;
projectileCanvas = canvas;
projectileCtx = canvas.getContext('2d');
drawProjectileMarkers();
};
img.src = cdnBase + '/' + path;
}
function setClickMode(mode) {
projectileClickMode = mode;
const container = document.getElementById('projectilePreviewContainer');
container.style.cursor = 'crosshair';
document.getElementById('projectileCoords').textContent =
mode === 'front' ? 'Click to set FRONT (arrow tip)' : 'Click to set BACK (arrow tail)';
}
function drawProjectileMarkers() {
if (!projectileCtx || !projectileCanvas) return;
projectileCtx.clearRect(0, 0, projectileCanvas.width, projectileCanvas.height);
const frontX = parseInt(document.getElementById('frontXInput').value) || 0;
const frontY = parseInt(document.getElementById('frontYInput').value) || 0;
const backX = parseInt(document.getElementById('backXInput').value) || 0;
const backY = parseInt(document.getElementById('backYInput').value) || 0;
// Draw line between front and back
if (frontX > 0 && frontY > 0 && backX > 0 && backY > 0) {
projectileCtx.strokeStyle = '#60a5fa';
projectileCtx.lineWidth = 2;
projectileCtx.beginPath();
projectileCtx.moveTo(frontX, frontY);
projectileCtx.lineTo(backX, backY);
projectileCtx.stroke();
}
// Draw front marker (arrow tip) - red
if (frontX > 0 && frontY > 0) {
projectileCtx.fillStyle = '#ef4444';
projectileCtx.strokeStyle = '#ffffff';
projectileCtx.lineWidth = 2;
projectileCtx.beginPath();
projectileCtx.arc(frontX, frontY, 5, 0, Math.PI * 2);
projectileCtx.fill();
projectileCtx.stroke();
projectileCtx.fillStyle = '#ffffff';
projectileCtx.font = 'bold 12px monospace';
projectileCtx.fillText('F', frontX - 4, frontY + 4);
}
// Draw back marker (arrow tail) - green
if (backX > 0 && backY > 0) {
projectileCtx.fillStyle = '#22c55e';
projectileCtx.strokeStyle = '#ffffff';
projectileCtx.lineWidth = 2;
projectileCtx.beginPath();
projectileCtx.arc(backX, backY, 5, 0, Math.PI * 2);
projectileCtx.fill();
projectileCtx.stroke();
projectileCtx.fillStyle = '#ffffff';
projectileCtx.font = 'bold 12px monospace';
projectileCtx.fillText('B', backX - 4, backY + 4);
}
}
// Set up event listeners
document.addEventListener('DOMContentLoaded', function() {
const img = document.getElementById('projectilePreviewImage');
const coords = document.getElementById('projectileCoords');
const container = document.getElementById('projectilePreviewContainer');
if (img) {
img.addEventListener('click', function(e) {
if (!projectileClickMode) return;
const rect = img.getBoundingClientRect();
const x = Math.round(e.clientX - rect.left);
const y = Math.round(e.clientY - rect.top);
if (projectileClickMode === 'front') {
document.getElementById('frontXInput').value = x;
document.getElementById('frontYInput').value = y;
} else if (projectileClickMode === 'back') {
document.getElementById('backXInput').value = x;
document.getElementById('backYInput').value = y;
}
projectileClickMode = null;
container.style.cursor = 'default';
coords.textContent = 'Hover to see coordinates';
drawProjectileMarkers();
});
img.addEventListener('mousemove', function(e) {
const rect = img.getBoundingClientRect();
const x = Math.round(e.clientX - rect.left);
const y = Math.round(e.clientY - rect.top);
coords.textContent = `X: ${x}, Y: ${y}`;
});
img.addEventListener('mouseleave', function() {
if (!projectileClickMode) {
coords.textContent = 'Hover to see coordinates';
}
});
}
// Update preview when inputs change
['frontXInput', 'frontYInput', 'backXInput', 'backYInput'].forEach(id => {
const input = document.getElementById(id);
if (input) {
input.addEventListener('input', drawProjectileMarkers);
}
});
});
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 toggleLinearFrames() {
const cb = document.getElementById('linearProjectileCheck');
const section = document.getElementById('linearFramesSection');
section.style.display = cb.checked ? 'block' : 'none';
if (cb.checked) {
const path = document.getElementById('spritePath').value;
if (path && path.trim()) {
updateProjectilePreview(path.trim());
}
}
}
function updateSections() {
const type = document.getElementById('itemType').value;
const isEquipment = ['Weapon', 'Armor', 'Accessory'].includes(type);
+17 -5
View File
@@ -169,22 +169,34 @@ public class DungeonItemDefinition
/// <summary>
/// Whether projectile flies linearly (true) or spins (false)
/// Linear projectiles use ProjectileFrontFrame and ProjectileBackFrame
/// Linear projectiles use front/back coordinates
/// 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)
/// X coordinate of arrow tip (front) in the sprite image
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileFrontFrame { get; set; } = 0;
public int ProjectileFrontX { get; set; } = 0;
/// <summary>
/// Frame index for back of linear projectile (arrow tail/feathers)
/// Y coordinate of arrow tip (front) in the sprite image
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileBackFrame { get; set; } = 0;
public int ProjectileFrontY { get; set; } = 0;
/// <summary>
/// X coordinate of arrow tail (back) in the sprite image
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileBackX { get; set; } = 0;
/// <summary>
/// Y coordinate of arrow tail (back) in the sprite image
/// Only used when IsLinearProjectile = true
/// </summary>
public int ProjectileBackY { get; set; } = 0;
// Visuals
/// <summary>