private static void AddEnemy(
            DFBlock.RdbObject obj,
            MobileTypes type,
            Transform parent = null,
            DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold)
        {
            // Get default reaction
            MobileReactions reaction = MobileReactions.Hostile;

            if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive)
            {
                reaction = MobileReactions.Passive;
            }

            // Just setup demo enemies at this time
            string         name       = string.Format("DaggerfallEnemy [{0}]", type.ToString());
            Vector3        position   = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;
            GameObject     go         = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, parent, position);
            SetupDemoEnemy setupEnemy = go.GetComponent <SetupDemoEnemy>();

            if (setupEnemy != null)
            {
                // Configure enemy
                setupEnemy.ApplyEnemySettings(type, reaction);

                // Align non-flying units with ground
                DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild();
                if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying)
                {
                    GameObjectHelper.AlignControllerToGround(go.GetComponent <CharacterController>());
                }
            }
        }
        private void AddAction(GameObject go, DFBlock blockData, DFBlock.RdbObject obj, int modelReference)
        {
            // Get model action record and description
            DFBlock.RdbActionResource action = obj.Resources.ModelResource.ActionResource;
            string description = blockData.RdbBlock.ModelReferenceList[modelReference].Description;

            // Check for known action types
            Vector3 actionRotation    = Vector3.zero;
            Vector3 actionTranslation = Vector3.zero;

            if ((action.Flags & (int)DFBlock.RdbActionFlags.Rotation) == (int)DFBlock.RdbActionFlags.Rotation)
            {
                actionRotation = (GetActionVector(ref action) / BlocksFile.RotationDivisor);
            }
            if ((action.Flags & (int)DFBlock.RdbActionFlags.Translation) == (int)DFBlock.RdbActionFlags.Translation)
            {
                actionTranslation = GetActionVector(ref action) * MeshReader.GlobalScale;
            }

            // A quick hack to fix special-case rotation issues.
            // Currently unknown if there is data indicating different rotation behaviour or if something else is happening.
            switch (description)
            {
            case "LID":
                actionRotation = new Vector3(0, 0, -90f);           // Coffin lids in Scourg barrow
                break;

            case "WHE":
                actionRotation = new Vector3(0, -360f, 0);          // Wheels in Direnni Tower
                break;
            }

            // Create action component
            DaggerfallAction c = go.AddComponent <DaggerfallAction>();

            c.ActionEnabled     = true;
            c.ModelDescription  = description;
            c.ActionRotation    = actionRotation;
            c.ActionTranslation = actionTranslation;
            c.ActionSoundID     = obj.Resources.ModelResource.SoundId;

            // Set duration in seconds
            // Not sure what timescale native value represents
            // Using 1/20 of native value in seconds
            c.ActionDuration = (float)action.Duration / 20f;
            c.ActionFlags    = action.Flags;

            // Create action links
            ActionLink link;

            link.gameObject = go;
            link.nextKey    = GetActionKey(groupIndex, action.NextObjectIndex);
            link.prevKey    = GetActionKey(groupIndex, action.PreviousObjectIndex);
            actionLinkDict.Add(GetActionKey(groupIndex, obj.Index), link);

            // Add sound
            AddActionAudioSource(go, (uint)c.ActionSoundID);

            return;
        }
