protected override bool CanAttack(Actor self, Target target)
        {
            if (state == PopupState.Transitioning || !building.BuildComplete)
            {
                return(false);
            }

            if (!base.CanAttack(self, target))
            {
                return(false);
            }

            idleTicks = 0;
            if (state == PopupState.Closed)
            {
                state = PopupState.Transitioning;
                wsb.PlayCustomAnimation(self, info.OpeningSequence, () =>
                {
                    state = PopupState.Open;
                    wsb.PlayCustomAnimationRepeating(self, wsb.Info.Sequence);
                });
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        void INotifyCreated.Created(Actor self)
        {
            if (spawnType == SpawnType.PlaceBuilding)
            {
                var productionQueue = self.Owner.PlayerActor.TraitsImplementing <SelfConstructingProductionQueue>().First(q => q.AllItems().Contains(self.Info));
                var valued          = self.Info.TraitInfoOrDefault <ValuedInfo>();
                productionItem = new SelfConstructingProductionItem(productionQueue, self, valued == null ? 0 : valued.Cost, null, null);
                productionQueue.BeginProduction(productionItem, false);

                health = self.Trait <Health>();

                healthSteps = new List <int>();
                for (var i = 0; i <= Steps; i++)
                {
                    healthSteps.Add(health.MaxHP * (i + 1) / (Steps + 1));
                }

                self.World.AddFrameEndTask(world => health.InflictDamage(self, self, new Damage(health.MaxHP - healthSteps[0]), true));

                wsb.CancelCustomAnimation(self);
                wsb.PlayCustomAnimationRepeating(self, Info.Sequence.Substring(0, Info.Sequence.Length - 1) + 0);
            }
            else if (spawnType == SpawnType.Deploy)
            {
                wsb.CancelCustomAnimation(self);
                wsb.PlayCustomAnimation(self, "deploy", () => OnComplete(self));
            }
            else
            {
                OnComplete(self);
            }
        }
Esempio n. 3
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled)
            {
                wsb.PlayCustomAnimationRepeating(self, wsb.Info.Sequence);
                playanim = true;

                if (externalCondition != null)
                {
                    Game.Debug("revoke: " + token);
                    externalCondition.TryRevokeCondition(self, dockactor, token);
                }
                return(NextActivity);
            }

            if (ChildActivity != null)
            {
                ActivityUtils.RunActivity(self, ChildActivity);
                return(this);
            }

            if (playanim)
            {
                playanim = false;
                QueueChild(self.Trait <IMove>().VisualMove(self, self.CenterPosition, _d.CenterPosition));
                QueueChild(new CallFunc(() =>
                {
                    var facing = self.Trait <IFacing>();
                    if (dockactor != null && facing != null && lockfacing)
                    {
                        var desiredFacing =
                            (dockactor.CenterPosition - self.CenterPosition).HorizontalLengthSquared != 0
                                ? (dockactor.CenterPosition - self.CenterPosition).Yaw.Facing
                                : facing.Facing;
                        facing.Facing = desiredFacing;
                    }
                    wsb.PlayCustomAnimationRepeating(self, info.PreySequence);

                    Game.Debug("Manager: " + externalCondition);
                    if (externalCondition != null)
                    {
                        token = externalCondition.GrantCondition(dockactor, self);
                    }
                }));
            }

            if (self.Info.TraitInfo <AcolytePreyInfo>().LeechesResources&& --ticks <= 0)
            {
                Leech(self);
                ticks = self.Info.TraitInfo <AcolytePreyInfo>().leechinterval;
            }


            return(this);
        }
Esempio n. 4
0
        protected override void Created(Actor self)
        {
            base.Created(self);

            // Map placed actors are created in the closed state
            if (skippedMakeAnimation)
            {
                state = PopupState.Closed;
                wsb.PlayCustomAnimationRepeating(self, info.ClosedIdleSequence);
                turret.DesiredFacing = null;
            }
        }
        void INotifyCreated.Created(Actor self)
        {
            var valued = self.Info.TraitInfoOrDefault <ValuedInfo>();
            var cost   = valued != null ? valued.Cost : 0;
            var pm     = self.Owner.PlayerActor.TraitOrDefault <PowerManager>();

            var productionQueue = self.TraitsImplementing <BuilderQueue>().First(q => q.AllItems().Contains(self.Info));

            productionItem = new ProductionItem(productionQueue, self.Info.Name, cost, pm, null);
            productionQueue.BeginProduction(productionItem);

            if (productionItem == null)
            {
                return;
            }

            health = self.Trait <Health>();

            healthSteps = new List <int>();
            for (var i = 0; i <= Info.Steps; i++)
            {
                healthSteps.Add(health.MaxHP * (i + 1) / (Info.Steps + 1));
            }

            health.InflictDamage(self, self, new Damage(health.MaxHP - healthSteps[0]), true);

            wsb.CancelCustomAnimation(self);
            wsb.PlayCustomAnimationRepeating(self, "building");
        }
Esempio n. 6
0
 public void IncomingDelivery(Actor self)
 {
     if (!IsTraitDisabled)
     {
         wsb.PlayCustomAnimationRepeating(self, Info.Sequence);
     }
 }
