public bool AttackBy(AttackByEventArgs eventArgs)
        {
            var playerEntity      = eventArgs.User;
            var interactionSystem = _entitySystemManager.GetEntitySystem <InteractionSystem>();

            if (!interactionSystem.InRangeUnobstructed(playerEntity.Transform.MapPosition, Owner.Transform.WorldPosition, ignoredEnt: Owner, insideBlockerValid: Prototype.CanBuildInImpassable))
            {
                _notifyManager.PopupMessage(Owner.Transform.GridPosition, playerEntity,
                                            _localizationManager.GetString("You can't reach there!"));
                return(false);
            }

            var stage = Prototype.Stages[Stage];

            if (TryProcessStep(stage.Forward, eventArgs.AttackWith))
            {
                Stage++;
                if (Stage == Prototype.Stages.Count - 1)
                {
                    // Oh boy we get to finish construction!
                    var entMgr = IoCManager.Resolve <IServerEntityManager>();
                    var ent    = entMgr.SpawnEntity(Prototype.Result, Transform.GridPosition);
                    ent.GetComponent <ITransformComponent>().LocalRotation = Transform.LocalRotation;
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            else if (TryProcessStep(stage.Backward, eventArgs.AttackWith))
            {
                Stage--;
                if (Stage == 0)
                {
                    // Deconstruction complete.
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            return(true);
        }
        public bool InteractUsing(InteractUsingEventArgs eventArgs)
        {
            // default interaction check for AttackBy allows inside blockers, so we will check if its blocked if
            // we're not allowed to build on impassable stuff
            if (Prototype.CanBuildInImpassable == false)
            {
                if (!InteractionChecks.InRangeUnobstructed(eventArgs, false))
                {
                    return(false);
                }
            }

            var stage = Prototype.Stages[Stage];

            if (TryProcessStep(stage.Forward, eventArgs.Using, eventArgs.User))
            {
                Stage++;
                if (Stage == Prototype.Stages.Count - 1)
                {
                    // Oh boy we get to finish construction!
                    var entMgr = IoCManager.Resolve <IServerEntityManager>();
                    var ent    = entMgr.SpawnEntity(Prototype.Result, Transform.GridPosition);
                    ent.GetComponent <ITransformComponent>().LocalRotation = Transform.LocalRotation;
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            else if (TryProcessStep(stage.Backward, eventArgs.Using, eventArgs.User))
            {
                Stage--;
                if (Stage == 0)
                {
                    // Deconstruction complete.
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool AttackBy(AttackByEventArgs eventArgs)
        {
            var stage = Prototype.Stages[Stage];

            if (TryProcessStep(stage.Forward, eventArgs.AttackWith))
            {
                Stage++;
                if (Stage == Prototype.Stages.Count - 1)
                {
                    // Oh boy we get to finish construction!
                    var entMgr = IoCManager.Resolve <IServerEntityManager>();
                    var ent    = entMgr.SpawnEntity(Prototype.Result, Transform.GridPosition);
                    ent.GetComponent <ITransformComponent>().LocalRotation = Transform.LocalRotation;
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            else if (TryProcessStep(stage.Backward, eventArgs.AttackWith))
            {
                Stage--;
                if (Stage == 0)
                {
                    // Deconstruction complete.
                    Owner.Delete();
                    return(true);
                }

                stage = Prototype.Stages[Stage];
                if (stage.Icon != null)
                {
                    Sprite.LayerSetSprite(0, stage.Icon);
                }
            }

            return(true);
        }
        protected void UpdateFillIcon()
        {
            if (string.IsNullOrEmpty(_fillInitState))
            {
                return;
            }

            var percentage = (CurrentVolume / MaxVolume).Double();
            var level      = ContentHelpers.RoundToLevels(percentage * 100, 100, _fillInitSteps);

            //Transformed glass uses special fancy sprites so we don't bother
            if (level == 0 || (Owner.TryGetComponent <TransformableContainerComponent>(out var transformComp) && transformComp.Transformed))
            {
                _spriteComponent.LayerSetColor(1, Color.Transparent);
                return;
            }

            _fillSprite = new SpriteSpecifier.Rsi(_fillPath, _fillInitState + level);
            _spriteComponent.LayerSetSprite(1, _fillSprite);
            _spriteComponent.LayerSetColor(1, SubstanceColor);
        }