Exemplo n.º 1
0
    private void SetWeaponToPerson(PlacedObject personObject)
    {
        // Remove weapons of person
        IList <Weapon> prevWeapons = personObject.GetComponentsInChildren <Weapon>();

        foreach (Weapon prevWeapon in prevWeapons)
        {
            if (prevWeapon is Fist)
            {
                continue;
            }

            PlacedObject weaponObject = prevWeapon.gameObject.transform.parent.GetComponent <PlacedObject>();
            if (weaponObject != null)
            {
                weaponObject.RemoveWeaponFromPerson();
            }
        }

        IWeapon weapon = (IWeapon)this.prefab.GetComponent <Weapon>();
        Person  person = personObject.prefab.GetComponent <Person>();

        transform.SetParent(personObject.transform);
        transform.position = person.GetWeaponAnchorPos();
        transform.rotation = person.transform.rotation;

        weapon.SetSortingLayerOfTextureOfWeapon(SortingLayerConstants.WEAPON_LAYER_NAME);
        person.Weapon = (Weapon)weapon;

        weapon.SetAnimatorOnFloorFlag(false);
        this.personWhichBelongsTo = personObject;
    }
        public void CheckForCollisions()
        {
            //------------------------THIS WHOLE SYSTEM SHOULD BE SWAPPED OUT
            //------------------------WE HAVE LITERALLY NO REASON NOT TO JUST
            //------------------------CREATE OUR OWN COLLISION SYSTEM, INSTEAD OF
            //------------------------USING ACTUAL PHYSICS. THIS IS SLOW AND
            //------------------------UNDER-PERFORMANT AND SHOULD BE SHUNNED
            if (ghostData.placing != null)
            {
                ghostData.okayToPlace = (ghostData.placing.type == ObjectType.Ground || ghostData.placing.type == ObjectType.Wall);
            }

            Collider2D[] collisions = Physics2D.OverlapCircleAll(transform.position, 0.25f);

            // If no collisions occure then something is terrible and we need to rectify it
            if (collisions == null || collisions.Length == 0)
            {
                ghostData.okayToPlace = false;

                return;
            }

            ghostData.overlapping = new PlacedObject[collisions.Length];

            ghostData.okayToPlace = true;

            for (int i = 0; i < collisions.Length; i++)
            {
                PlacedObject PlacedObject = collisions[i].gameObject.GetComponent <PlacedObject>();

                if (PlacedObject)
                {
                    ghostData.overlapping[i] = collisions[i].gameObject.GetComponent <PlacedObject>();

                    if (ghostData.placing != null)
                    {
                        if (i > 0)
                        {
                            if (ghostData.okayToPlace)
                            {
                                ghostData.okayToPlace = Constructor.NothingBlocking(ghostData.placing, PlacedObject.objectData);
                            }
                        }
                        else
                        {
                            ghostData.okayToPlace = Constructor.NothingBlocking(ghostData.placing, PlacedObject.objectData);
                        }
                    }
                    else
                    {
                        ghostData.okayToPlace = false;
                    }
                }
            }

            if (ghostData.placing != null)
            {
                UpdateColor();
            }
        }
Exemplo n.º 3
0
        public void UpdateGrid()
        {
            grid = new Node[gridSize.x, gridSize.y];

            Vector2 worldBottomLeft = transform.position - new Vector3(PlayAreaSize.x, PlayAreaSize.y);

            for (int x = 0; x < gridSize.x; x++)
            {
                for (int y = 0; y < gridSize.y; y++)
                {
                    Vector3 worldPoint  = worldBottomLeft + new Vector2(x * nodeDiameter, y * nodeDiameter);
                    bool    obstruction = false;

                    Collider2D collision = Physics2D.OverlapCircle(worldPoint, nodeRadius / 2);

                    if (collision != null)
                    {
                        PlacedObject placedObject = collision.GetComponent <PlacedObject>();

                        if (placedObject && placedObject.objectData != null)
                        {
                            if (placedObject.objectData.type == ObjectType.Wall)
                            {
                                obstruction = true;
                            }
                        }
                    }

                    grid[x, y] = new Node(new Vector2(x, y), obstruction, worldPoint);
                }
            }
        }
Exemplo n.º 4
0
 public void OccupyTiles(List <GridTile> currentTiles, PlacedObject placedObj)
 {
     foreach (var tile in currentTiles)
     {
         tile.SetOccupant(placedObj);
     }
 }
