Ejemplo n.º 1
0
        public static EntitySpawnPoint From(Int3 batchId, GameObject go, CellManager.CellHeader cellHeader)
        {
            // Why is this not a constructor?
            EntitySpawnPoint esp = new EntitySpawnPoint
            {
                Level   = cellHeader.level,
                ClassId = go.ClassId,
                BatchId = batchId,
                CellId  = cellHeader.cellId
            };

            EntitySlot entitySlot = go.GetComponent <EntitySlot>();

            if (!ReferenceEquals(entitySlot, null))
            {
                esp.BiomeType        = entitySlot.biomeType;
                esp.Density          = entitySlot.density;
                esp.CanSpawnCreature = entitySlot.IsCreatureSlot();
            }

            Vector3 localPosition = go.GetComponent <Transform>().Position;

            Int3.Bounds         bounds = BatchCells.GetBlockBounds(batchId, cellHeader.cellId, 0, Map.BATCH_DIMENSIONS);
            UnityEngine.Vector3 center = EntityCell.GetCenter(bounds);

            esp.Position = new UnityEngine.Vector3(center.x + localPosition.x - Map.BATCH_DIMENSION_CENTERING.x,
                                                   center.y + localPosition.y - Map.BATCH_DIMENSION_CENTERING.y,
                                                   center.z + localPosition.z - Map.BATCH_DIMENSION_CENTERING.z);
            return(esp);
        }
Ejemplo n.º 2
0
        public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            var item = GetItemAt(indexPath);

            var entityCellContext = item as IEntityCellContext;

            if (entityCellContext != null)
            {
                var height = EntityCell.CalculateCellHeight(
                    UIApplication.SharedApplication.KeyWindow.Bounds.Size,
                    entityCellContext);
                return(height);
            }

            var venueShow = item as Show;

            if (venueShow != null)
            {
                var height = VenueShowCell.CalculateCellHeight(
                    tableView.Frame.Width,
                    Equals(_viewModel.ExpandedShow, venueShow),
                    venueShow);
                return(height);
            }

            if (item is string)
            {
                return(NextVenueCell.DefaultHeight);
            }

            throw new Exception("There is an unsupported type in the list.");
        }
Ejemplo n.º 3
0
        public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
        {
            var item = GetItemAt(indexPath);

            var entityCellContext = item as IEntityCellContext;

            if (entityCellContext != null)
            {
                var height = EntityCell.CalculateCellHeight(
                    UIApplication.SharedApplication.KeyWindow.Bounds.Size,
                    entityCellContext);
                return(height);
            }

            throw new Exception("There is an unsupported type in the list.");
        }
Ejemplo n.º 4
0
        private EntityCell EnsureCell(Entity entity, Optional <GameObject> liveRoot)
        {
            EntityCell entityCell;

            if (!entityCells.TryGetValue(entity.AbsoluteEntityCell, out entityCell) && liveRoot.IsPresent() && liveRoot.Get().GetComponent <LargeWorldEntityCell>())
            {
                Int3 batchId = ToInt3(entity.AbsoluteEntityCell.BatchId);
                Int3 cellId  = ToInt3(entity.AbsoluteEntityCell.CellId);
                entityCell = new EntityCell(LargeWorldStreamer.main.cellManager, LargeWorldStreamer.main, batchId, cellId, entity.Level);
                entityCells.Add(entity.AbsoluteEntityCell, entityCell);
                entityCell.liveRoot      = liveRoot.Get();
                entityCell.liveRoot.name = string.Format("CellRoot {0}, {1}, {2}; Batch {3}, {4}, {5}", cellId.x, cellId.y, cellId.z, batchId.x, batchId.y, batchId.z);
                entityCell.Initialize();
            }
            return(entityCell);
        }
Ejemplo n.º 5
0
        private void Spawn(Entity entity, Optional <GameObject> parent)
        {
            alreadySpawnedIds.Add(entity.Id);

            EntityCell cellRoot = EnsureCell(entity);

            IEntitySpawner        entitySpawner = ResolveEntitySpawner(entity);
            Optional <GameObject> gameObject    = entitySpawner.Spawn(entity, parent, cellRoot);

            foreach (Entity childEntity in entity.ChildEntities)
            {
                if (!alreadySpawnedIds.Contains(childEntity.Id) && !entitySpawner.SpawnsOwnChildren())
                {
                    Spawn(childEntity, gameObject);
                }

                alreadySpawnedIds.Add(childEntity.Id);
            }
        }
