Beispiel #1
0
        private void SpawnTarget(Player player)
        {
            // Create new target
            this._spawnedTarget = GameObject.Instantiate(new LevelObjectTemplate
            {
                Lot      = Targets[Math.Min(this._targetsDestroyed / 2, Targets.Length - 1)],
                Position = this.GameObject.Transform.Position,
                Rotation = this._targetRotation,
                Scale    = 1,
                LegoInfo = new LegoDataDictionary(),
            }, this.Zone);

            Object.Start(this._spawnedTarget);
            GameObject.Construct(this._spawnedTarget);

            var stats = this._spawnedTarget.GetComponent <DestroyableComponent>();

            // Whenever the target takes damage, increase score by the amount of damage dealt.
            // It also increases the score when other players damage the target.
            // This is intentional; according to the LU wiki, this is how it worked in Live as well.
            Listen(stats.OnHealthChanged, (u, i) =>
            {
                if (i >= 0) // Health gets reset to max when object dies
                {
                    return;
                }
                this.UpdateActivityValue(player, 0, -i);
                this.SetNetworkVar("totalDmg", this.GetActivityValue(player, 0));
            });

            // If the timer hasn't ended yet, spawn a new target when this one dies.
            var destructibleComponent = this._spawnedTarget.GetComponent <DestructibleComponent>();

            Listen(destructibleComponent.OnSmashed, (smasher, lootOwner) =>
            {
                Destroy(this._spawnedTarget);
                this._targetsDestroyed++;
                if (this._active)
                {
                    this.SpawnTarget(player);
                }
            });
        }