public override void BlockInteraction(Vector3i pos, Quaternion rot, VehicleComponent vehicle, Inventory inv = null)
        {
            if (inv == null)
            {
                return;
            }
            foreach (var offset in area)
            {
                SeedItem seed       = inv.GroupedStacks.Where(x => x.Item is SeedItem).First().Item as SeedItem;
                var      targetPos  = (rot.RotateVector(offset) + pos).XYZi;
                Result   authResult = AuthManager.IsAuthorized(targetPos, vehicle.Driver.User);
                if (authResult.Success)
                {
                    if (World.GetBlock(targetPos + Vector3i.Down).Is <Tilled>() && World.GetBlock(targetPos).Is <Empty>())
                    {
                        var changes = new InventoryChangeSet(inv, vehicle.Driver.User);
                        changes.RemoveItem(seed.Type);
                        IAtomicAction plantAction = PlayerActions.Plant.CreateAtomicAction(vehicle.Driver, targetPos, seed.Species);

                        if (new MultiAtomicAction(changes, plantAction).TryApply())
                        {
                            var plant = EcoSim.PlantSim.SpawnPlant(seed.Species, targetPos);
                            plant.Tended = true;
                        }
                    }
                }
            }
        }
Exemple #2
0
        //[Serialized] private string description = "An Empty note. You can copy text from a sign to it or use /writenote to add text.";
        //[Serialized] private string name = "Empty Note";
        //[Serialized] private bool empty = true;


        public override InteractResult OnActRight(InteractionContext context)
        {
            if (context.HasTarget && context.Target is WorldObject)
            {
                WorldObject wo = context.Target as WorldObject;
                if (wo.HasComponent <CustomTextComponent>())
                {
                    NoteItem noteItem = (NoteItem)Item.Create <NoteItem>();

                    noteItem.description = wo.GetComponent <CustomTextComponent>().Text;
                    noteItem.owner       = context.Player.User;

                    InventoryChangeSet inventoryChange = new InventoryChangeSet(context.Player.User.Inventory, context.Player.User);
                    inventoryChange.RemoveItem(typeof(EmptyNoteItem));
                    inventoryChange.AddItem(noteItem);
                    if (inventoryChange.TryApply().Success)
                    {
                        return(InteractResult.Success);
                    }
                    else
                    {
                        return(InteractResult.Failure("Not enough room in inventory".ToLocString()));//ChatManager.ServerMessageToPlayer("Not enough room in inventory",context.Player.User);
                    }
                }
            }


            return(base.OnActRight(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;
                        }
                    }
                }
            }
        }
Exemple #4
0
        public static void WriteText(User user, string text)
        {
            //string onestringtext = string.Concat(text);

            NoteItem noteItem = (NoteItem)Item.Create <NoteItem>();

            noteItem.description = text;
            noteItem.owner       = user;

            InventoryChangeSet inventoryChange = new InventoryChangeSet(user.Inventory, user);

            inventoryChange.AddItem(noteItem);
            inventoryChange.RemoveItem(typeof(EmptyNoteItem));
            if (inventoryChange.TryApply().Success)
            {
                return;
            }
            else
            {
                ChatManager.ServerMessageToPlayer("Not enough room in inventory", user);
            }
        }
Exemple #5
0
        public static void Seal(User user, string target)
        {
            UserIdType idtype;
            User       targetuser = UserManager.FindUser(target, out idtype);

            if (idtype == UserIdType.Unknown)
            {
                ChatManager.ServerMessageToPlayer("User " + target + " not found", user);
                return;
            }
            if (!(user.Inventory.Toolbar.SelectedItem is NoteItem))
            {
                ChatManager.ServerMessageToPlayer("No Note selected", user);
                return;
            }

            LetterItem letter = (LetterItem)Item.Create <LetterItem>();

            letter.content         = user.Inventory.Toolbar.SelectedItem;
            letter.contentquantity = user.Inventory.Toolbar.SelectedStack.Quantity;
            letter.recipient       = targetuser;
            letter.sender          = user;


            InventoryChangeSet inventoryChange = new InventoryChangeSet(user.Inventory, user);

            inventoryChange.RemoveItem(typeof(EnvelopeItem));
            inventoryChange.ModifyStack(user.Inventory.Toolbar.SelectedStack, 1 - user.Inventory.Toolbar.SelectedStack.Quantity, letter);

            if (inventoryChange.TryApply().Success)
            {
                return;
            }
            else
            {
                ChatManager.ServerMessageToPlayer("Not enough Envelopes found", user);
            }
        }