Beispiel #3
0
        private void ReadRdbModelActionRecords(BinaryReader reader, ref DFBlock.RdbObject rdbObject, DFBlock.RdbObject[] rdbObjects)
        {
            // Go to action offset
            reader.BaseStream.Position = rdbObject.Resources.ModelResource.ActionOffset;

            // Read action data
            rdbObject.Resources.ModelResource.ActionResource.Position         = reader.BaseStream.Position;
            rdbObject.Resources.ModelResource.ActionResource.Axis             = reader.ReadByte();
            rdbObject.Resources.ModelResource.ActionResource.Duration         = reader.ReadUInt16();
            rdbObject.Resources.ModelResource.ActionResource.Magnitude        = reader.ReadUInt16();
            rdbObject.Resources.ModelResource.ActionResource.NextObjectOffset = reader.ReadInt32();
            rdbObject.Resources.ModelResource.ActionResource.Flags            = reader.ReadByte();

            // Exit if no action target
            if (rdbObject.Resources.ModelResource.ActionResource.NextObjectOffset < 0)
            {
                return;
            }

            // Find index of action offset in object array
            int index = 0;

            foreach (DFBlock.RdbObject obj in rdbObjects)
            {
                if (obj.This ==
                    rdbObject.Resources.ModelResource.ActionResource.NextObjectOffset)
                {
                    // Set target and and parent indices
                    rdbObject.Resources.ModelResource.ActionResource.NextObjectIndex = index;
                    rdbObjects[index].Resources.ModelResource.ActionResource.PreviousObjectOffset = rdbObject.This;
                    break;
                }
                index++;
            }
        }
        private void ReadRdbModelActionRecords(ref BinaryReader Reader, ref DFBlock.RdbObject RdbObject, DFBlock.RdbObject[] RdbObjects)
        {
            // Go to action offset
            Reader.BaseStream.Position = RdbObject.Resources.ModelResource.ActionOffset;

            // Read action data
            RdbObject.Resources.ModelResource.ActionResource.Position         = Reader.BaseStream.Position;
            RdbObject.Resources.ModelResource.ActionResource.Axis             = (DFBlock.RdbActionAxes)Reader.ReadByte();
            RdbObject.Resources.ModelResource.ActionResource.Duration         = Reader.ReadUInt16();
            RdbObject.Resources.ModelResource.ActionResource.Magnitude        = Reader.ReadUInt16();
            RdbObject.Resources.ModelResource.ActionResource.NextObjectOffset = Reader.ReadInt32();
            RdbObject.Resources.ModelResource.ActionResource.ActionType       = (DFBlock.RdbActionType)Reader.ReadByte();

            // Exit if no action target
            if (RdbObject.Resources.ModelResource.ActionResource.NextObjectOffset < 0)
            {
                return;
            }

            // Find index of action offset in object array
            int index = 0;

            foreach (DFBlock.RdbObject obj in RdbObjects)
            {
                if (obj.This ==
                    RdbObject.Resources.ModelResource.ActionResource.NextObjectOffset)
                {
                    // Set target and and parent indices
                    RdbObject.Resources.ModelResource.ActionResource.NextObjectIndex             = index;
                    RdbObjects[index].Resources.ModelResource.ActionResource.PreviousObjectIndex = RdbObject.Index;
                    break;
                }
                index++;
            }
        }