Ejemplo n.º 6
0
        private void Spawn(Entity entity, Optional <GameObject> parent)
        {
            alreadySpawnedIds.Add(entity.Id);

            EntityCell cellRoot = EnsureCell(entity);

            IEntitySpawner        entitySpawner = entitySpawnerResolver.ResolveEntitySpawner(entity);
            Optional <GameObject> gameObject    = entitySpawner.Spawn(entity, parent, cellRoot);

            if (!entitySpawner.SpawnsOwnChildren())
            {
                foreach (Entity childEntity in entity.ChildEntities)
                {
                    if (!WasSpawnedByServer(childEntity.Id))
                    {
                        Spawn(childEntity, gameObject);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void Spawn(Entity entity, Optional <GameObject> parent)
        {
            alreadySpawnedIds.Add(entity.Id);

            IEntitySpawner        entitySpawner = ResolveEntitySpawner(entity);
            Optional <GameObject> gameObject    = entitySpawner.Spawn(entity, parent);

            EntityCell cellRoot = EnsureCell(entity, gameObject);

            if (cellRoot != null && gameObject.Get().GetComponent <LargeWorldEntityCell>() != null)
            {
                LargeWorldStreamer.main.cellManager.QueueForAwake(cellRoot);
            }

            foreach (Entity childEntity in entity.ChildEntities)
            {
                if (!alreadySpawnedIds.Contains(childEntity.Id) && !entitySpawner.SpawnsOwnChildren())
                {
                    Spawn(childEntity, gameObject);
                }

                alreadySpawnedIds.Add(childEntity.Id);
            }
        }
Ejemplo n.º 8
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (!parent.HasValue)
            {
                return(Optional.Empty);
            }

            if (parent.Value.transform.childCount - 1 < entity.ExistingGameObjectChildIndex.Value)
            {
                Log.Error($"Parent {parent.Value} did not have a child at index {entity.ExistingGameObjectChildIndex.Value}");
                return(Optional.Empty);
            }

            GameObject gameObject = parent.Value.transform.GetChild(entity.ExistingGameObjectChildIndex.Value).gameObject;

            NitroxEntity.SetNewId(gameObject, entity.Id);

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
 public static bool IsProcessing(this EntityCell entityCell)
 {
     return((bool)IsProcessingMethod.Invoke(entityCell, new object[] { }));
 }
Ejemplo n.º 10
0
 public static bool Prefix(EntityCell __instance)
 {
     Multiplayer.Logic.Chunks.ChunkUnloaded(__instance.BatchId, __instance.Level);
     return(true);
 }
Ejemplo n.º 11
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            GameObject gameObject = SerializationHelper.GetGameObject(entity.SerializedGameObject);

            gameObject.transform.position   = entity.Transform.Position;
            gameObject.transform.rotation   = entity.Transform.Rotation;
            gameObject.transform.localScale = entity.Transform.LocalScale;

            if (entity.WaterParkId != null)
            {
                AssignToWaterPark(gameObject, entity.WaterParkId);
            }

            EnableRigidBody(gameObject);
            ExecuteDropItemAction(entity.TechType.Enum(), gameObject);

            NitroxEntity.SetNewId(gameObject, entity.Id);

            return(Optional <GameObject> .Of(gameObject));
        }
Ejemplo n.º 12
0
        public static bool Prefix(EntityCell __instance)
        {
            NitroxServiceLocator.LocateService <Terrain>().CellLoaded(__instance.BatchId, __instance.CellId, __instance.Level);

            return(true);
        }
Ejemplo n.º 13
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            Optional <GameObject> reefback = defaultSpawner.Spawn(entity, parent, cellRoot);

            if (!reefback.HasValue)
            {
                return(Optional.Empty);
            }
            ReefbackLife life = reefback.Value.GetComponent <ReefbackLife>();

            if (life == null)
            {
                return(Optional.Empty);
            }

            life.initialized = true;
            life.SpawnPlants();
            foreach (Entity childEntity in entity.ChildEntities)
            {
                Optional <GameObject> child = defaultSpawner.Spawn(childEntity, reefback, cellRoot);
                if (child.HasValue)
                {
                    child.Value.AddComponent <ReefbackCreature>();
                }
            }

            return(Optional.Empty);
        }
Ejemplo n.º 14
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional.Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Transform.Position;
            gameObject.transform.rotation   = entity.Transform.Rotation;
            gameObject.transform.localScale = entity.Transform.LocalScale;

            NitroxEntity.SetNewId(gameObject, entity.Id);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            if (parent.HasValue)
            {
                gameObject.transform.SetParent(parent.Value.transform, true);
            }

            if (parent.HasValue && parent.Value.GetComponent <LargeWorldEntityCell>() != null)
            {
                LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
            }
            else
            {
                gameObject.SetActive(true);
            }

            return(Optional.Of(gameObject));
        }
Ejemplo n.º 15
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            NitroxInt3 cellId  = entity.AbsoluteEntityCell.CellId;
            NitroxInt3 batchId = entity.AbsoluteEntityCell.BatchId;

            cellRoot.liveRoot.name = $"CellRoot {cellId.X}, {cellId.Y}, {cellId.Z}; Batch {batchId.X}, {batchId.Y}, {batchId.Z}";

            NitroxEntity.SetNewId(cellRoot.liveRoot, entity.Id);

            LargeWorldStreamer.main.cellManager.QueueForAwake(cellRoot);

            return(Optional.OfNullable(cellRoot.liveRoot));
        }
        public static bool Prefix(EntityCell __instance)
        {
            Multiplayer.Logic.Terrain.CellLoaded(__instance.BatchId, __instance.CellId, __instance.Level);

            return(true);
        }
