Esempio n. 1
0
        public TechBunker(ActorInitializer init, TechBunkerInfo info)
        {
            this.info = info;
            wsb       = init.Self.Trait <WithSpriteBody>();
            timer     = 0;
            state     = TechBunkerState.ClosedLocked;

            var rs = init.Self.Trait <RenderSprites>();

            if (info.SequenceLocked != null)
            {
                var overlay = new Animation(init.World, rs.GetImage(init.Self), () => state != TechBunkerState.ClosedLocked);
                overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, init.Self.GetDamageState(), info.SequenceLocked));

                var anim = new AnimationWithOffset(overlay,
                                                   () => WVec.Zero,
                                                   () => state != TechBunkerState.ClosedLocked,
                                                   p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1));

                rs.Add(anim);
            }

            if (info.SequenceUnlocked != null)
            {
                var overlay = new Animation(init.World, rs.GetImage(init.Self), () => state != TechBunkerState.ClosedUnlocked);
                overlay.PlayRepeating(RenderSprites.NormalizeSequence(overlay, init.Self.GetDamageState(), info.SequenceUnlocked));

                var anim = new AnimationWithOffset(overlay,
                                                   () => WVec.Zero,
                                                   () => state != TechBunkerState.ClosedUnlocked,
                                                   p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1));

                rs.Add(anim);
            }
        }
Esempio n. 2
0
        void ITick.Tick(Actor self)
        {
            switch (state)
            {
            case TechBunkerState.ClosedLocked:
                if (timer++ >= info.UnlockAfter && self.World.SharedRandom.Next(0, info.UnlockChance) == 0)
                {
                    state = TechBunkerState.ClosedUnlocked;
                    timer = 0;
                }

                break;

            case TechBunkerState.ClosedUnlocked:
                var nearbyActors = self.World.FindActorsInCircle(self.CenterPosition, info.TriggerRadius).Where(actor => !actor.Owner.NonCombatant).ToArray();
                if (!nearbyActors.Any())
                {
                    return;
                }

                var owner = nearbyActors[self.World.SharedRandom.Next(0, nearbyActors.Length - 1)].Owner;

                state = TechBunkerState.Opening;

                wsb.PlayCustomAnimation(self, info.SequenceOpening, () =>
                {
                    state = TechBunkerState.Opened;
                    wsb.PlayCustomAnimationRepeating(self, info.SequenceOpened);

                    EjectContents(self, owner);
                });

                if (info.SoundOpen != null)
                {
                    Game.Sound.Play(SoundType.World, info.SoundOpen.Random(self.World.SharedRandom), self.CenterPosition);
                }
                break;

            case TechBunkerState.Opened:
                if (self.World.WorldActor.Trait <BunkerSettings>().Reusable&& info.LockAfter != -1 && timer++ >= info.LockAfter)
                {
                    state = TechBunkerState.Closing;
                    timer = 0;

                    wsb.PlayCustomAnimationBackwards(self, info.SequenceOpening, () =>
                    {
                        state = TechBunkerState.ClosedLocked;
                        wsb.CancelCustomAnimation(self);
                    });

                    if (info.SoundClose != null)
                    {
                        Game.Sound.Play(SoundType.World, info.SoundClose.Random(self.World.SharedRandom), self.CenterPosition);
                    }
                }

                break;
            }
        }
Esempio n. 3
0
        void ITick.Tick(Actor self)
        {
            switch (State)
            {
            case TechBunkerState.ClosedLocked:
                if (timer++ >= info.UnlockAfter && self.World.SharedRandom.Next(0, info.UnlockChance) == 0)
                {
                    State = TechBunkerState.ClosedUnlocked;
                    timer = 0;
                }

                break;

            case TechBunkerState.ClosedUnlocked:
                if (usage.Usage != TechBunkerUsageType.Proximity)
                {
                    break;
                }

                var nearbyActors = self.World.FindActorsInCircle(self.CenterPosition, info.TriggerRadius).Where(actor => !actor.Owner.NonCombatant)
                                   .ToArray();

                if (!nearbyActors.Any())
                {
                    return;
                }

                Use(self, nearbyActors[self.World.SharedRandom.Next(0, nearbyActors.Length - 1)].Owner);

                break;

            case TechBunkerState.Opened:
                if (uses.Uses == TechBunkerUsesType.Infinitely && info.LockAfter != -1 &&
                    timer++ >= info.LockAfter)
                {
                    State = TechBunkerState.Closing;
                    timer = 0;

                    withSpriteBody.PlayCustomAnimationBackwards(self, info.SequenceOpening, () =>
                    {
                        State = TechBunkerState.ClosedLocked;
                        withSpriteBody.CancelCustomAnimation(self);
                    });

                    if (info.SoundClose != null)
                    {
                        Game.Sound.Play(SoundType.World, info.SoundClose.Random(self.World.SharedRandom), self.CenterPosition);
                    }
                }

                break;
            }
        }
Esempio n. 4
0
        public void Use(Actor self, Player owner)
        {
            State = TechBunkerState.Opening;

            withSpriteBody.PlayCustomAnimation(self, info.SequenceOpening, () =>
            {
                State = TechBunkerState.Opened;
                withSpriteBody.PlayCustomAnimationRepeating(self, info.SequenceOpened);

                switch (contains.Contains)
                {
                case TechBunkerContainsType.Resources:
                    EjectResources(owner);
                    break;

                case TechBunkerContainsType.Both:
                    if (self.World.SharedRandom.Next(0, info.ContainableActors.Length + 1) == 0)
                    {
                        EjectResources(owner);
                    }
                    else
                    {
                        EjectUnit(self, owner);
                    }

                    break;

                case TechBunkerContainsType.Units:
                    EjectUnit(self, owner);
                    break;
                }
            });

            if (info.SoundOpen != null)
            {
                Game.Sound.Play(SoundType.World, info.SoundOpen.Random(self.World.SharedRandom), self.CenterPosition);
            }
        }