Skip to content

Commit

Permalink
Implement and use LinkedObjectGroupId to sync objects
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7c13 committed Aug 13, 2023
1 parent 4e25c7f commit 6949a02
Show file tree
Hide file tree
Showing 50 changed files with 108 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Core/DataReader/Scn/ScnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ 24 以拣起的道具
public string FailedMessage; // char[16] 失败提示字符串名称

#if PAL3A
public uint Unknown; // TODO
public ushort LinkedObjectGroupId; // 同时触发的关联编号 (如阳名百纳二的机关浮板,神魔结界的三相桥)
#endif

public uint ScriptId;
Expand Down
5 changes: 3 additions & 2 deletions Assets/Scripts/Core/DataReader/Scn/ScnFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ private static ScnObjectInfo ReadObjectInfo(IBinaryReader reader, int codepage)
_ = reader.ReadByte(); // Empty padding byte to complete 4-byte alignment

#if PAL3A
var unknown = reader.ReadUInt32(); // TODO
var linkedObjectGroupId = reader.ReadUInt16();
_ = reader.ReadBytes(2); // Empty padding bytes to complete 4-byte alignment
#endif

var scriptId = reader.ReadUInt32();
Expand Down Expand Up @@ -224,7 +225,7 @@ private static ScnObjectInfo ReadObjectInfo(IBinaryReader reader, int codepage)
FailedMessage = failedMessage,

#if PAL3A
Unknown = unknown, // TODO
LinkedObjectGroupId = linkedObjectGroupId,
#endif

ScriptId = scriptId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ public class ThreePhaseSwitchStateChangedNotification : ICommand
public ThreePhaseSwitchStateChangedNotification(
int objectId,
int previousState,
int currentState)
int currentState,
bool isBridgeMovingAlongYAxis)
{
ObjectId = objectId;
PreviousState = previousState;
CurrentState = currentState;
IsBridgeMovingAlongYAxis = isBridgeMovingAlongYAxis;
}

public int ObjectId { get; }
public int PreviousState { get; }
public int CurrentState { get; }
public bool IsBridgeMovingAlongYAxis { get; }
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AutoTriggerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Pal3/Scene/SceneObjects/ChestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ChestObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override bool IsDirectlyInteractable(float distance)
{
return Activated && distance < MAX_INTERACTION_DISTANCE;
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}

public override bool ShouldGoToCutsceneWhenInteractionStarted()
Expand All @@ -37,7 +37,7 @@ public override bool ShouldGoToCutsceneWhenInteractionStarted()

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
_meshCollider = sceneGameObject.AddComponent<SceneObjectMeshCollider>();
return sceneGameObject;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Pal3/Scene/SceneObjects/ClimbableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public ClimbableObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override bool IsDirectlyInteractable(float distance)
{
return Activated && distance < MAX_INTERACTION_DISTANCE;
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Vector3 climbablePosition = sceneGameObject.transform.position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public CollectableObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override bool IsDirectlyInteractable(float distance)
{
return Activated && distance < MAX_INTERACTION_DISTANCE;
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}

public override bool ShouldGoToCutsceneWhenInteractionStarted()
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/CollidableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CollidableObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

// Don't add a trigger if the object is already collided (SwitchState sets to 1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DivineTreeFlowerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

bool isFlowerInOpenState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public DivineTreePortalObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/DoorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public DoorObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ElevatorDoorObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
// Add collider to block player
_meshCollider = sceneGameObject.AddComponent<SceneObjectMeshCollider>();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/ElevatorObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ElevatorObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ElevatorPedalObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/EyeBallObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public EyeBallObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
CommandExecutorRegistry<ICommand>.Instance.Register(this);
return sceneGameObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public FallableObstacleObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GeneralSceneObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public GravitySwitchObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/ImpulsiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ImpulsiveObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

Color subObjectTintColor = tintColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public InvestigationTriggerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneIn

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
if (ObjectInfo.IsNonBlocking == 0)
{
Expand All @@ -38,7 +38,7 @@ public override GameObject Activate(GameResourceProvider resourceProvider, Color

public override bool IsDirectlyInteractable(float distance)
{
return Activated && distance < MAX_INTERACTION_DISTANCE;
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}

public override IEnumerator InteractAsync(InteractionContext ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public JumpableAreaObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LiftingPlatformObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

#if PAL3A
Expand Down
25 changes: 24 additions & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/MovableCarrierObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public MovableCarrierObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down Expand Up @@ -108,6 +108,29 @@ public override IEnumerator InteractAsync(InteractionContext ctx)
SaveCurrentPosition();
yield break;
}
else
{
#if PAL3A
// PAL3A has additional interaction logic for grouped objects
// This is to sync moving carriers in m07-2 scene
if (SceneInfo.Is("m07", "2") &&
ObjectInfo.LinkedObjectGroupId != 0)
{
var allObjects = ctx.CurrentScene.GetAllSceneObjects();
foreach (SceneObject otherObject in allObjects.Values)
{
if (ObjectInfo.Id != otherObject.ObjectInfo.Id &&
ObjectInfo.Type == otherObject.ObjectInfo.Type &&
ObjectInfo.LinkedObjectGroupId == otherObject.ObjectInfo.LinkedObjectGroupId &&
otherObject.IsActivated)
{
yield return otherObject.InteractAsync(ctx);
}

}
}
#endif
}

var actorMovementController = ctx.PlayerActorGameObject.GetComponent<ActorMovementController>();
var waypoints = new List<Vector3>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public MushroomBridgeObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Bounds bounds = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PaperweightDeskObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override bool IsDirectlyInteractable(float distance)
{
return Activated &&
return IsActivated &&
distance < MAX_INTERACTION_DISTANCE &&
ObjectInfo.Times > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public PedalSwitchObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PiranhaFlowerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)
public override GameObject Activate(GameResourceProvider resourceProvider,
Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

_triggerController = sceneGameObject.AddComponent<TilemapTriggerController>();
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Pal3/Scene/SceneObjects/PushableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public PushableObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Pal3/Scene/SceneObjects/RareChestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public RareChestObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override bool IsDirectlyInteractable(float distance)
{
return Activated && distance < MAX_INTERACTION_DISTANCE;
return IsActivated && distance < MAX_INTERACTION_DISTANCE;
}

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);
_meshCollider = sceneGameObject.AddComponent<SceneObjectMeshCollider>();
return sceneGameObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public RetractableBlockerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public RoadElevatorOrBlockerObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneI

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Bounds bounds = GetMeshBounds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RotatingBridgeObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();

GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public RotatingWallObject(ScnObjectInfo objectInfo, ScnSceneInfo sceneInfo)

public override GameObject Activate(GameResourceProvider resourceProvider, Color tintColor)
{
if (Activated) return GetGameObject();
if (IsActivated) return GetGameObject();
GameObject sceneGameObject = base.Activate(resourceProvider, tintColor);

// Add mesh collider to block player
Expand Down
Loading

0 comments on commit 6949a02

Please sign in to comment.