Ejemplo n.º 17
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            Optional <GameObject> reefback = defaultSpawner.Spawn(entity, parent, cellRoot);

            if (reefback.IsPresent())
            {
                ReefbackLife life = reefback.Get().GetComponent <ReefbackLife>();
                if (life != null) // Child Reefy...
                {
                    life.initialized = true;
                    life.ReflectionCall("SpawnPlants");

                    foreach (Entity childEntity in entity.ChildEntities)
                    {
                        Optional <GameObject> child = defaultSpawner.Spawn(childEntity, reefback, cellRoot);

                        if (child.IsPresent())
                        {
                            child.Get().AddComponent <ReefbackCreature>();
                        }
                    }
                }
            }

            return(Optional <GameObject> .Empty());
        }
Ejemplo n.º 18
0
        /**
         * Crash fish are spawned by the CrashHome in the Monobehaviours Start method
         */
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (parent.HasValue)
            {
                CrashHome crashHome = parent.Value.GetComponent <CrashHome>();

                GameObject gameObject = Object.Instantiate(crashHome.crashPrefab, Vector3.zero, Quaternion.Euler(-90f, 0f, 0f));
                gameObject.transform.SetParent(crashHome.transform, false);
                NitroxEntity.SetNewId(gameObject, entity.Id);
                crashHome.crash = gameObject.GetComponent <Crash>();
            }

            return(Optional.Empty);
        }
Ejemplo n.º 19
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            GameObject gameObject = SerializationHelper.GetGameObject(entity.SerializedGameObject);

            gameObject.transform.position   = entity.Transform.Position.ToUnity();
            gameObject.transform.rotation   = entity.Transform.Rotation.ToUnity();
            gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity();

            if (entity.WaterParkId != null)
            {
                AssignToWaterPark(gameObject, entity.WaterParkId);
            }

            EnableRigidBody(gameObject);
            ExecuteDropItemAction(entity.TechType.ToUnity(), gameObject);

            NitroxEntity.SetNewId(gameObject, entity.Id);

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Ejemplo n.º 20
0
        /**
         * Crash fish are spawned by the CrashHome in the Monobehaviours Start method
         */
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            if (parent.IsPresent())
            {
                CrashHome crashHome = parent.Get().GetComponent <CrashHome>();

                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(crashHome.crashPrefab, Vector3.zero, Quaternion.Euler(-90f, 0f, 0f));
                gameObject.transform.SetParent(crashHome.transform, false);
                NitroxEntity.SetNewId(gameObject, entity.Id);
                ReflectionHelper.ReflectionSet <CrashHome>(crashHome, "crash", gameObject.GetComponent <Crash>());
            }

            return(Optional <GameObject> .Empty());
        }
Ejemplo n.º 21
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            TechType techType = entity.TechType.ToUnity();

            GameObject gameObject = CreateGameObject(techType, entity.ClassId);

            gameObject.transform.position   = entity.Transform.Position.ToUnity();
            gameObject.transform.rotation   = entity.Transform.Rotation.ToUnity();
            gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity();

            NitroxEntity.SetNewId(gameObject, entity.Id);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>())
            {
                LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
            }
            else if (gameObject.GetComponent <LargeWorldEntity>() != null && gameObject.transform.parent == null)
            {
                gameObject.transform.SetParent(cellRoot.liveRoot.transform, true);
                LargeWorldEntity.Register(gameObject);
            }
            else
            {
                gameObject.SetActive(true);
            }

            if (parent.HasValue)
            {
                gameObject.transform.SetParent(parent.Value.transform, true);
            }

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
Ejemplo n.º 22
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            NitroxInt3 cellId  = entity.AbsoluteEntityCell.CellId;
            NitroxInt3 batchId = entity.AbsoluteEntityCell.BatchId;

            cellRoot.liveRoot.name = string.Format("CellRoot {0}, {1}, {2}; Batch {3}, {4}, {5}", cellId.X, cellId.Y, cellId.Z, batchId.X, batchId.Y, batchId.Z);

            NitroxEntity.SetNewId(cellRoot.liveRoot, entity.Id);

            LargeWorldStreamer.main.cellManager.QueueForAwake(cellRoot);

            return(cellRoot.liveRoot);
        }