private void TrySpawnMob()
    {
        var pos = gameObject.WorldPosServer();

        spawnedMobs.Remove(null);

        var mobs = spawnedMobs;

        foreach (var mob in mobs)
        {
            if (mob.TryGetComponent <LivingHealthBehaviour>(out var health) && health.IsDead)
            {
                spawnedMobs.Remove(mob);
            }
        }

        if (spawnedMobs.Count >= maxMobs)
        {
            return;
        }

        foreach (var vector in adjacentVectors)
        {
            if (MatrixManager.IsPassableAtAllMatricesOneTile((pos + vector).RoundToInt(), true))
            {
                var result = Spawn.ServerPrefab(mobsToSpawn.GetRandom(), pos + vector, transform.parent.transform);
                spawnedMobs.Add(result.GameObject);
                return;
            }
        }
    }
Example #2
0
        protected void GiveGunToPlayer(ConnectedPlayer player)
        {
            GameObject gun = Spawn.ServerPrefab(gunList.GetRandom(),
                                                player.Script.WorldPos, player.Script.transform.parent, player.Script.transform.rotation).GameObject;

            ItemSlot slot = player.Script.DynamicItemStorage.GetBestHandOrSlotFor(gun);

            if (slot != null && slot.IsEmpty)
            {
                Inventory.ServerAdd(gun, slot);
            }
        }
Example #3
0
    public override void AfterFeedEffect(HandApply touchSource)
    {
        var amount = randomSpawnAmounts
                        ? Random.Range(minHowManyDifferentItems, howManyDifferentItems + 1)
                        : howManyDifferentItems;

        var amountItem = randomSpawnAmounts
                        ? Random.Range(minHowManyOfThoseItems, howManyOfThoseItems + 1)
                        : howManyOfThoseItems;

        for (int i = 0; i < amount; i++)
        {
            Spawn.ServerPrefab(itemsToSpawn.GetRandom(), gameObject.WorldPosServer(), transform.parent.transform
                               , count: amountItem, scatterRadius: scatterRadius);
        }

        if (string.IsNullOrEmpty(spawnMessage))
        {
            return;
        }

        Chat.AddLocalMsgToChat(spawnMessage, gameObject);
    }