public override void Start(Level level) { #if SERVER originalInventoryID = Entity.NullEntityID; #endif item = null; if (!IsClient) { //ruin/wreck items are allowed to spawn close to the sub float minDistance = spawnPositionType == Level.PositionType.Ruin || spawnPositionType == Level.PositionType.Wreck ? 0.0f : Level.Loaded.Size.X * 0.3f; Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f); if (!string.IsNullOrEmpty(existingItemTag)) { var suitableItems = Item.ItemList.Where(it => it.HasTag(existingItemTag)); switch (spawnPositionType) { case Level.PositionType.Cave: case Level.PositionType.MainPath: item = suitableItems.FirstOrDefault(it => Vector2.DistanceSquared(it.WorldPosition, position) < 1000.0f); break; case Level.PositionType.Ruin: item = suitableItems.FirstOrDefault(it => it.ParentRuin != null && it.ParentRuin.Area.Contains(position)); break; case Level.PositionType.Wreck: foreach (Item it in suitableItems) { if (it.Submarine == null || it.Submarine.Info.Type != SubmarineType.Wreck) { continue; } Rectangle worldBorders = it.Submarine.Borders; worldBorders.Location += it.Submarine.WorldPosition.ToPoint(); if (Submarine.RectContains(worldBorders, it.WorldPosition)) { item = it; #if SERVER usedExistingItem = true; #endif break; } } break; } } if (item == null) { item = new Item(itemPrefab, position, null); item.body.FarseerBody.BodyType = BodyType.Kinematic; item.FindHull(); } for (int i = 0; i < statusEffects.Count; i++) { List <StatusEffect> effectList = statusEffects[i]; if (effectList.Count == 0) { continue; } int effectIndex = Rand.Int(effectList.Count); var selectedEffect = effectList[effectIndex]; item.ApplyStatusEffect(selectedEffect, selectedEffect.type, deltaTime: 1.0f, worldPosition: item.Position); #if SERVER executedEffectIndices.Add(new Pair <int, int>(i, effectIndex)); #endif } //try to find a container and place the item inside it if (!string.IsNullOrEmpty(containerTag) && item.ParentInventory == null) { foreach (Item it in Item.ItemList) { if (!it.HasTag(containerTag)) { continue; } if (it.NonInteractable) { continue; } switch (spawnPositionType) { case Level.PositionType.Cave: case Level.PositionType.MainPath: if (it.Submarine != null || it.ParentRuin != null) { continue; } break; case Level.PositionType.Ruin: if (it.ParentRuin == null) { continue; } break; case Level.PositionType.Wreck: if (it.Submarine == null || it.Submarine.Info.Type != SubmarineType.Wreck) { continue; } break; } var itemContainer = it.GetComponent <Items.Components.ItemContainer>(); if (itemContainer == null) { continue; } if (itemContainer.Combine(item, user: null)) { #if SERVER originalInventoryID = it.ID; originalItemContainerIndex = (byte)it.GetComponentIndex(itemContainer); #endif break; } // Placement successful } } } }