Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion Ultima/Animations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class Animations
private static FileIndex _fileIndex3 = new FileIndex("Anim3.idx", "Anim3.mul", 0x20000, -1);
private static FileIndex _fileIndex4 = new FileIndex("Anim4.idx", "Anim4.mul", 0x20000, -1);
private static FileIndex _fileIndex5 = new FileIndex("Anim5.idx", "Anim5.mul", 0x20000, -1);
private static FileIndex _fileIndex6 = new FileIndex("Anim6.idx", "Anim6.mul", 0x20000, -1);

private static byte[] _streamBuffer;

Expand All @@ -27,9 +28,11 @@ public static void Reload()
_fileIndex3 = new FileIndex("Anim3.idx", "Anim3.mul", 0x20000, -1);
_fileIndex4 = new FileIndex("Anim4.idx", "Anim4.mul", 0x20000, -1);
_fileIndex5 = new FileIndex("Anim5.idx", "Anim5.mul", 0x20000, -1);
_fileIndex6 = new FileIndex("Anim6.idx", "Anim6.mul", 0x20000, -1);

BodyConverter.Initialize();
BodyTable.Initialize();
AnimationsUopLoader.Reload();
}

/// <summary>
Expand All @@ -46,6 +49,11 @@ public static void Reload()
/// <returns></returns>
public static AnimationFrame[] GetAnimation(int body, int action, int direction, ref int hue, bool preserveHue, bool firstFrame)
{
if (AnimationsUopLoader.IsUopBody(body))
{
return AnimationsUopLoader.GetAnimation(body, action, direction, ref hue, preserveHue, firstFrame);
}

if (preserveHue)
{
Translate(ref body);
Expand Down Expand Up @@ -262,6 +270,11 @@ private static void LoadTable()
/// <returns></returns>
public static bool IsActionDefined(int body, int action, int direction)
{
if (AnimationsUopLoader.IsUopBody(body))
{
return AnimationsUopLoader.IsActionDefined(body, action);
}

Translate(ref body);
int fileType = BodyConverter.Convert(ref body);

Expand All @@ -272,6 +285,19 @@ public static bool IsActionDefined(int body, int action, int direction)
return valid && (length >= 1);
}

public static bool IsUopBody(int body) => AnimationsUopLoader.IsUopBody(body);

public static int GetUopAnimationType(int body) => AnimationsUopLoader.GetAnimationType(body);

public static System.Collections.Generic.List<int> GetUopDefinedActions(int body) =>
AnimationsUopLoader.GetDefinedActions(body);

public static System.Collections.Generic.IEnumerable<int> GetAllUopBodies() =>
AnimationsUopLoader.GetAllUopBodyIds();

public static System.Collections.Generic.IEnumerable<int> GetAllMobTypeBodies() =>
AnimationsUopLoader.GetAllMobTypeBodyIds();

/// <summary>
/// Is Animation in given anim file defined
/// </summary>
Expand Down Expand Up @@ -313,6 +339,8 @@ public static int GetAnimCount(int fileType)
return 400 + ((int)(_fileIndex4.IdxLength - (35000 * 12)) / (12 * 175));
case 5:
return 400 + ((int)(_fileIndex5.IdxLength - (35000 * 12)) / (12 * 175));
case 6:
return 400 + ((int)(_fileIndex6.IdxLength - (35000 * 12)) / (12 * 175));
}
}

Expand Down Expand Up @@ -371,6 +399,7 @@ public static int GetAnimLength(int body, int fileType)
break;
case 4:
case 5:
case 6:
if (body < 200)
{
length = 22;
Expand Down Expand Up @@ -478,6 +507,22 @@ private static void GetFileIndex(int body, int action, int direction, int fileTy
index = 35000 + ((body - 400) * 175);
}

break;
case 6:
fileIndex = _fileIndex6;
if (body < 200)
{
index = body * 110;
}
else if (body < 400)
{
index = 22000 + ((body - 200) * 65);
}
else
{
index = 35000 + ((body - 400) * 175);
}

break;
}

Expand All @@ -500,10 +545,15 @@ private static void GetFileIndex(int body, int action, int direction, int fileTy
/// <returns>anim{0}.mul</returns>
public static string GetFileName(int body)
{
if (AnimationsUopLoader.IsUopBody(body))
{
return AnimationsUopLoader.GetUopFileName(body);
}

Translate(ref body);
int fileType = BodyConverter.Convert(ref body);

return fileType == 1 ? "anim.mul" : $"anim{fileType}.mul";
return fileType == 1 ? "anim.mul" : $"anim{fileType}.mul"; // covers anim2–anim6
}
}

Expand Down
Loading