Beispiel #5
0
        private static void AddRandomRDBEnemy(
            DFBlock.RdbObject obj,
            DFRegion.DungeonTypes dungeonType,
            float monsterPower,
            int monsterVariance,
            Transform parent,
            ref DFBlock blockData,
            bool serialize)
        {
            // Must have a dungeon type
            if (dungeonType == DFRegion.DungeonTypes.NoDungeon)
            {
                return;
            }

            // Get dungeon type index
            int dungeonIndex = (int)dungeonType >> 8;

            if (dungeonIndex < RandomEncounters.EncounterTables.Length)
            {
                // Get encounter table
                RandomEncounterTable table = RandomEncounters.EncounterTables[dungeonIndex];

                // Get base monster index into table
                int baseMonsterIndex = (int)((float)table.Enemies.Length * monsterPower);

                // Set min index
                int minMonsterIndex = baseMonsterIndex - monsterVariance;
                if (minMonsterIndex < 0)
                {
                    minMonsterIndex = 0;
                }

                // Set max index
                int maxMonsterIndex = baseMonsterIndex + monsterVariance;
                if (maxMonsterIndex >= table.Enemies.Length)
                {
                    maxMonsterIndex = table.Enemies.Length;
                }

                // Get random monster from table
                MobileTypes type = table.Enemies[UnityEngine.Random.Range(minMonsterIndex, maxMonsterIndex)];

                // Create unique LoadID for save sytem
                long loadID = 0;
                if (serialize)
                {
                    loadID = (blockData.Index << 24) + obj.This;
                }

                // Add enemy
                AddEnemy(obj, type, parent, loadID);
            }
            else
            {
                DaggerfallUnity.LogMessage(string.Format("RDBLayout: Dungeon type {0} is out of range or unknown.", dungeonType), true);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Check is model has action record.
 /// </summary>
 private static bool HasAction(DFBlock.RdbObject obj)
 {
     DFBlock.RdbActionResource action = obj.Resources.ModelResource.ActionResource;
     if (action.Flags != 0)
     {
         return(true);
     }
     return(false);
 }
        private void AddRDBFlat(DFBlock.RdbObject obj, Transform parent)
        {
            int archive = obj.Resources.FlatResource.TextureArchive;
            int record  = obj.Resources.FlatResource.TextureRecord;

            // Spawn billboard gameobject
            GameObject go = GameObjectHelper.CreateDaggerfallBillboardGameObject(archive, record, parent, true);
            Vector3    billboardPosition = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;

            // Add RDB data to billboard
            DaggerfallBillboard dfBillboard = go.GetComponent <DaggerfallBillboard>();

            dfBillboard.SetResourceData(obj.Resources.FlatResource);

            // Set transform
            go.transform.position = billboardPosition;

            // Handle supported editor flats
            if (dfUnity.Option_ImportEnemies && archive == 199)
            {
                switch (record)
                {
                case 10:                            // Start marker
                    startMarkers.Add(go);
                    break;

                case 15:                            // Random enemy
                    AddRandomRDBEnemy(obj);
                    go.SetActive(false);
                    break;

                case 16:                            // Fixed enemy
                    AddFixedRDBEnemy(obj);
                    go.SetActive(false);
                    break;
                }
            }

            // Add torch burning sound
            if (dfUnity.Option_DefaultSounds && archive == 210)
            {
                switch (record)
                {
                case 0:
                case 1:
                case 6:
                case 16:
                case 17:
                case 18:
                case 19:
                case 20:
                    AddTorchAudioSource(go);
                    break;
                }
            }
        }
 /// <summary>
 /// Sets NPC data from RDB layout.
 /// </summary>
 public void SetLayoutData(DFBlock.RdbObject obj)
 {
     // Store common layout data
     npcData.hash      = GetPositionHash(obj.XPos, obj.YPos, obj.ZPos);
     npcData.flags     = obj.Resources.FlatResource.Flags;
     npcData.factionID = obj.Resources.FlatResource.FactionOrMobileId;
     npcData.nameSeed  = (int)obj.Resources.FlatResource.Position;
     npcData.gender    = ((npcData.flags & 32) == 32) ? Genders.Female : Genders.Male;
     npcData.context   = Context.Dungeon;
 }
Beispiel #9
0
        private void ReadRdbLightResource(BinaryReader reader, ref DFBlock.RdbObject rdbObject)
        {
            // Go to resource offset
            reader.BaseStream.Position = rdbObject.ResourceOffset;

            // Read light data
            rdbObject.Resources.LightResource.Unknown1 = reader.ReadUInt32();
            rdbObject.Resources.LightResource.Unknown2 = reader.ReadUInt32();
            rdbObject.Resources.LightResource.Radius   = reader.ReadUInt16();
        }
    /*
     * private void PrepMesh()
     * {
     *  int[] textureTable = new int[] { 119, 120, 122, 123, 124, 168 };
     *  uint _ModelId = (uint)ModelId;
     *
     *  DaggerfallUnity dfUnity = DaggerfallUnity.Instance;
     *
     *  DFBlock.RdbObject obj = new DFBlock.RdbObject();
     *
     *  Matrix4x4 modelMatrix = GetModelMatrix(obj);
     *
     *  // Get model data
     *  DaggerfallWorkshop.ModelData modelData = new ModelData();
     *  dfUnity.MeshReader.GetModelData(_ModelId, out modelData);
     * }
     */

    public static BareDaggerfallMeshStats GetBareMeshFromId(int ModelID)
    {
        BareDaggerfallMeshStats MeshDat = new BareDaggerfallMeshStats();

        // ---------------
        int[] textureTable = new int[] { 119, 120, 122, 123, 124, 168 };
        uint  _ModelId     = (uint)ModelID;

        DaggerfallUnity dfUnity = DaggerfallUnity.Instance;

        DFBlock.RdbObject obj = new DFBlock.RdbObject();

        Matrix4x4 modelMatrix = GetModelMatrix(obj);

        // Get model data
        DaggerfallWorkshop.ModelData modelData = new ModelData();
        dfUnity.MeshReader.GetModelData(_ModelId, out modelData);
        // ---------------


        // DIVERT MESH FUNCTIONALITY HERE
        // Maybe model ID, or makestatic
        CachedMaterial[] cachedMaterials;
        int[]            textureKeys;
        //textureKeys = DungeonTextureTables.DefaultTextureTable;
        bool hasAnimations;

        MeshDat.mesh = dfUnity.MeshReader.GetMesh(
            dfUnity,
            (uint)ModelID,
            out cachedMaterials,
            out textureKeys,
            out hasAnimations,
            dfUnity.MeshReader.AddMeshTangents,
            dfUnity.MeshReader.AddMeshLightmapUVs);

        MeshDat.matrix       = modelMatrix;
        MeshDat.SubMeshIndex = modelData.SubMeshes.Length;      // May be only drawing one submesh

        MeshDat.mat   = new Material[cachedMaterials.Length];
        MeshDat.mProp = new MaterialPropertyBlock();
        for (int i = 0; i < cachedMaterials.Length; i++)
        {
            MeshDat.mProp.SetTexture(i, cachedMaterials[i].material.mainTexture);
            MeshDat.mat[i] = cachedMaterials[i].material;
        }
        //meshRenderer.sharedMaterials = GetMaterialArray(cachedMaterials);
        //dfMesh.SetDefaultTextures(textureKeys);


        //SetDefaultTextures(textureKeys);
        //MeshDat.mat = SetBaseMeshTextures(textureTable);

        return(MeshDat);
    }
        private static bool HasAction(DFBlock blockData, DFBlock.RdbObject obj, int modelReference)
        {
            // Allow for known action types
            DFBlock.RdbActionResource action = obj.Resources.ModelResource.ActionResource;
            if (action.Flags != 0)
            {
                return(true);
            }

            return(false);
        }
Beispiel #12
0
 /// <summary>
 /// Sets NPC data from RDB layout.
 /// </summary>
 public void SetLayoutData(DFBlock.RdbObject obj)
 {
     SetLayoutData(ref npcData,
                   obj.XPos, obj.YPos, obj.ZPos,
                   obj.Resources.FlatResource.Flags,
                   obj.Resources.FlatResource.FactionOrMobileId,
                   obj.Resources.FlatResource.TextureArchive,
                   obj.Resources.FlatResource.TextureRecord,
                   obj.Resources.FlatResource.Position,
                   0);
     npcData.context = Context.Dungeon;
 }
        private static bool IsActionDoor(DFBlock blockData, DFBlock.RdbObject obj, int modelReference)
        {
            // Check if this is a door (DOR) or double-door (DDR)
            string description = blockData.RdbBlock.ModelReferenceList[modelReference].Description;

            if (description == "DOR" || description == "DDR")
            {
                return(true);
            }

            return(false);
        }
Beispiel #14
0
        private static void AddActionModelHelper(
            GameObject go,
            Dictionary <int, ActionLink> actionLinkDict,
            DFBlock.RdbObject rdbObj,
            ref DFBlock blockData,
            bool serialize)
        {
            DFBlock.RdbModelResource obj = rdbObj.Resources.ModelResource;
            string description           = blockData.RdbBlock.ModelReferenceList[obj.ModelIndex].Description;
            int    soundID_Index         = obj.SoundIndex;
            float  duration  = obj.ActionResource.Duration;
            float  magnitude = obj.ActionResource.Magnitude;
            int    axis      = obj.ActionResource.Axis;

            DFBlock.RdbTriggerFlags triggerFlag = DFBlock.RdbTriggerFlags.None;
            DFBlock.RdbActionFlags  actionFlag  = DFBlock.RdbActionFlags.None;

            if (actionLinkDict != null)
            {
                // Set action flag if valid / known
                if (Enum.IsDefined(typeof(DFBlock.RdbActionFlags), (DFBlock.RdbActionFlags)obj.ActionResource.Flags))
                {
                    actionFlag = (DFBlock.RdbActionFlags)obj.ActionResource.Flags;
                }

                // Set trigger flag if valid / known
                if (Enum.IsDefined(typeof(DFBlock.RdbTriggerFlags), (DFBlock.RdbTriggerFlags)obj.TriggerFlag_StartingLock))
                {
                    triggerFlag = (DFBlock.RdbTriggerFlags)obj.TriggerFlag_StartingLock;
                }

                // Add action node to actionLink dictionary
                if (!actionLinkDict.ContainsKey(rdbObj.This))
                {
                    ActionLink link;
                    link.nextKey    = obj.ActionResource.NextObjectOffset;
                    link.prevKey    = obj.ActionResource.PreviousObjectOffset;
                    link.gameObject = go;
                    actionLinkDict.Add(rdbObj.This, link);
                }
            }

            // Create unique LoadID for save sytem
            long loadID = 0;

            if (serialize)
            {
                loadID = (blockData.Index << 24) + rdbObj.This;
            }

            AddAction(go, description, soundID_Index, duration, magnitude, axis, triggerFlag, actionFlag, loadID);
        }
        private void ReadRdbFlatResource(ref BinaryReader Reader, ref DFBlock.RdbObject RdbObject)
        {
            // Go to resource offset
            Reader.BaseStream.Position = RdbObject.ResourceOffset;

            // Read flat data
            RdbObject.Resources.FlatResource.TextureBitfield = Reader.ReadUInt16();
            RdbObject.Resources.FlatResource.TextureArchive  = RdbObject.Resources.FlatResource.TextureBitfield >> 7;
            RdbObject.Resources.FlatResource.TextureRecord   = RdbObject.Resources.FlatResource.TextureBitfield & 0x7f;
            RdbObject.Resources.FlatResource.Gender          = (DFBlock.RdbFlatGenders)Reader.ReadUInt16();
            RdbObject.Resources.FlatResource.FactionId       = Reader.ReadUInt16();
            RdbObject.Resources.FlatResource.Unknown1        = Reader.ReadBytes(5);
        }
        /// <summary>
        /// Adds RDB light source.
        /// </summary>
        /// <param name="obj">RdbObject.</param>
        private void AddRDBLight(DFBlock.RdbObject obj)
        {
            BlockLight light = new BlockLight
            {
                Dungeon  = true,
                Position = new Vector3(obj.XPos, -obj.YPos, -obj.ZPos) * ModelManager.GlobalScale,
                Radius   = (obj.Resources.LightResource.Radius) * ModelManager.GlobalScale,
                Unknown1 = obj.Resources.LightResource.Unknown1,
                Unknown2 = obj.Resources.LightResource.Unknown2,
            };

            blockLights.Add(light);
        }
        /// <summary>
        /// Adds RDB flat.
        /// </summary>
        /// <param name="obj">RdbObject.</param>
        private void AddRDBFlat(DFBlock.RdbObject obj)
        {
            BlockFlat flat = new BlockFlat
            {
                Dungeon  = true,
                Archive  = obj.Resources.FlatResource.TextureArchive,
                Record   = obj.Resources.FlatResource.TextureRecord,
                Position = new Vector3(obj.XPos, -obj.YPos, -obj.ZPos) * ModelManager.GlobalScale,
                Type     = GetFlatType(obj.Resources.FlatResource.TextureArchive),
            };

            blockFlats.Add(flat);
        }
        public static GameObject AddLightObject(Transform parent, DFBlock.RdbObject obj)
        {
            // Spawn light gameobject
            float      range    = obj.Resources.LightResource.Radius * MeshReader.GlobalScale;
            Vector3    position = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;
            GameObject go       = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_InteriorLightPrefab.gameObject, string.Empty, parent, position);
            Light      light    = go.GetComponent <Light>();

            if (light != null)
            {
                light.range = range * 3;
            }
            return(go);
        }
        /// <summary>
        /// Adds RDB flat to scene node.
        /// </summary>
        /// <param name="obj">RdbObject.</param>
        /// <param name="blockNode">BlockNode.</param>
        private void AddRDBFlat(DFBlock.RdbObject obj, BlockNode blockNode)
        {
            // Get flat type
            BillboardNode.BillboardType billboardType =
                GetFlatType(obj.Resources.FlatResource.TextureArchive);

            // Add light if needed

            // Load flat
            int     textureKey;
            Vector2 startSize;
            Vector2 finalSize;

            if (true == LoadDaggerfallFlat(
                    obj.Resources.FlatResource.TextureArchive,
                    obj.Resources.FlatResource.TextureRecord,
                    TextureManager.TextureCreateFlags.Dilate |
                    TextureManager.TextureCreateFlags.PreMultiplyAlpha,
                    out textureKey,
                    out startSize,
                    out finalSize))
            {
                // Foliage (TEXTURE.500 and up) do not seem to use scaling
                // in dungeons. Revert scaling.
                if (obj.Resources.FlatResource.TextureArchive > 499)
                {
                    finalSize = startSize;
                }

                // Calcuate position
                Vector3 position = new Vector3(
                    obj.XPos,
                    -obj.YPos,
                    -obj.ZPos);

                // Create billboard node
                BillboardNode billboardNode = new BillboardNode(
                    billboardType,
                    textureKey,
                    finalSize);
                billboardNode.Position = position;
                blockNode.Add(billboardNode);

                // Add point light node
                if (billboardType == BillboardNode.BillboardType.Light)
                {
                    AddPointLight(position, PointLightNode.DungeonRadius, blockNode);
                }
            }
        }
Beispiel #20
0
        private static void AddActionFlatHelper(
            GameObject go,
            Dictionary <int, ActionLink> actionLinkDict,
            ref DFBlock blockData,
            DFBlock.RdbObject rdbObj,
            bool serialize = true)
        {
            DFBlock.RdbFlatResource obj = rdbObj.Resources.FlatResource;
            string description          = "FLT";
            int    soundID_Index        = obj.Sound_index;
            float  duration             = 0.0f;
            float  magnitude            = obj.Magnitude;
            int    axis = obj.Magnitude;

            DFBlock.RdbTriggerFlags triggerFlag = DFBlock.RdbTriggerFlags.None;
            DFBlock.RdbActionFlags  actionFlag  = DFBlock.RdbActionFlags.None;

            //set action flag if valid / known
            if (Enum.IsDefined(typeof(DFBlock.RdbActionFlags), (DFBlock.RdbActionFlags)obj.Action))
            {
                actionFlag = (DFBlock.RdbActionFlags)obj.Action;
            }

            //set trigger flag if valid / known
            if (Enum.IsDefined(typeof(DFBlock.RdbTriggerFlags), (DFBlock.RdbTriggerFlags)obj.TriggerFlag))
            {
                triggerFlag = (DFBlock.RdbTriggerFlags)obj.TriggerFlag;
            }

            //add action node to actionLink dictionary
            if (!actionLinkDict.ContainsKey(rdbObj.This))
            {
                ActionLink link;
                link.nextKey    = obj.NextObjectOffset;
                link.prevKey    = -1;
                link.gameObject = go;
                actionLinkDict.Add(rdbObj.This, link);
            }

            // Create unique LoadID for save sytem
            long loadID = 0;

            if (serialize)
            {
                loadID = (blockData.Index << 24) + rdbObj.This;
            }

            AddAction(go, description, soundID_Index, duration, magnitude, axis, triggerFlag, actionFlag, loadID);
        }
        private static void AddFixedRDBEnemy(DFBlock.RdbObject obj, Transform parent)
        {
            // Get type value and ignore known invalid types
            int typeValue = (int)(obj.Resources.FlatResource.FactionMobileId & 0xff);

            if (typeValue == 99)
            {
                return;
            }

            // Cast to enum
            MobileTypes type = (MobileTypes)(obj.Resources.FlatResource.FactionMobileId & 0xff);

            AddEnemy(obj, type, parent);
        }
        /// <summary>
        /// Sets NPC data from RDB layout.
        /// </summary>
        public void SetLayoutData(DFBlock.RdbObject obj)
        {
            PlayerGPS playerGPS = GameManager.Instance.PlayerGPS;

            SetLayoutData(ref npcData,
                          obj.XPos, obj.YPos, obj.ZPos,
                          obj.Resources.FlatResource.Flags,
                          obj.Resources.FlatResource.FactionOrMobileId,
                          obj.Resources.FlatResource.TextureArchive,
                          obj.Resources.FlatResource.TextureRecord,
                          obj.Resources.FlatResource.Position,
                          playerGPS.CurrentMapID,
                          playerGPS.CurrentLocation.LocationIndex,
                          0);
            npcData.context = Context.Dungeon;
        }
        private void ReadRdbFlatResource(BinaryReader reader, ref DFBlock.RdbObject rdbObject)
        {
            // Go to resource offset
            reader.BaseStream.Position = rdbObject.ResourceOffset;

            // Read flat data
            rdbObject.Resources.FlatResource.TextureBitfield   = reader.ReadUInt16();
            rdbObject.Resources.FlatResource.TextureArchive    = rdbObject.Resources.FlatResource.TextureBitfield >> 7;
            rdbObject.Resources.FlatResource.TextureRecord     = rdbObject.Resources.FlatResource.TextureBitfield & 0x7f;
            rdbObject.Resources.FlatResource.Gender            = (DFBlock.RdbFlatGenders)reader.ReadUInt16();
            rdbObject.Resources.FlatResource.FactionMobileId   = reader.ReadUInt16();
            rdbObject.Resources.FlatResource.FlatData.Unknown1 = reader.ReadByte();
            rdbObject.Resources.FlatResource.FlatData.Unknown2 = reader.ReadByte();
            rdbObject.Resources.FlatResource.FlatData.Unknown3 = reader.ReadByte();
            rdbObject.Resources.FlatResource.FlatData.Unknown4 = reader.ReadByte();
            rdbObject.Resources.FlatResource.FlatData.Reaction = reader.ReadByte();
        }
Beispiel #24
0
        private void ReadRdbFlatResource(BinaryReader reader, ref DFBlock.RdbObject rdbObject)
        {
            // Go to resource offset
            reader.BaseStream.Position = rdbObject.ResourceOffset;

            // Read flat data
            rdbObject.Resources.FlatResource.TextureBitfield  = reader.ReadUInt16();
            rdbObject.Resources.FlatResource.TextureArchive   = rdbObject.Resources.FlatResource.TextureBitfield >> 7;
            rdbObject.Resources.FlatResource.TextureRecord    = rdbObject.Resources.FlatResource.TextureBitfield & 0x7f;
            rdbObject.Resources.FlatResource.TriggerFlag      = reader.ReadUInt16();
            rdbObject.Resources.FlatResource.Magnitude        = reader.ReadByte();
            rdbObject.Resources.FlatResource.SoundIndex       = reader.ReadByte();
            rdbObject.Resources.FlatResource.Gender           = (DFBlock.RdbFlatGenders)rdbObject.Resources.FlatResource.TriggerFlag;
            rdbObject.Resources.FlatResource.FactionMobileId  = BitConverter.ToUInt16(new byte[] { rdbObject.Resources.FlatResource.Magnitude, rdbObject.Resources.FlatResource.SoundIndex }, 0);
            rdbObject.Resources.FlatResource.NextObjectOffset = reader.ReadInt32();
            rdbObject.Resources.FlatResource.Action           = reader.ReadByte();
        }
        /// <summary>
        /// Check if model is a hinged action door.
        /// </summary>
        private static bool IsActionDoor(ref DFBlock blockData, DFBlock.RdbObject obj, int modelReference)
        {
            // Always reject red brick doors, they are not action doors despite having "DOR" attached
            if (blockData.RdbBlock.ModelReferenceList[modelReference].ModelIdNum == redBrickDoorModelID)
            {
                return(false);
            }

            // Otherwise Check if this is a door (DOR) or double-door (DDR)
            string description = blockData.RdbBlock.ModelReferenceList[modelReference].Description;

            if (description == "DOR" || description == "DDR")
            {
                return(true);
            }

            return(false);
        }
        private static GameObject AddFlat(DFBlock.RdbObject obj, Transform parent)
        {
            int archive = obj.Resources.FlatResource.TextureArchive;
            int record  = obj.Resources.FlatResource.TextureRecord;

            // Spawn billboard gameobject
            GameObject go = GameObjectHelper.CreateDaggerfallBillboardGameObject(archive, record, parent, true);
            Vector3    billboardPosition = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;

            // Add RDB data to billboard
            DaggerfallBillboard dfBillboard = go.GetComponent <DaggerfallBillboard>();

            dfBillboard.SetResourceData(obj.Resources.FlatResource);

            // Set transform
            go.transform.position = billboardPosition;

            // Disable enemy flats
            if (archive == TextureReader.EditorFlatsTextureArchive && (record == 15 || record == 16))
            {
                go.SetActive(false);
            }

            // Add torch burning sound
            if (archive == TextureReader.LightsTextureArchive)
            {
                switch (record)
                {
                case 0:
                case 1:
                case 6:
                case 16:
                case 17:
                case 18:
                case 19:
                case 20:
                    AddTorchAudioSource(go);
                    break;
                }
            }

            return(go);
        }
        public static GameObject AddFlatObject(DFBlock.RdbObject obj)
        {
            int archive = obj.Resources.FlatResource.TextureArchive;
            int record  = obj.Resources.FlatResource.TextureRecord;

            // Add GameObject to scene
            Vector3    targetPosition = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale;
            GameObject go             = MeshReplacement.ImportCustomFlatGameobject(archive, record, targetPosition, null, true);

            if (!go)
            {
                // Setup standard billboard and assign RDB data
                go = GameObjectHelper.CreateDaggerfallBillboardGameObject(archive, record, null);
                go.transform.position = targetPosition;
                Billboard dfBillboard = go.GetComponent <Billboard>();
                dfBillboard.SetRDBResourceData(obj.Resources.FlatResource);
            }
            return(go);
        }
        /// <summary>
        /// Adds RDB model to the batch.
        /// </summary>
        /// <param name="block">DFBlock.</param>
        /// <param name="obj">RdbObject.</param>
        private void AddRDBModel(ref DFBlock block, DFBlock.RdbObject obj)
        {
            // Get model reference index, desc, and id
            int    modelReference   = obj.Resources.ModelResource.ModelIndex;
            string modelDescription = block.RdbBlock.ModelReferenceList[modelReference].Description;
            uint   modelId          = block.RdbBlock.ModelReferenceList[modelReference].ModelIdNum;

            // Get rotation angle for each axis
            float degreesX = obj.Resources.ModelResource.XRotation / BlocksFile.RotationDivisor;
            float degreesY = obj.Resources.ModelResource.YRotation / BlocksFile.RotationDivisor;
            float degreesZ = -obj.Resources.ModelResource.ZRotation / BlocksFile.RotationDivisor;

            // Calcuate position
            Vector3 position = new Vector3(obj.XPos, -obj.YPos, -obj.ZPos) * ModelManager.GlobalScale;

            // Calculate rotation
            Vector3 rotation = new Vector3(
                MathHelper.ToRadians(degreesX),
                MathHelper.ToRadians(degreesY),
                MathHelper.ToRadians(degreesZ));

            // Create transforms
            Matrix rotationX   = Matrix.CreateRotationX(rotation.X);
            Matrix rotationY   = Matrix.CreateRotationY(rotation.Y);
            Matrix rotationZ   = Matrix.CreateRotationZ(rotation.Z);
            Matrix translation = Matrix.CreateTranslation(position);

            // Create model transform
            Matrix modelMatrix = Matrix.Identity;

            Matrix.Multiply(ref modelMatrix, ref rotationY, out modelMatrix);
            Matrix.Multiply(ref modelMatrix, ref rotationX, out modelMatrix);
            Matrix.Multiply(ref modelMatrix, ref rotationZ, out modelMatrix);
            Matrix.Multiply(ref modelMatrix, ref translation, out modelMatrix);

            // Load model data
            ModelManager.ModelData modelData;
            LoadModel(modelId, out modelData);

            // Add model data to batch builder
            staticGeometry.AddToBuilder(ref modelData, modelMatrix);
        }
Beispiel #29
0
        public void CreateData(DFBlock.RdbObject obj, int rol, DataType type)
        {
            if (type != DataType.Light)
            {
                HideComponents();
            }

            rdbObjListIdx = rol;
            rdbObj        = obj;
            this.type     = type;
            if (type == DataType.Flat)
            {
                id        = obj.Resources.FlatResource.TextureArchive + "." + obj.Resources.FlatResource.TextureRecord;
                factionID = (short)obj.Resources.FlatResource.FactionOrMobileId;
            }
            else if (type == DataType.Light)
            {
                radius = obj.Resources.LightResource.Radius;
            }
        }
Beispiel #30
0
        private void ReadRdbModelResource(BinaryReader reader, ref DFBlock.RdbObject rdbObject, DFBlock.RdbObject[] rdbObjects)
        {
            // Go to resource offset
            reader.BaseStream.Position = rdbObject.ResourceOffset;

            // Read model data
            rdbObject.Resources.ModelResource.XRotation  = reader.ReadInt32();
            rdbObject.Resources.ModelResource.YRotation  = reader.ReadInt32();
            rdbObject.Resources.ModelResource.ZRotation  = reader.ReadInt32();
            rdbObject.Resources.ModelResource.ModelIndex = reader.ReadUInt16();
            rdbObject.Resources.ModelResource.TriggerFlag_StartingLock = reader.ReadUInt32();
            rdbObject.Resources.ModelResource.SoundIndex   = reader.ReadByte();
            rdbObject.Resources.ModelResource.ActionOffset = reader.ReadInt32();

            // Read action data
            if (rdbObject.Resources.ModelResource.ActionOffset > 0)
            {
                ReadRdbModelActionRecords(reader, ref rdbObject, rdbObjects);
            }
        }