Exemplo n.º 5
0
        public void PlacedObjectInCell()
        {
            var mod   = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var block = new CellBlock()
            {
                BlockNumber = 2,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 4,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block.SubBlocks.Add(subBlock);
            mod.Cells.Records.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Cells.Add(cell1);
            subBlock.Cells.Add(cell2);
            var block2 = new CellBlock()
            {
                BlockNumber = 5,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock2 = new CellSubBlock()
            {
                BlockNumber = 8,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block2.SubBlocks.Add(subBlock2);
            mod.Cells.Records.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Cells.Add(cell3);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);

            var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var placedObjOverride = contexts[0].GetOrAddAsOverride(mod2);

            Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey);
            mod2.Cells.Records.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.First().Cells.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.Should().HaveCount(1);
            Assert.Same(placedObjOverride, mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.First());
        }
Exemplo n.º 6
0
 // Token: 0x06001E3A RID: 7738 RVA: 0x001AF10C File Offset: 0x001AD30C
 public GravityAmplifier(PlacedObject placedObject, Room room)
 {
     this.placedObject = placedObject;
     this.pos          = placedObject.pos;
     this.lastPos      = this.pos;
     this.depth        = 0;
     if (!room.GetTile(placedObject.pos).Solid)
     {
         this.depth = ((!room.GetTile(placedObject.pos).wallbehind) ? 2 : 1);
     }
     this.roomSpecks = new System.Collections.Generic.List <GenericZeroGSpeck>();
     this.mySpecks   = new System.Collections.Generic.List <GravityAmplifier.DisruptorSpeck>();
     for (int i = 0; i < 20; i++)
     {
         room.AddObject(new GravityAmplifier.DisruptorSpeck(this.pos + Custom.RNV() * 400f * UnityEngine.Random.value, this));
     }
     this.lights = new float[16, 4];
     for (int j = 0; j < this.lights.GetLength(0); j++)
     {
         this.lights[j, 3] = UnityEngine.Random.value;
     }
     this.pointDir      = Custom.RNV();
     this.getToPointDir = this.pointDir;
     this.dirFac        = UnityEngine.Random.value;
     this.dirFacGetTo   = this.dirFac;
     this.power         = 1f;
     this.lastPower     = 1f;
 }
Exemplo n.º 7
0
    public void AddMaterials(int x, int y, int i, int m)
    {
        int chunkX = (((x / 10) * 10));
        int chunkY = (((y / 10) * 10));

        using (StreamReader stream = new StreamReader(streamPath + chunkX.ToString() + "_" + chunkY.ToString() + ".json"))
        {
            string json = stream.ReadToEnd();

            objectCollection = JsonUtility.FromJson <PlacedObjectCollection>(json);
        }


        PlacedObject placed = objectCollection.placedObjects[(y - chunkY) + ((x - chunkX) * 10)];

        placed.m[i] = m;



        objectCollection.placedObjects[(y - chunkY) + ((x - chunkX) * 10)] = placed;
        using (StreamWriter stream = new StreamWriter(streamPath + chunkX.ToString() + "_" + chunkY.ToString() + ".json"))
        {
            string json = JsonUtility.ToJson(objectCollection, false);
            stream.Write(json);
        }
    }
    private IEnumerator TimedPosition(Pose hit, PlacedObject placementObject)
    {
        placementObject.Selected = false;
        OcclusionUIManager.Instance.UpdateObjectCountText($"placedObject selected: {placementObject.Selected}");
        yield return(new WaitForSeconds(0.5f));

        placedObject.transform.position = new Vector3(Random.Range(-1, 1), hit.position.y, Random.Range(-1, 1));
    }
Exemplo n.º 9
0
    public void LoadData()
    {
        string filePath = Path.Combine(Application.dataPath, "Resources/JsonText.json");

        string jsonFromFile = File.ReadAllText(filePath);

        PlacedObject PlacedObj = JsonUtility.FromJson <PlacedObject>(jsonFromFile);

        Instantiate(PlacedObj.ObjSaved, PlacedObj.ObjPos, Quaternion.identity);
    }
Exemplo n.º 10
0
        public PlacedObject Duplicate(
            IPlacedObjectGetter item,
            FormKey formKey,
            TranslationCrystal?copyMask)
        {
            var newRec = new PlacedObject(formKey);

            newRec.DeepCopyIn(item, default(ErrorMaskBuilder?), copyMask);
            return(newRec);
        }
Exemplo n.º 11
0
        public void ParentRefs()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);
            var baseContext = contexts[0];
            var cellContext = baseContext.Parent;

            cellContext.Should().BeOfType(typeof(ModContext <ISkyrimMod, ISkyrimModGetter, ICell, ICellGetter>));
            cellContext !.Record.Should().Be(cell);
            var subBlockContext = cellContext.Parent;

            subBlockContext !.Record.Should().Be(subBlock);
            var blockContext = subBlockContext.Parent;

            blockContext !.Record.Should().Be(block);
            var worldspaceContext = blockContext.Parent;

            worldspaceContext !.Record.Should().Be(worldspace);
            baseContext.IsUnderneath <IWorldspaceGetter>().Should().BeTrue();
            baseContext.TryGetParent <IWorldspaceGetter>(out var worldParent).Should().BeTrue();
            worldParent.Should().Be(worldspace);
            baseContext.TryGetParentContext <IWorldspace, IWorldspaceGetter>(out var worldParentContext).Should().BeTrue();
            worldParentContext !.Record.Should().Be(worldspace);
        }