Esempio n. 7
0
        void ITick.Tick(Actor self)
        {
            if (self.IsDead)
            {
                return;
            }

            if (token != ConditionManager.InvalidConditionToken)
            {
                sellTimer = developerMode.FastBuild ? 0 : sellTimer - 1;

                if (sellTimer <= 0)
                {
                    foreach (var notifySold in self.TraitsImplementing <INotifySold>())
                    {
                        notifySold.Sold(self);
                    }

                    var pr     = self.Owner.PlayerActor.Trait <PlayerResources>();
                    var valued = self.Info.TraitInfoOrDefault <ValuedInfo>();

                    if (valued != null)
                    {
                        pr.GiveCash(refundAmount * info.RefundPercent / 100);
                    }

                    self.Dispose();
                }
                else
                {
                    wsb.PlayCustomAnimationRepeating(self, selfConstructing.Sequence + Math.Min(sellTimer * selfConstructing.Steps / sellTimerTotal, selfConstructing.Steps - 1));
                }
            }
        }
Esempio n. 8
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;
            }
        }
        public override void OnStateDock(Actor self)
        {
            foreach (var trait in self.TraitsImplementing <INotifyHarvesterAction>())
            {
                trait.Docked();
            }

            wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence));
            dockingState = DockingState.Loop;
        }
 public void Charged(Actor self, string key)
 {
     conditionToken = conditionManager.GrantCondition(self, info.Condition);
     this.key       = key;
     if (key == info.OrderName)
     {
         wsb.PlayCustomAnimation(self, info.ChargedSequence, () =>
         {
             wsb.PlayCustomAnimationRepeating(self, info.ActiveSequence);
         });
     }
 }
Esempio n. 11
0
        public void ChangeState(BunkerState bunkered)
        {
            if (buildComplete)
            {
                switch (bunkered)
                {
                case BunkerState.NonBunkered:
                    if (!string.IsNullOrEmpty(Info.BunkerNotSequence))
                    {
                        wsb.PlayCustomAnimationRepeating(self, Info.BunkerNotSequence);
                    }
                    break;

                case BunkerState.Bunkered:
                    if (!string.IsNullOrEmpty(Info.BunkeredSequence))
                    {
                        wsb.PlayCustomAnimationRepeating(self, Info.BunkeredSequence);
                    }
                    break;
                }
            }
            bunkerState = bunkered;
        }
        void Open()
        {
            if (open || !wsb.DefaultAnimation.HasSequence(info.OpenSequence))
            {
                return;
            }

            open = true;
            wsb.PlayCustomAnimation(self, info.OpenSequence, () =>
            {
                if (wsb.DefaultAnimation.HasSequence(info.UnloadSequence))
                {
                    wsb.PlayCustomAnimationRepeating(self, info.UnloadSequence);
                }
            });
        }
Esempio n. 13
0
        void Touchdown()
        {
            if (landed || !body.DefaultAnimation.HasSequence(info.LandingSequence))
            {
                return;
            }

            landed = true;
            body.PlayCustomAnimation(self, info.LandingSequence, () =>
            {
                if (body.DefaultAnimation.HasSequence(info.TouchdownSequence))
                {
                    body.PlayCustomAnimationRepeating(self, info.TouchdownSequence);
                }
            });
        }
Esempio n. 14
0
        void UpdateAnimation(Actor self)
        {
            var playAnim = false;

            if (!IsTraitDisabled)
            {
                playAnim = true;
            }

            if (!playAnim && wsb.DefaultAnimation.CurrentSequence.Name == Info.FlySequence)
            {
                wsb.CancelCustomAnimation(self);
                return;
            }

            if (playAnim && wsb.DefaultAnimation.CurrentSequence.Name != Info.FlySequence)
            {
                wsb.PlayCustomAnimationRepeating(self, Info.FlySequence);
            }
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || CancleActivity(self))
            {
                wsb.PlayCustomAnimationRepeating(self, wsb.Info.Sequence);
                playanim = true;
                if (condtion != null && token != ConditionManager.InvalidConditionToken)
                {
                    token = conditionManager.RevokeCondition(self, token);
                    token = ConditionManager.InvalidConditionToken;
                }

                if (endqueueonce)
                {
                    endqueueonce = false;
                    QueueChild(self.Trait <IMove>().VisualMove(self, self.CenterPosition,
                                                               self.World.Map.CenterOfCell(self.World.Map.CellContaining(self.CenterPosition))));
                    QueueChild(new CallFunc(() =>
                    {
                        self.Trait <IPositionable>()
                        .SetPosition(self, self.World.Map.CellContaining(self.CenterPosition));
                    }));
                }

                if (ChildActivity == null)
                {
                    return(NextActivity);
                }
            }

            if (ChildActivity != null)
            {
                ActivityUtils.RunActivity(self, ChildActivity);
                return(this);
            }

            if (playanim)
            {
                playanim     = false;
                endqueueonce = true;
                QueueChild(self.Trait <IMove>().VisualMove(self, self.CenterPosition, d.CenterPosition));
                QueueChild(new CallFunc(() =>
                {
                    var facing = self.Trait <IFacing>();
                    if (dockactor != null && facing != null && lockfacing)
                    {
                        var desiredFacing =
                            (dockactor.CenterPosition - self.CenterPosition).HorizontalLengthSquared != 0
                               ? (dockactor.CenterPosition - self.CenterPosition).Yaw.Facing
                               : facing.Facing;
                        facing.Facing = desiredFacing;
                    }

                    wsb.PlayCustomAnimationRepeating(self, info.PreySequence);
                    if (condtion != null)
                    {
                        token = conditionManager.GrantCondition(self, condtion);
                    }
                }));
            }

            if (self.Info.TraitInfo <AcolytePreyInfo>().LeechesResources&& --ticks <= 0)
            {
                var amm = Leech(self);
                ticks = self.Info.TraitInfo <AcolytePreyInfo>().Leechinterval + amm;
            }

            return(this);
        }
Esempio n. 17
0
 public void IncomingDelivery(Actor self)
 {
     wsb.PlayCustomAnimationRepeating(self, info.ActiveSequence);
 }