Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Actor/ActorFactory.cs
Jiaqi (0x7c13) Liu e870cf487a Add core protocol regression tests and copyright checks
Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation.

Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries.
2026-11-12 13:37:27 +08:00

113 lines
4.7 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Actor
{
using System;
using System.Collections.Generic;
using Controllers;
using Core.Contract.Enums;
using Data;
using Dev.Presenters;
using Engine.Core.Abstraction;
using Engine.Core.Implementation;
using Scene;
using Color = Core.Primitives.Color;
using Vector2Int = UnityEngine.Vector2Int;
public static class ActorFactory
{
public static IGameEntity CreateActorGameEntity(GameResourceProvider resourceProvider,
GameActor actor,
Tilemap tilemap,
bool isDropShadowEnabled,
Color tintColor,
float movementMaxYDifferential,
float movementMaxYDifferentialCrossLayer,
float movementMaxYDifferentialCrossPlatform,
Func<int, int[], HashSet<Vector2Int>> getAllActiveActorBlockingTilePositions)
{
IGameEntity actorGameEntity = GameEntityFactory.Create($"Actor_{actor.Id}_{actor.Name}");
// Attach ScnNpcInfo to the GameEntity for better debuggability
#if UNITY_EDITOR
NpcInfoPresenter npcInfoPresent = actorGameEntity.AddComponent<NpcInfoPresenter>();
npcInfoPresent.npcInfo = actor.Info;
#endif
bool hasColliderAndRigidBody = actor.HasColliderAndRigidBody();
ActorActionController actionController;
switch (actor.AnimationType)
{
case ActorAnimationType.Vertex:
{
bool autoStand = actor.Info.InitBehaviour != ActorBehaviourType.Hold;
bool canPerformHoldAnimation = actor.Info is {InitBehaviour: ActorBehaviourType.Hold, LoopAction: 0};
VertexAnimationActorActionController vertexActionController =
actorGameEntity.AddComponent<VertexAnimationActorActionController>();
vertexActionController.Init(resourceProvider,
actor,
hasColliderAndRigidBody,
isDropShadowEnabled,
autoStand,
canPerformHoldAnimation,
tintColor);
actionController = vertexActionController;
break;
}
case ActorAnimationType.Skeletal:
{
SkeletalAnimationActorActionController skeletalActionController =
actorGameEntity.AddComponent<SkeletalAnimationActorActionController>();
skeletalActionController.Init(resourceProvider,
actor,
hasColliderAndRigidBody,
isDropShadowEnabled,
tintColor);
actionController = skeletalActionController;
break;
}
default:
throw new NotSupportedException($"Unsupported actor animation type: {actor.AnimationType}");
}
ActorMovementController movementController = actorGameEntity.AddComponent<ActorMovementController>();
movementController.Init(actor,
tilemap,
actionController,
movementMaxYDifferential,
movementMaxYDifferentialCrossLayer,
movementMaxYDifferentialCrossPlatform,
getAllActiveActorBlockingTilePositions);
ActorController actorController = actorGameEntity.AddComponent<ActorController>();
actorController.Init(actor, actionController, movementController);
// Attach additional controller(s) to special actor
#if PAL3
switch ((PlayerActorId)actor.Id)
{
case PlayerActorId.HuaYing:
actorGameEntity.AddComponent<HuaYingController>().Init(actor, actorController, actionController);
break;
case PlayerActorId.LongKui:
actorGameEntity.AddComponent<LongKuiController>().Init(actor, actionController);
break;
}
#elif PAL3A
switch ((PlayerActorId)actor.Id)
{
case PlayerActorId.TaoZi:
actorGameEntity.AddComponent<FlyingActorController>().Init(actor, actorController, actionController);
break;
}
#endif
return actorGameEntity;
}
}
}