Exemplo n.º 1
0
        public void DisableAPI()
        {
            // Some calls assuring the Disable() API is accessible and working.
            SkyrimMod    sourceMod    = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            FormKey      key          = sourceMod.GetNextFormKey();
            PlacedObject placedObject = new PlacedObject(key, SkyrimRelease.SkyrimSE);

            // Simplistic Disable access and verification.
            PlacedObject disabledObj = placedObject;

            disabledObj.Disable();
            //_testOutputHelper.WriteLine($"{disabledPlacedObject.MajorRecordFlagsRaw}");
            Assert.True(EnumExt.HasFlag(disabledObj.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            MajorRecord majorRecord = placedObject;

            majorRecord.Disable();
            Assert.True(EnumExt.HasFlag(majorRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IMajorRecordCommon interfaceRecord = placedObject;

            interfaceRecord.Disable();
            Assert.True(EnumExt.HasFlag(interfaceRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IPlaced interfacePlaced = placedObject;

            interfacePlaced.Disable();
            Assert.True(EnumExt.HasFlag(interfacePlaced.MajorRecordFlagsRaw, Constants.InitiallyDisabled));

            // Sanity test both API are invokable under Placed context.
            PlacedTrap placedTrap = new PlacedTrap(key, SkyrimRelease.SkyrimSE);

            placedTrap.Disable(IPlaced.DisableType.DisableWithoutZOffset);
            interfacePlaced = placedTrap;
            interfacePlaced.Disable(IPlaced.DisableType.JustInitiallyDisabled);
            IPlaced abstractPlaced = placedTrap;

            abstractPlaced.Disable();
            abstractPlaced.Disable(IPlaced.DisableType.SafeDisable);

            //Try any other object other than Placed (invoke MajorRecord.Disable() and see if it works)
            var armor = new Armor(key, SkyrimRelease.SkyrimSE);

            armor.Disable();
            Assert.True(EnumExt.HasFlag(armor.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
        }
Exemplo n.º 2
0
    private void PlaceTraps()
    {
        DungeonBiomeData biomeData = Game.instance.currentDungeonData.biomeData;

        // Collect regions with shared trap IDs
        Dictionary <int, List <Vector2Int> > regions = new Dictionary <int, List <Vector2Int> >();

        for (int x = 0; x < mDungeon.width; ++x)
        {
            for (int y = 0; y < mDungeon.height; ++y)
            {
                RandomDungeonTileData td = mDungeon.Data(x, y);
                if (td.trap >= 0)
                {
                    List <Vector2Int> positions = null;
                    bool exists = regions.TryGetValue(td.trap, out positions);
                    if (!exists)
                    {
                        positions = new List <Vector2Int>();
                        regions.Add(td.trap, positions);
                    }

                    positions.Add(new Vector2Int(x, y));
                }
            }
        }

        // Try to place the traps
        // Traps may have requirements - ie: they may require certain region sizes
        // They may also conditionally take up 1 or all spaces of a region
        // todo bdsowers - break traps apart into traps & spawners so that traps
        // aren't responsible for spawning themselves, which is awkward...

        // Now generate traps, filling the respective regions (where still possible)

        // Find all the trap generators
        List <PlacedTrap> trapPlacerPrefabs = new List <PlacedTrap>();
        int maxTrapPrefabsToConsider        = MaxTrapsToConsider(biomeData);

        for (int i = 0; i < maxTrapPrefabsToConsider; ++i)
        {
            string prefabName = biomeData.trapPrefabs[i];

            GameObject prefab     = PrefabManager.instance.PrefabByName(prefabName);
            PlacedTrap trapPlacer = prefab.GetComponent <PlacedTrap>();
            if (trapPlacer != null)
            {
                trapPlacerPrefabs.Add(prefab.GetComponent <PlacedTrap>());
            }
            else
            {
                Debug.LogError("Unplaceable trap in biome: " + prefabName);
            }
        }

        List <PlacedTrap> potentialTraps = new List <PlacedTrap>();

        foreach (KeyValuePair <int, List <Vector2Int> > pair in regions)
        {
            int prob = 15;
            if (Game.instance.quirkRegistry.IsQuirkActive <TrapQueenQuirk>())
            {
                prob = 75;
            }

            if (Random.Range(0, 100) > prob)
            {
                continue;
            }

            potentialTraps.Clear();
            potentialTraps.AddRange(trapPlacerPrefabs);

            bool trapPlaced = false;
            while (!trapPlaced && potentialTraps.Count > 0)
            {
                PlacedTrap trap = potentialTraps.Sample();
                if (trap.CanSpawn(pair.Value))
                {
                    trap.Spawn(pair.Value, this);
                    trapPlaced = true;
                }
                else
                {
                    potentialTraps.Remove(trap);
                }
            }
        }
    }
Exemplo n.º 3
0
            static void ParseTemporary(MutagenFrame frame, ICellInternal obj)
            {
                var groupMeta = frame.ReadGroup();
                var formKey   = FormKey.Factory(frame.MetaData.MasterReferences !, BinaryPrimitives.ReadUInt32LittleEndian(groupMeta.ContainedRecordTypeData));

                if (formKey != obj.FormKey)
                {
                    throw new ArgumentException("Cell children group did not match the FormID of the parent cell.");
                }
                obj.TemporaryTimestamp        = BinaryPrimitives.ReadInt32LittleEndian(groupMeta.LastModifiedData);
                obj.TemporaryUnknownGroupData = BinaryPrimitives.ReadInt32LittleEndian(groupMeta.HeaderData.Slice(groupMeta.HeaderData.Length - 4));
                var items = ListBinaryTranslation <IPlaced> .Instance.Parse(
                    reader : frame,
                    transl : (MutagenFrame r, RecordType header, out IPlaced placed) =>
                {
                    switch (header.TypeInt)
                    {
                    case RecordTypeInts.ACHR:
                        placed = PlacedNpc.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.REFR:
                        placed = PlacedObject.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PARW:
                        placed = PlacedArrow.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PBAR:
                        placed = PlacedBarrier.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PBEA:
                        placed = PlacedBeam.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PCON:
                        placed = PlacedCone.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PFLA:
                        placed = PlacedFlame.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PHZD:
                        placed = PlacedHazard.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PMIS:
                        placed = PlacedMissile.CreateFromBinary(r);
                        return(true);

                    case RecordTypeInts.PGRE:
                        placed = PlacedTrap.CreateFromBinary(r);
                        return(true);

                    default:
                        if (ParseTemporaryOutliers(frame, obj))
                        {
                            placed = null !;
                            return(false);
                        }
                        throw new NotImplementedException();
                    }
                });

                obj.Temporary.SetTo(new ExtendedList <IPlaced>(items));
            }