Пример #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);
    }
Пример #2
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));
    }
Пример #3
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));
        }
Пример #4
0
        public static InteractResult DoClaim(Deed deed, User actor, Vector2i position, bool notify = true)
        {   // Try to perform the claiming action
            Result claimResult = AtomicActions.ClaimPropertyNow(deed, actor, actor.Inventory, position, ClaimedOrUnclaimed.ClaimingLand, false, notify);

            if (!claimResult.Success && !deed.OwnedObjects.Any())
            {
                PropertyManager.TryRemoveDeed(deed);
            }
            return((InteractResult)claimResult);
        }
Пример #5
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));
        }
Пример #6
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            if (context.HasBlock && context.Block !.Is <Clearable>())
            {
                return((InteractResult)AtomicActions.DestroyPlantNow(this.CreateMultiblockContext(context), notify: false));
            }

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

            return(base.OnActLeft(context));
        }
Пример #7
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            if (context.HasBlock && this.ShouldHighlight(context.Block !.GetType()))
            {
                return((InteractResult)AtomicActions.ChangeBlockNow(this.CreateMultiblockContext(context, () => new TampRoad()), typeof(DirtRoadBlock)));
            }

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

            return(base.OnActLeft(context));
        }
Пример #8
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            if (context.HasBlock)
            {
                var prospectResult = AtomicActions.UseToolNow(this.CreateMultiblockContext(context));
                if (prospectResult.Success)
                {
                    context.Player.OpenUI(this.GetProspectData(context), "ProspectingUI");
                }

                return((InteractResult)prospectResult);
            }

            return(base.OnActLeft(context));
        }
 public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null)
 {
     if (this.enabled)
     {
         AtomicActions.HarvestPlantNow(  // Create a pack, fill it with harvest actions and try to perform.
             harvestTo:    inv,
             reapableOnly: false,        // Harvest every plant.
             context:      new MultiblockActionContext()
         {
             Player            = vehicle.Driver,
             ToolUsed          = this,
             ActionDescription = Localizer.DoStr("harvest plant"),
             Area = area.MoveAndRotate(pos, rot)                  // Rotate area of effect and shift it to current position (and exclude repetitions from the result).
         });
     }
 }
 public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null)
 {
     if (this.enabled)                                                   // Plow only if it's on.
     {
         AtomicActions.ChangeBlockNow(newType: typeof(TilledDirtBlock),  // Create a pack, fill it with plow actions and try to perform.
                                      context: new MultiblockActionContext()
         {
             Player   = vehicle.Driver,
             ToolUsed = this,
             GameActionConstructor = () => new PlowField(),
             ActionDescription     = Localizer.DoStr("plow a block"),
             Area = area.MoveAndRotate(pos, rot)                                 // Rotate area of effect and shift it to current position (and exclude repetitions from the result).
                    .Where(position => World.GetBlock(position).Is <Tillable>()) // Exclude untillable blocks.
         });
     }
 }
Пример #11
0
    public override InteractResult OnActLeft(InteractionContext context)
    {
        // Try plow the block (and maybe its surroundings).
        if (context.HasBlock && context.Block !.Is <Tillable>())
        {
            return((InteractResult)AtomicActions.ChangeBlockNow(this.CreateMultiblockContext(context, () => new PlowField()), typeof(TilledDirtBlock)));
        }

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

        // Fallback.
        return(base.OnActLeft(context));
    }
Пример #12
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // Try harvest.
            if (context.HasBlock && context.Block.Is <Reapable>())
            {
                return((InteractResult)AtomicActions.HarvestPlantNow(this.CreateMultiblockContext(context), context.Player?.User.Inventory));
            }

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

            // Fallback.
            return(base.OnActLeft(context));
        }
Пример #13
0
 public int FireArrow(Player player, Vector3 position, Vector3 velocity)
 {
     if (player.User.Inventory.TryRemoveItem <ArrowItem>(player.User))
     {
         if (AtomicActions.UseToolNow(this.CreateMultiblockContext(player)))
         {
             var arrow = new ArrowEntity
             {
                 Damage   = this.Damage.GetCurrentValue(player.User), Controller = player, Position = position,
                 Velocity = velocity,
                 BowItem  = this
             };
             arrow.SetActiveAndCreate();
             return(arrow.ID);
         }
     }
     return(-1);
 }