Esempio n. 1
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // Try delete tree debris with reduced XP multiplier.
            if (context.HasBlock && context.Block.Get <TreeDebris>() is TreeDebris treeDebris)
            {
                // Create game action pack, compose and try to perform.
                using (var pack = new GameActionPack())
                {
                    // Add debris items to inventory.
                    foreach (var x in ((TreeSpecies)EcoSim.GetSpecies(treeDebris.Species)).DebrisResources)
                    {
                        pack.AddToInventory(context.Player?.User.Inventory, Item.Get(x.Key), x.Value.RandInt, context.Player?.User);
                    }

                    // Create multiblock context with reduced XP multiplier for cleaning debris.
                    var multiblockContext = this.CreateMultiblockContext(context);
                    multiblockContext.ActionDescription    = Localizer.DoStr("clean up tree debris");
                    multiblockContext.ExperiencePerAction *= 0.1f;

                    // Add block deletion to the pack and try to perform it.
                    pack.DeleteBlock(multiblockContext);
                    return((InteractResult)pack.TryPerform());
                }
            }

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

            // Fallback (try to damage target).
            return(base.OnActLeft(context));
        }
Esempio n. 2
0
    private InteractResult PlaceBlockFill(InteractionContext context, Vector3i blockPosition)
    {
        int rotation = 0;
        BlueprintInstance blueprintInstance = null;

        if (context.Parameters != null)
        {
            BSONValue val;
            if (context.Parameters.TryGetValue("formRotation", out val))
            {
                rotation = val.Int32Value;
            }

            if (context.Parameters.TryGetValue("blueprint", out val))
            {
                blueprintInstance = new BlueprintInstance(new Blueprint(), Vector3i.Zero);
                blueprintInstance.FromBson(val.ObjectValue);
            }
        }

        var creatingItem = context.CarriedItem as BlockItem;

        if (creatingItem == null)
        {
            return(InteractResult.NoOp);
        }

        // TODO SJS: Verify all the blocks are created from the same type

        var form      = context.Player?.User.Inventory.Carried.SelectedForm?.FormType.Name;
        var blockType = BlockFormManager.GetBlockTypeToCreate(context.Player, context.SelectedItem, context.CarriedItem, form, rotation);

        // Let's give up! (Let the carried type handle it)
        if (form == null || blockType == null || blueprintInstance == null)
        {
            return(InteractResult.NoOp);
        }

        // Create game action pack, fill it and try to perform.
        using (var pack = new GameActionPack())
        {
            // Fill the pack.
            foreach (var blockPos in blueprintInstance)
            {
                pack.PlaceBlock(
                    context:              this.CreateMultiblockContext(context.Player, blockPos.Offset.SingleItemAsEnumerable()),
                    blockType:            BlockManager.FromId(blockPos.BlockId),
                    createBlockAction:    true,
                    removeFromInv:        context.Player?.User.Inventory,
                    itemToRemove:         creatingItem.GetType());
            }

            // Try to perform created actions.
            return((InteractResult)pack.TryPerform(false));
        }
    }
Esempio n. 3
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));
        }
        // TODO: create atomic actions covering the case and utilize them.
        public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null)
        {
            if (inv == null)
            {
                return;
            }

            if (!this.enabled)
            {
                return;
            }

            foreach (var offset in area)
            {
                var stack = inv.GroupedStacks.Where(x => x.Item is SeedItem).FirstOrDefault();
                if (stack == null)
                {
                    return;
                }
                SeedItem seed       = stack.Item as SeedItem;
                var      targetPos  = (rot.RotateVector(offset) + pos).XYZi;
                Result   authResult = ServiceHolder <IAuthManager> .Obj.IsAuthorized(targetPos, vehicle.Driver.User, AccessType.ConsumerAccess, null);

                if (authResult.Success)
                {
                    if (World.GetBlock(targetPos + Vector3i.Down).Is <Tilled>() && World.GetBlock(targetPos).Is <Empty>())
                    {
                        var pack = new GameActionPack();
                        pack.AddGameAction(new PlantSeeds()
                        {
                            Species        = seed.Species.GetType(),
                            ActionLocation = targetPos,
                            Citizen        = vehicle.Driver.User,
                            ToolUsed       = this
                        });

                        var changes = new InventoryChangeSet(inv, vehicle.Driver.User);
                        changes.RemoveItem(seed.Type);
                        pack.AddChangeSet(changes);

                        if (pack.TryPerform())
                        {
                            var plant = EcoSim.PlantSim.SpawnPlant(seed.Species, targetPos);
                            plant.Tended = true;
                        }
                    }
                }
            }
        }