Exemple #1
0
        void ITick.Tick(Actor self)
        {
            if (fireBitTimer > 0)
            {
                if (--fireBitTimer == 0)
                {
                    var tiles = GetBitTargetTiles(self);

                    for (var i = 0; i < info.NumberOfBits; i++)
                    {
                        var tile = tiles[self.World.SharedRandom.Next(0, tiles.Count)];
                        tiles.Remove(tile);
                        LaunchBits(self, tile);
                        Explodes(self);
                    }
                }
            }

            if (!self.IsDead)
            {
                return;
            }

            if (bitPickers.Values.Sum() < info.NumberOfBits)
            {
                return;
            }

            var bits     = bitPickers.Aggregate((a, b) => a.Value > b.Value ? a : b).Value;
            var newOwner = bitPickers.First(entry => entry.Value == bits).Key;

            if (bitPickers.Values.Count(value => value == bits) > 1)
            {
                newOwner = self.World.Players.First(player => player.InternalName == "Creeps");
            }

            self.ChangeOwner(newOwner);
            Game.Sound.Play(SoundType.World, info.CaptureSound, self.CenterPosition);
            bitPickers.Clear();

            // Get the timing right as owner change is also done at the end of the frame.
            self.World.AddFrameEndTask(_ =>
            {
                self.CancelActivity();                 // Stop shooting!

                health.Resurrect(self, self);
                health.InflictDamage(self, self, new Damage(health.MaxHP - info.ResurrectHealth), true);

                if (rallyPoint != null)
                {
                    rallyPoint.AddIndicator(self);                     // HACK: Workaround due to killing the colony
                }
            });
        }