Example #1
0
        private static ActivationInfo ProcessActivateToolMessage(Player player)
        {
            var slot = (ToolSlot)Storage.PacketReader.ReadByte();
            var type = (ToolType)Storage.PacketReader.ReadByte();
            var state = Storage.PacketReader.ReadBoolean();

            // This is scary.

            var propertyName = Storage.PacketReader.ReadString();
            var propertyValue = Storage.PacketReader.ReadSingle();

            if(player is RemotePlayer)
            {
                var tool = player.ToolInSlot(slot, type);
                tool.Active = state;

                if(propertyName != "")
                {
                    var toolType = tool.GetType();
                    var property = toolType.GetProperty(propertyName);

                    if(property != null)
                    {
                        var propertyType = property.PropertyType;

                        property.SetValue(tool,
                                          Convert.ChangeType(propertyValue, propertyType),
                                          null);
                    }
                }
            }

            return new ActivationInfo(slot, type, state, propertyName, propertyValue);
        }