Go Back   RunUO - Ultima Online Emulation > RunUO > Utility Support > Ultima SDK

Ultima SDK Support for the Ultima SDK.

Reply
 
Thread Tools Display Modes
Old 09-22-2007, 10:57 PM   #1 (permalink)
Forum Expert
 
Join Date: Oct 2006
Age: 22
Posts: 268
Default BodyConverter

Code:
using System;
using System.Collections.Generic;
using System.IO;

namespace Client
{
    class BodyConverter
    {
        private static List<List<int>> m_Values;

        static BodyConverter()
        {
            using (StreamReader streamReader = new StreamReader(FileManager.GetFilePath("bodyconv.def")))
            {
                string currentLine;

                while ((currentLine = streamReader.ReadLine()) != null)
                {
                    if (currentLine.IndexOf("#") >= 0)
                        currentLine = currentLine.Remove(currentLine.IndexOf("#"));

                    if (currentLine.IndexOf('"') >= 0)
                        currentLine = currentLine.Remove(currentLine.IndexOf('"'));

                    currentLine = currentLine.Trim();

                    if (currentLine.Length == 0)
                        continue;

                    string[] splitLine = currentLine.Split('\t');

                    if (m_Values == null)
                    {
                        m_Values = new List<List<int>>();

                        for (int i = 0; i < splitLine.Length; i++)
                            m_Values.Add(new List<int>());
                    }

                    for (int i = 0; i < m_Values.Count; i++)
                    {
                        if (splitLine.Length < m_Values.Count)
                            m_Values[i].Add(-1);
                        else
                        {
                            splitLine[i] = splitLine[i].Trim();

                            m_Values[i].Add(Int32.Parse(splitLine[i]));
                        }
                    }
                }
            }
        }

        public static int Convert(int value, out int fileIndex)
        {
            int index = GetIndex(value);

            if (index >= 0)
            {
                for (int i = 1; i < m_Values.Count; i++)
                {
                    if (m_Values[i][index] != -1)
                    {
                        fileIndex = i + 1;

                        return m_Values[i][index];
                    }
                }
            }

            fileIndex = 1;

            return value;
        }

        private static int GetIndex(int value)
        {
            for (int i = 0; i < m_Values[0].Count; i++)
            {
                if (m_Values[0][i] == value)
                    return i;
            }

            return -1;
        }
    }
}
Code:
// fileIndex:
// 1 = anim.mul
// 2 = anim2.mul
// 3 = anim3.mul
// 4 = anim4.mul
// 5 = anim5.mul

int bodyID = 917;
int fileIndex;

bodyID = BodyConverter.Convert(bodyID, out fileIndex);

// Result: bodyID = 637 & fileIndex = 5

Last edited by I Cheat; 09-23-2007 at 12:42 AM. Reason: Small change & example.
I Cheat is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5