Example #1
0
    private InteractResult Blast(InteractionContext context, Vector3i blockPosition)
    {
        //todo: make it use the hammer's calories and durability if it's selected
        Vector3i minTop = blockPosition + new Vector3i(-2, -1, -2);
        Vector3i maxTop = blockPosition + new Vector3i(2, -1, 2);

        Vector3i minBottom = minTop + new Vector3i(0, -5, 0);
        Vector3i maxBottom = maxTop + new Vector3i(0, -5, 0);

        var pack = new GameActionPack();

        var range = new WorldRange(minBottom, maxTop);

        foreach (var blockPos in range.XYZIterInc())
        {
            var blockType = World.GetBlock(blockPos).GetType();
            if (RubbleObject.BecomesRubble(blockType))
            {
                AtomicActions.DeleteBlockNow(this.CreateMultiblockContext(context));
                RubbleObject.TrySpawnFromBlock(context.Player, blockType, blockPos, 4);
            }
        }

        return(InteractResult.Success);
    }
Example #2
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // Try interact with a block.
            if (context.HasBlock && context.Block.Is <Diggable>())
            {
                // Is it a diggable plant? Treat it like a plant then.
                if (context.Block is PlantBlock)
                {
                    return((InteractResult)AtomicActions.DestroyPlantNow(this.CreateMultiblockContext(context), harvestTo: context.Player?.User.Inventory));
                }

                // Delete diggable block and add it to inventory.
                return((InteractResult)AtomicActions.DeleteBlockNow(
                           context:            this.CreateMultiblockContext(context),                                     // Get context with area of effect, calories, XP, etc.
                           harvestPlantsAbove: World.GetBlock(context.BlockPosition.Value + Vector3i.Up).Is <Diggable>(), // Also try harvest plants above if they are diggable.
                           addTo:              context.Player?.User.Inventory));                                          // Deleted block (and maybe plants above) will be added to this inventory.
            }

            // Try interact with a world object.
            if (context.Target is WorldObject)
            {
                return(this.BasicToolOnWorldObjectCheck(context));
            }

            // Fallback.
            return(base.OnActLeft(context));
        }
Example #3
0
    public override InteractResult OnActLeft(InteractionContext context)
    {
        if (context.HasBlock)
        {
            if (context.Block.Is <Constructed>())
            {
                return((InteractResult)AtomicActions.DeleteBlockNow(context: this.CreateMultiblockContext(context, () => new ConstructOrDeconstruct()
                {
                    ConstructedOrDeconstructed = ConstructedOrDeconstructed.Deconstructed
                }),
                                                                    addTo:   context.Player?.User.Inventory));
            }
            else if (context.Block is WorldObjectBlock block)
            {
                return(this.TryPickUp(block.WorldObjectHandle.Object, context));
            }
            else
            {
                return(InteractResult.NoOp);
            }
        }
        else if (context.Target is WorldObject worldObject)
        {
            return(this.TryPickUp(worldObject, context));
        }

        return(base.OnActLeft(context));
    }
Example #4
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            if (context.HasBlock && context.Block.Is <Minable>())
            {
                var user = context.Player.User;
                var item = context.Block is IRepresentsItem?Item.Get((IRepresentsItem)context.Block) : null;

                var totalDamageToTarget = user.BlockHitCache.MemorizeHit(context.Block.GetType(), context.BlockPosition.Value, this.Tier.GetCurrentValue(context.Player.User) * this.Damage);
                if (context.Block.Get <Minable>().Hardness <= totalDamageToTarget)
                {
                    var result = AtomicActions.DeleteBlockNow(this.CreateMultiblockContext(context), spawnRubble: false);

                    //Spawn the rubble if needed
                    if (result.Success)
                    {
                        var forced = context.Player.User.Talentset.HasTalent(typeof(MiningLuckyBreakTalent)) ? 4 : -1;
                        if (RubbleObject.TrySpawnFromBlock(context.Player, context.Block.GetType(), context.BlockPosition.Value, forced))
                        {
                            var addition = item != null ? " " + item.UILink() : string.Empty;
                            this.AddExperience(user, 1f, new LocString(Localizer.Format("mining") + addition));
                            user.UserUI.OnCreateRubble.Invoke(item.DisplayName.NotTranslated);
                            user.BlockHitCache.ForgetHit(context.BlockPosition.Value);
                        }
                    }

                    return((InteractResult)result);
                }
                else
                {
                    return((InteractResult)AtomicActions.UseToolNow(this.CreateMultiblockContext(context)));
                }
            }
            else if (context.Target is RubbleObject)
            {
                var rubble = (RubbleObject)context.Target;
                if (rubble.IsBreakable)
                {
                    using var pack = new GameActionPack();
                    pack.UseTool(this.CreateMultiblockContext(context));
                    pack.AddPostEffect(() => rubble.Breakup(context.Player));
                    return((InteractResult)pack.TryPerform(false));
                }

                return(InteractResult.NoOp);
            }

            if (context.Target is WorldObject)
            {
                return(this.BasicToolOnWorldObjectCheck(context));
            }

            return(base.OnActLeft(context));
        }