Exemplo n.º 12
0
    public void UpdateUI(PlacedObject placedObject)
    {
        ClearActionElements();

        selectedObjectText.text = placedObject.GetObjectName();
        foreach (PlaceableAction action in placedObject.ActionList)
        {
            SelectedObjectActionUIElement newAction = Instantiate(actionPrefab, layoutGroup.transform);
            newAction.SetProperties(action.ActionName, action.ActionActivate);
            selectedObjectActions.Add(newAction);
        }
    }
Exemplo n.º 13
0
    GameObject generateObjectSlotPrefab(PlacedObject placementObject)
    {
        GameObject go = Instantiate(objectSlotPrefab, Vector3.zero, Quaternion.identity);

        if (placementObject.prefab != null)
        {
            go.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <Image>().sprite = placementObject.icon;
            go.transform.GetChild(0).GetChild(1).GetComponent <Text>().text = placementObject.text;
            go.GetComponent <Button>().onClick.AddListener(() => PlacementManager.Instance.ChangePrefabTo(placementObject.text));
        }
        return(go);
    }
Exemplo n.º 14
0
        public PlacedObject DeepCopy(
            IPlacedObjectGetter item,
            PlacedObject.TranslationMask?copyMask = null)
        {
            PlacedObject ret = (PlacedObject)((PlacedObjectCommon)((IPlacedObjectGetter)item).CommonInstance() !).GetNew();

            ((PlacedObjectSetterTranslationCommon)((IPlacedObjectGetter)ret).CommonSetterTranslationInstance() !).DeepCopyIn(
                item: ret,
                rhs: item,
                errorMask: null,
                copyMask: copyMask?.GetCrystal(),
                deepCopy: true);
            return(ret);
        }
Exemplo n.º 15
0
    private void SimpleRetrieveObject(DynamoDBContext context)
    {
        PlacedObject placedObject = new PlacedObject();

        context.LoadAsync <PlacedObject>(2,
                                         (AmazonDynamoDBResult <PlacedObject> result) =>
        {
            if (result.Exception != null)
            {
                Debug.LogException(result.Exception);
                return;
            }
            placedObject = result.Result;
        }, null);
    }
Exemplo n.º 16
0
 private void HandleRightClick(object sender, PlayerInput.OnRightClickArgs args)
 {
     if (!GridBuildingSystem.Instance.IsActive())
     {
         if (SelectedObject != null)
         {
             m_selectedObjectArea.Clear();
             SelectedObject = null;
         }
         else
         {
             Debug.Log("Didnt hit placedObject");
         }
     }
 }
Exemplo n.º 17
0
    public static PlacedObject Create(Vector3 worldPosition, Vector2Int origin, PlaceableScriptableObject.Dir dir, PlaceableScriptableObject placeableType, int cellScale)
    {
        Transform placedObjectTransform = Instantiate(placeableType.prefab, worldPosition, Quaternion.Euler(0, placeableType.GetRotationAngle(dir), 0));

        PlacedObject placedObject = placedObjectTransform.GetComponent <PlacedObject>();

        placedObject.placeableType = placeableType;
        placedObject.origin        = origin;
        placedObject.dir           = dir;
        placedObject.originalScale = placeableType.prefab.localScale;
        placedObject.cellScale     = cellScale;
        placedObject.BindActions();

        return(placedObject);
    }
