Files
Jiaqi Liu 5d0f564a00 Add a standalone battle editor and battle system for PAL3 and PAL3A (#99)
* build: migrate C# formatting and add offscreen editor test support

Host IMGUI tests on a detached panel without creating a native editor window.

* feat(core): decode native battle records, geometry and animation metadata

Read the two game variants’ battle tables and model data, with binary-reader and original-resource coverage.

* feat(battle): implement deterministic combat rules and action settlement

Implement actors, inventory, formation, action timing, status interruption, AI, stage ownership and deterministic replay. Keep the domain and its regression suite independent of Unity.

* feat(battle): project native HUD state and input commands

Add the presentation assembly and tests for command routing, lineup selection, floating numbers and stage messages.

* feat(rendering): add battle lighting, actor appearance and native shadows

Support baked and toon lighting, actor and weapon rendering, display refresh rate and resource ownership.

* feat(effects): drive battle effects through shared resource previews

Bind battle control nodes to action owners. Share preview lighting, geometry and effect resources with the existing Unity editors.

* refactor(game): isolate story battle targeting and actor lifetimes

Preserve scene ownership, bound story battle targeting and stop debug attacks when their actor leaves the scene.

* feat(editor): compile original game data into battle scenarios

Build per-variant animation and ability catalogs, encounter music, scene lighting profiles, random parties, equipment and test inventory from the original resources.

* feat(editor): play battle sessions with animated previews and synced media

Drive the preview scene, camera, effects, hit feedback, result choreography, music and movies from simulation snapshots and events.

* feat(editor): add the battle workbench, native HUD and input controls

Expose scenario authoring, replay, diagnostics, responsive command menus and mouse, touch and gamepad targeting. Include the editor workflow and HUD integration tests.
2026-11-21 22:28:47 +08:00

70 lines
2.6 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Rendering.Native
{
using System;
using Core.DataReader.Mv3;
using Engine.Extensions;
using UnityEngine;
/// <summary>A captured native shadow radius and the current role position.</summary>
public readonly struct GameBoxBattleShadow
{
public Vector3 Position
{
get;
}
public float NativeRadius
{
get;
}
public GameBoxBattleShadow(Vector3 position, float nativeRadius)
{
Position = position;
NativeRadius = nativeRadius;
}
public Vector3 Corner(int index)
{
float radius = NativeRadius / UnityPrimitivesConvertor.GameBoxUnitToUnityUnit;
float height = .5f / UnityPrimitivesConvertor.GameBoxUnitToUnityUnit;
return Position + (index switch
{
0 => new Vector3(radius, height, radius),
1 => new Vector3(-radius, height, radius),
2 => new Vector3(-radius, height, -radius),
3 => new Vector3(radius, height, -radius),
_ => throw new ArgumentOutOfRangeException(nameof(index))
});
}
// GetCollideOBB takes the union of the action's authored mesh bounds.
// The combat shadow uses the complete X/Z width as its radius.
public static float CaptureRadius(Mv3File model)
{
if (model == null)
throw new ArgumentNullException(nameof(model));
if (model.Meshes.Length == 0)
throw new ArgumentException("A shadow model must contain meshes.", nameof(model));
float minX = float.MaxValue, minZ = float.MaxValue;
float maxX = float.MinValue, maxZ = float.MinValue;
foreach (Mv3Mesh mesh in model.Meshes)
{
minX = Math.Min(minX, mesh.GameBoxBoundsMin.X);
minZ = Math.Min(minZ, mesh.GameBoxBoundsMin.Z);
maxX = Math.Max(maxX, mesh.GameBoxBoundsMax.X);
maxZ = Math.Max(maxZ, mesh.GameBoxBoundsMax.Z);
}
return Math.Min(maxX - minX, maxZ - minZ);
}
public static bool IsVisible(bool pal3A, bool valid, bool modelAlive, bool ally, int hp, float blend) =>
valid && (!pal3A || blend >= .5f) && (modelAlive || ally && hp > 0);
}
}