Ejemplo n.º 1
0
        public StarterKitDialog() : base("Starter Kit", 0, 0)
        {
            Width  = 52;
            Height = 10;

            var label = new Label("PlayerId")
            {
                X      = 2,
                Y      = 2,
                Width  = 20,
                Height = 1,
            };

            Add(label);

            var field = new TextField("")
            {
                Id     = "playerId",
                X      = 22,
                Y      = Pos.Top(label),
                Width  = 22,
                Height = 1,
            };

            Add(field);

            var btn = new Button("Give")
            {
                X       = Pos.Center(),
                Y       = 4,
                Clicked = delegate()
                {
                    var rng      = new Random();
                    var playerId = Guid.Parse(field.Text.ToString());

                    var evnts = Domain.Seed.EntityLibrary.Data()
                                .Select(e => new PlayerInventoryChangedEvent(playerId, new Player {
                        Name = "<toolbox>"
                    })
                    {
                        InventoryChange = new[]
                        {
                            new LuaItemStack
                            {
                                Name  = e.Name,
                                Count = rng.Next(10, 1000000),
                            },
                        },
                    })
                                .ToArray();


                    var producer = new ProducerDialog();
                    producer.Produce(evnts);
                    Application.Run(producer);
                },
            };

            Add(btn);
        }
Ejemplo n.º 2
0
        private void HandleClick(Type eventType, List <TextField> formFields, List <PropertyInfo> props)
        {
            var evnt = Activator.CreateInstance(eventType);

            // Parse form fields and set values
            foreach (var field in formFields.Where(f => !string.IsNullOrEmpty(f.Text.ToString())))
            {
                var prop = eventType.GetProperty(field.Id.ToString());
                if (prop.PropertyType == typeof(string))
                {
                    prop.SetValue(evnt, field.Text.ToString());
                }
                else if (prop.PropertyType == typeof(int))
                {
                    prop.SetValue(evnt, int.Parse(field.Text.ToString()));
                }
                else if (prop.PropertyType == typeof(long))
                {
                    prop.SetValue(evnt, long.Parse(field.Text.ToString()));
                }
                else if (prop.PropertyType == typeof(double))
                {
                    prop.SetValue(evnt, double.Parse(field.Text.ToString()));
                }
                else if (prop.PropertyType == typeof(float))
                {
                    prop.SetValue(evnt, float.Parse(field.Text.ToString()));
                }
                else if (prop.PropertyType == typeof(Guid))
                {
                    prop.SetValue(evnt, Guid.Parse(field.Text.ToString()));
                }
            }

            // Set auto-generated values for certain prop types
            foreach (var prop in props)
            {
                if (prop.PropertyType == typeof(LuaItemStack[]))
                {
                    var stack = new[]
                    {
                        new LuaItemStack
                        {
                            Name  = "iron-plate",
                            Count = 420,
                        },
                    };
                    prop.SetValue(evnt, stack);
                }
            }

            if (evnt is Event baseEvent)
            {
                baseEvent.Initiator = new EventInitiator
                {
                    PlayerName = "<toolbox>",
                };
                baseEvent.Metadata = new EventMetadata
                {
                    CreatedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
                };
                var producer = new ProducerDialog();
                producer.Produce(baseEvent);
                Application.Run(producer);
            }
            else
            {
                throw new Exception("Could not instantiate the event correctly!");
            }
        }