Exemplo n.º 18
0
    private void RetrieveDBObjectLocation(DynamoDBContext context)
    {
        m_SuccessText.text = "";
        bool foundObject = false;

        for (int j = 1; j <= m_TableLength; j++)
        {
            if (foundObject)
            {
                break;
            }
            PlacedObject placedObject = new PlacedObject();
            context.LoadAsync <PlacedObject>(j,
                                             (AmazonDynamoDBResult <PlacedObject> result) =>
            {
                if (result.Exception != null)
                {
                    Debug.LogException(result.Exception);
                    return;
                }
                placedObject     = result.Result;
                float latitude   = placedObject.Latitude;
                float longitude  = placedObject.Longitude;
                float compassDeg = placedObject.CompassAngle;
                //m_SuccessText.text = "Our Latitude: " + m_Latitude + "\nDB latitude: " + latitude;

                if (latitude >= m_Latitude - m_LocationRadius && latitude <= m_Latitude + m_LocationRadius)
                {
                    //m_SuccessText.text = "Almost there";
                    if (longitude >= m_Longitude - m_LocationRadius && longitude <= m_Longitude + m_LocationRadius)
                    {
                        m_SuccessText.text = "In Right Area! \nThis is your number: " + placedObject.UserName + "\nTable Length: " + m_TableLength.ToString();
                        foundObject        = true;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                Debug.Log(latitude);
            }, null);
        }
    }
Exemplo n.º 19
0
        public PlacedObject DeepCopy(
            IPlacedObjectGetter item,
            out PlacedObject.ErrorMask errorMask,
            PlacedObject.TranslationMask?copyMask = null)
        {
            var          errorMaskBuilder = new ErrorMaskBuilder();
            PlacedObject ret = (PlacedObject)((PlacedObjectCommon)((IPlacedObjectGetter)item).CommonInstance() !).GetNew();

            ((PlacedObjectSetterTranslationCommon)((IPlacedObjectGetter)ret).CommonSetterTranslationInstance() !).DeepCopyIn(
                ret,
                item,
                errorMask: errorMaskBuilder,
                copyMask: copyMask?.GetCrystal(),
                deepCopy: true);
            errorMask = PlacedObject.ErrorMask.Factory(errorMaskBuilder);
            return(ret);
        }
Exemplo n.º 20
0
 private void DeleteObjectFromDB(DynamoDBContext context)
 {
     context.DeleteAsync <PlacedObject>(1, (res) =>
     {
         if (res.Exception == null)
         {
             context.LoadAsync <PlacedObject>(1, (result) =>
             {
                 PlacedObject deletedBook = result.Result;
                 if (deletedBook == null)
                 {
                     Debug.Log("Object Deleted");
                 }
             });
         }
     });
 }
Exemplo n.º 21
0
            static void ParseTypical(
                MutagenFrame frame,
                ICellInternal obj,
                IList <IPlaced> coll,
                bool persistentParse)
            {
                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.");
                }
                if (persistentParse)
                {
                    obj.PersistentTimestamp = groupMeta.LastModifiedData.Int32();
                }
                else
                {
                    obj.VisibleWhenDistantTimestamp = groupMeta.LastModifiedData.Int32();
                }
                coll.AddRange(
                    ListBinaryTranslation <IPlaced> .Instance.Parse(
                        reader: frame,
                        transl: (MutagenFrame r, RecordType header, out IPlaced placed) =>
                {
                    switch (header.TypeInt)
                    {
                    case 0x45524341:             // "ACRE":
                        placed = PlacedCreature.CreateFromBinary(r);
                        return(true);

                    case 0x52484341:             //"ACHR":
                        placed = PlacedNpc.CreateFromBinary(r);
                        return(true);

                    case 0x52464552:             // "REFR":
                        placed = PlacedObject.CreateFromBinary(r);
                        return(true);

                    default:
                        throw new NotImplementedException();
                    }
                }));
            }
Exemplo n.º 22
0
        public void PlacedInWorldspaceQuerySucceedsIfMajorRecordType(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var placed    = new PlacedObject(prototype);

            prototype.Worldspaces.Add(new Worldspace(prototype)
            {
                SubCells = new ExtendedList <WorldspaceBlock>()
                {
                    new WorldspaceBlock()
                    {
                        Items = new ExtendedList <WorldspaceSubBlock>()
                        {
                            new WorldspaceSubBlock()
                            {
                                Items = new ExtendedList <Cell>()
                                {
                                    new Cell(prototype)
                                    {
                                        Temporary = new ExtendedList <IPlaced>()
                                        {
                                            placed
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                package.TryResolve <ISkyrimMajorRecordGetter>(placed.FormKey, out var rec2)
                .Should().BeTrue();
                rec2.Should().Be(placed);
            });
            WrapPotentialThrow(cacheType, style, () =>
            {
                contextRetriever.TryResolveContext <ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(placed.AsLink(), package, out var rec)
                .Should().BeTrue();
                rec.Record.Should().Be(placed);
            });
        }
Exemplo n.º 23
0
 private void HandleLeftClick(object sender, PlayerInput.OnLeftClickArgs args)
 {
     if (!GridBuildingSystem.Instance.IsActive())
     {
         RaycastHit   hit          = StaticFunctions.GetMouseRaycastHit();
         PlacedObject placedObject = GridBuildingSystem.Instance.GetPlacedObjectAtWorldPosition(hit.point);
         if (placedObject != null)
         {
             text = placedObject.GetObjectName();
             m_selectedObjectArea.UpdateUI(placedObject);
             SelectedObject = placedObject;
         }
         else
         {
             Debug.Log("Didnt hit placedObject");
         }
     }
 }
Exemplo n.º 24
0
        public void Execute(int index)
        {
            var foregroundObjectBox = PlacedForegroundObjects[index];
            // See comment regarding Random in jobs in BackgroundGenerator.PlaceObjectsJob
            var rand = new Random(RandomSeed + (uint)index * ObjectPlacementUtilities.LargePrimeNumber);

            var prefabIndex = rand.NextInt(OccludingObjectBounds.Length);
            var bounds      = OccludingObjectBounds[prefabIndex];
            var foregroundObjectBoundingBox = ObjectPlacementUtilities.IntersectRect(
                foregroundObjectBox.BoundingBox, ImageCoordinates);

            //place over a foreground object such that overlap is between 10%-30%
            var numTries = 0;

            PlacedOccludingObjects[index] = new PlacedObject()
            {
                PrefabIndex = -1
            };
            while (numTries < 1000)
            {
                numTries++;
                var rotation = rand.NextQuaternionRotation();
                var position = new Vector3(rand.NextFloat(foregroundObjectBoundingBox.xMin, foregroundObjectBoundingBox.xMax),
                                           rand.NextFloat(foregroundObjectBoundingBox.yMin, foregroundObjectBoundingBox.yMax), 0f);
                var scale = ObjectPlacementUtilities.ComputeScaleToMatchArea(Transformer, position, rotation, bounds,
                                                                             rand.NextFloat(ScalingMin, ScalingMin + ScalingSize) * foregroundObjectBox.ProjectedArea);
                var placedObject = new PlacedObject()
                {
                    Scale       = scale,
                    Rotation    = rotation,
                    Position    = position,
                    PrefabIndex = prefabIndex
                };
                // NOTE: This computation is done with orthographic projection and will be slightly inaccurate
                //       when rendering with perspective projection
                var occludingObjectBox = GetBoundingBox(bounds, scale, position, rotation);
                var cropping           = ComputeOverlap(foregroundObjectBoundingBox, occludingObjectBox);
                if (cropping >= 0.10 && cropping <= 0.30)
                {
                    PlacedOccludingObjects[index] = placedObject;
                    return;
                }
            }
        }
Exemplo n.º 25
0
        public void Execute()
        {
            bool placedSuccessfully;

            do
            {
                var curriculumState = *CurriculumStatePtr;
                var bounds          = ObjectBounds[curriculumState.PrefabIndex];
                var scale           =
                    ObjectPlacementUtilities.ComputeForegroundScaling(bounds, NativePlacementStatics.ScaleFactors[curriculumState.ScaleIndex]);
                var rotation = ObjectPlacementUtilities.ComposeForegroundRotation(curriculumState,
                                                                                  NativePlacementStatics.OutOfPlaneRotations, NativePlacementStatics.InPlaneRotations);
                var placedObject = new PlacedObject
                {
                    Scale       = scale,
                    Rotation    = rotation,
                    PrefabIndex = curriculumState.PrefabIndex,
                };
                placedSuccessfully = false;
                for (var i = 0; i < 100; i++)
                {
                    placedObject.Position = new Vector3(RandomPtr->NextFloat(ImageCoordinates.xMin, ImageCoordinates.xMax),
                                                        RandomPtr->NextFloat(ImageCoordinates.yMin, ImageCoordinates.yMax), 0f);
                    placedObject.ProjectedArea = ObjectPlacementUtilities.ComputeProjectedArea(
                        Transformer, placedObject.Position, rotation, bounds, scale);

                    placedObject.BoundingBox = GetBoundingBox(bounds, placedObject.Scale, placedObject.Position, placedObject.Rotation);
                    var cropping      = CalculateCropping(placedObject.BoundingBox, ImageCoordinates);
                    var passedOverlap = ValidateOverlap(placedObject.BoundingBox, PlaceObjects);
                    if ((cropping <= .5 && passedOverlap))
                    {
                        placedSuccessfully = true;
                        PlaceObjects.Add(placedObject);
                        *CurriculumStatePtr = NextCurriculumState(curriculumState, NativePlacementStatics);

                        break;
                    }
                }

                // If it can’t be placed within the scene due to violations of the cropping or overlap
                // constraints we stop processing the current foreground scene
                // and start with the next one.
            } while (placedSuccessfully && PlaceObjects.Length < NativePlacementStatics.MaxForegroundObjects && CurriculumStatePtr->ScaleIndex < NativePlacementStatics.ScaleFactors.Length);
        }
Exemplo n.º 26
0
        public void PlacedInWorldspaceOnlyOverridesPlaced(LinkCacheTestTypes cacheType)
        {
            var prototype = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var placed    = new PlacedObject(prototype);
            var outgoing  = new SkyrimMod(TestConstants.PluginModKey4, SkyrimRelease.SkyrimSE);

            prototype.Worldspaces.Add(new Worldspace(prototype)
            {
                SubCells = new ExtendedList <WorldspaceBlock>()
                {
                    new WorldspaceBlock()
                    {
                        Items = new ExtendedList <WorldspaceSubBlock>()
                        {
                            new WorldspaceSubBlock()
                            {
                                Items = new ExtendedList <Cell>()
                                {
                                    new Cell(prototype)
                                    {
                                        Landscape = new Landscape(prototype),
                                        Temporary = new ExtendedList <IPlaced>()
                                        {
                                            placed
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
            using var disp      = ConvertMod(prototype, out var mod);
            var(style, package) = GetLinkCache(mod, cacheType);
            WrapPotentialThrow(cacheType, style, () =>
            {
                package.TryResolveContext <ISkyrimMajorRecord, ISkyrimMajorRecordGetter>(placed.FormKey, out var rec)
                .Should().BeTrue();
                rec.Record.Should().Be(placed);
                rec.GetOrAddAsOverride(outgoing);
                outgoing.Worldspaces.First().SubCells.First().Items.First().Items.First().Landscape.Should().BeNull();
            });
        }
Exemplo n.º 27
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.º 28
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);
                var items = ListBinaryTranslation <IPlaced> .Instance.Parse(
                    reader : frame,
                    transl : (MutagenFrame r, RecordType header, out IPlaced placed) =>
                {
                    switch (header.TypeInt)
                    {
                    case 0x45524341:         // "ACRE":
                        placed = PlacedCreature.CreateFromBinary(r);
                        return(true);

                    case 0x52484341:         //"ACHR":
                        placed = PlacedNpc.CreateFromBinary(r);
                        return(true);

                    case 0x52464552:         // "REFR":
                        placed = PlacedObject.CreateFromBinary(r);
                        return(true);

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

                obj.Temporary.SetTo(new ExtendedList <IPlaced>(items));
            }
Exemplo n.º 29
0
    private void SimpleAddObjectToDB(DynamoDBContext context)
    {
        PlacedObject myObj = new PlacedObject
        {
            UserName     = 3,
            CompassAngle = m_TableLength,
            Latitude     = 43.091f,
            Longitude    = -115.234f,
            Altitude     = 0
        };

        // Save the book.
        context.SaveAsync(myObj, (result) =>
        {
            if (result.Exception == null)
            {
                Debug.Log("Object Saved");
            }
        });
    }
Exemplo n.º 30
0
    private void AddCurrentObjectToDB(DynamoDBContext context)
    {
        PlacedObject myObj = new PlacedObject
        {
            UserName     = m_TableLength,
            CompassAngle = m_CompassDegree,
            Latitude     = m_Latitude,
            Longitude    = m_Longitude,
            Altitude     = m_Altiude
        };

        // Save the book.
        context.SaveAsync(myObj, (result) =>
        {
            if (result.Exception == null)
            {
                Debug.Log("Object Saved");
            }
        });
    }