Ejemplo n.º 1
0
        public static void NmFireGun(this Gun gun, Action <List <Bullet> > value, bool alsoAddThemToWorld = true)
        {
            var firedBullets = GlobalPool <List <Bullet> > .Rent();

            firedBullets.Clear(); // ensure clean
            value(firedBullets);

            if (firedBullets.Count == 0)
            {
                goto collect;
            }

            if (alsoAddThemToWorld)
            {
                var currentLevel = Level.current;
                foreach (var item in firedBullets)
                {
                    currentLevel.AddThing(item);
                }
            }

            if (gun != null)
            {
                gun.bulletFireIndex++;
            }
            if (Network.isActive)
            {
                NMFireGun gunEvent = new(gun, firedBullets, gun?.bulletFireIndex ?? 0, rel : false, 4);
                Send.Message(gunEvent, NetMessagePriority.ReliableOrdered);
            }
collect:
            firedBullets.Clear();
            GlobalPool <List <Bullet> > .Return(firedBullets);
        }